Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add boolean custom option

  • Loading branch information...
commit 16e7f6b79694f5c96c2a7df038c528854a4d91a7 1 parent f720e8b
David Chelimsky dchelimsky authored
6 features/configuration/custom_options.feature
View
@@ -1,4 +1,3 @@
-@wip
Feature: custom options
In order to seamlessly provide my users more options
@@ -45,6 +44,7 @@ Feature: custom options
When I run "rspec boolean_option_spec.rb"
Then I should see "2 examples, 0 failures"
+@wip
Scenario: boolean option overridden in client app
Given a file named "boolean_option_spec.rb" with:
"""
@@ -53,12 +53,12 @@ Feature: custom options
end
Rspec.configure do |c|
- c.custom_option = :reset
+ c.custom_option = true
end
describe "custom option" do
it "returns the value set in the client app" do
- Rspec.configuration.custom_option.should == :reset
+ Rspec.configuration.custom_option.should be_true
end
it "is exposed as a predicate" do
11 lib/rspec/core/configuration.rb
View
@@ -239,6 +239,17 @@ def require_files_to_run
files_to_run.map {|f| require f }
end
+ def add_option(mname, options)
+ case options[:type]
+ when :boolean
+ (class << self; self; end).class_eval do
+ attr_reader mname
+ define_method("#{mname}?") { !!(send mname) }
+ end
+ instance_variable_set "@#{mname}", options[:default]
+ end
+ end
+
end
end
end
29 spec/rspec/core/configuration_spec.rb
View
@@ -261,6 +261,33 @@ def that_thing
end
end
- end
+ describe "#add_option" do
+ describe ":type => :boolean" do
+ context "with no additional options" do
+ before { config.add_option :custom_option, :type => :boolean }
+
+ it "defaults to false" do
+ config.custom_option.should be_false
+ end
+
+ it "adds a predicate" do
+ config.custom_option?.should be_false
+ end
+ end
+
+ context "with :default => true" do
+ before { config.add_option :custom_option, :type => :boolean, :default => true }
+ it "defaults to false" do
+ config.custom_option.should be_true
+ end
+
+ it "adds a predicate" do
+ config.custom_option?.should be_true
+ end
+ end
+ end
+ end
+
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.