1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
Feature: Custom settings
Extensions like rspec-rails can add their own configuration settings.
Scenario: Simple setting (with defaults)
Given a file named "additional_setting_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.add_setting :custom_setting
end
RSpec.describe "custom setting" do
it "is nil by default" do
expect(RSpec.configuration.custom_setting).to be_nil
end
it "is exposed as a predicate" do
expect(RSpec.configuration.custom_setting?).to be(false)
end
it "can be overridden" do
RSpec.configuration.custom_setting = true
expect(RSpec.configuration.custom_setting).to be(true)
expect(RSpec.configuration.custom_setting?).to be(true)
end
end
"""
When I run `rspec ./additional_setting_spec.rb`
Then the examples should all pass
Scenario: Default to `true`
Given a file named "additional_setting_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.add_setting :custom_setting, :default => true
end
RSpec.describe "custom setting" do
it "is true by default" do
expect(RSpec.configuration.custom_setting).to be(true)
end
it "is exposed as a predicate" do
expect(RSpec.configuration.custom_setting?).to be(true)
end
it "can be overridden" do
RSpec.configuration.custom_setting = false
expect(RSpec.configuration.custom_setting).to be(false)
expect(RSpec.configuration.custom_setting?).to be(false)
end
end
"""
When I run `rspec ./additional_setting_spec.rb`
Then the examples should all pass
Scenario: Overridden in a subsequent `RSpec.configure` block
Given a file named "additional_setting_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.add_setting :custom_setting
end
RSpec.configure do |c|
c.custom_setting = true
end
RSpec.describe "custom setting" do
it "returns the value set in the last configure block to get eval'd" do
expect(RSpec.configuration.custom_setting).to be(true)
end
it "is exposed as a predicate" do
expect(RSpec.configuration.custom_setting?).to be(true)
end
end
"""
When I run `rspec ./additional_setting_spec.rb`
Then the examples should all pass
|