Skip to content
Browse files

Use consistent APIs in cukes.

- `RSpec.describe` rather than `describe`.
- `expect` rather than `should`
- `it { is_expected.to matcher }` rather than `it { should matcher }`.

I've added a cucumber environment file that enforces these as well.
  • Loading branch information...
1 parent 2cf24eb commit 75a470fddb22074c90405b009d3869b188ba1047 @myronmarston myronmarston committed Feb 19, 2014
Showing with 340 additions and 307 deletions.
  1. +1 −1 README.md
  2. +1 −1 features/README.md
  3. +4 −4 features/built_in_matchers/be.feature
  4. +11 −11 features/built_in_matchers/be_within.feature
  5. +2 −2 features/built_in_matchers/change.feature
  6. +2 −2 features/built_in_matchers/comparisons.feature
  7. +1 −1 features/built_in_matchers/contain_exactly.feature
  8. +15 −15 features/built_in_matchers/cover.feature
  9. +12 −12 features/built_in_matchers/end_with.feature
  10. +7 −7 features/built_in_matchers/equality.feature
  11. +2 −2 features/built_in_matchers/exist.feature
  12. +47 −47 features/built_in_matchers/include.feature
  13. +10 −10 features/built_in_matchers/match.feature
  14. +2 −2 features/built_in_matchers/output.feature
  15. +21 −21 features/built_in_matchers/predicates.feature
  16. +9 −9 features/built_in_matchers/raise_error.feature
  17. +20 −20 features/built_in_matchers/respond_to.feature
  18. +5 −5 features/built_in_matchers/satisfy.feature
  19. +12 −12 features/built_in_matchers/start_with.feature
  20. +3 −3 features/built_in_matchers/throw_symbol.feature
  21. +42 −42 features/built_in_matchers/types.feature
  22. +4 −4 features/built_in_matchers/yield.feature
  23. +12 −12 features/composing_matchers.feature
  24. +2 −2 features/compound_expectations.feature
  25. +2 −2 features/custom_matchers/access_running_example.feature
  26. +2 −2 features/custom_matchers/define_diffable_matcher.feature
  27. +42 −44 features/custom_matchers/define_matcher.feature
  28. +2 −2 features/custom_matchers/define_matcher_with_fluent_interface.feature
  29. +2 −2 features/customized_message.feature
  30. +4 −4 features/diffing.feature
  31. +2 −2 features/implicit_docstrings.feature
  32. +34 −0 features/support/disallow_certain_apis.rb
  33. +3 −2 features/syntax_configuration.feature
View
2 README.md
@@ -23,7 +23,7 @@ Minitest, or Cucumber, you can install it directly:
Here's an example using rspec-core:
```ruby
-describe Order do
+RSpec.describe Order do
it "sums the prices of the items in its line items" do
order = Order.new
order.add_entry(LineItem.new(:item => Item.new(
View
2 features/README.md
@@ -1,6 +1,6 @@
rspec-expectations is used to define expected outcomes.
- describe Account do
+ RSpec.describe Account do
it "has a balance of zero when first created" do
expect(Account.new.balance).to eq(Money.new(0))
end
View
8 features/built_in_matchers/be.feature
@@ -12,7 +12,7 @@ Feature: "be" matchers
Scenario: be_truthy matcher
Given a file named "be_truthy_spec.rb" with:
"""ruby
- describe "be_truthy matcher" do
+ RSpec.describe "be_truthy matcher" do
specify { expect(true).to be_truthy }
specify { expect(7).to be_truthy }
specify { expect("foo").to be_truthy }
@@ -58,7 +58,7 @@ Feature: "be" matchers
Scenario: be_falsey matcher
Given a file named "be_falsey_spec.rb" with:
"""ruby
- describe "be_falsey matcher" do
+ RSpec.describe "be_falsey matcher" do
specify { expect(nil).to be_falsey }
specify { expect(false).to be_falsey }
specify { expect(true).not_to be_falsey }
@@ -104,7 +104,7 @@ Feature: "be" matchers
Scenario: be_nil matcher
Given a file named "be_nil_spec.rb" with:
"""ruby
- describe "be_nil matcher" do
+ RSpec.describe "be_nil matcher" do
specify { expect(nil).to be_nil }
specify { expect(false).not_to be_nil }
specify { expect(true).not_to be_nil }
@@ -150,7 +150,7 @@ Feature: "be" matchers
Scenario: be matcher
Given a file named "be_spec.rb" with:
"""ruby
- describe "be_matcher" do
+ RSpec.describe "be_matcher" do
specify { expect(true).to be }
specify { expect(7).to be }
specify { expect("foo").to be }
View
22 features/built_in_matchers/be_within.feature
@@ -23,20 +23,20 @@ Feature: be_within matcher
Scenario: basic usage
Given a file named "be_within_matcher_spec.rb" with:
"""ruby
- describe 27.5 do
- it { should be_within(0.5).of(27.9) }
- it { should be_within(0.5).of(28.0) }
- it { should be_within(0.5).of(27.1) }
- it { should be_within(0.5).of(27.0) }
+ RSpec.describe 27.5 do
+ it { is_expected.to be_within(0.5).of(27.9) }
+ it { is_expected.to be_within(0.5).of(28.0) }
+ it { is_expected.to be_within(0.5).of(27.1) }
+ it { is_expected.to be_within(0.5).of(27.0) }
- it { should_not be_within(0.5).of(28.1) }
- it { should_not be_within(0.5).of(26.9) }
+ it { is_expected.not_to be_within(0.5).of(28.1) }
+ it { is_expected.not_to be_within(0.5).of(26.9) }
# deliberate failures
- it { should_not be_within(0.5).of(28) }
- it { should_not be_within(0.5).of(27) }
- it { should be_within(0.5).of(28.1) }
- it { should be_within(0.5).of(26.9) }
+ it { is_expected.not_to be_within(0.5).of(28) }
+ it { is_expected.not_to be_within(0.5).of(27) }
+ it { is_expected.to be_within(0.5).of(28.1) }
+ it { is_expected.to be_within(0.5).of(26.9) }
end
"""
When I run `rspec be_within_matcher_spec.rb`
View
4 features/built_in_matchers/change.feature
@@ -32,7 +32,7 @@ Feature: change matcher
"""ruby
require "counter"
- describe Counter, "#increment" do
+ RSpec.describe Counter, "#increment" do
it "should increment the count" do
expect { Counter.increment }.to change{Counter.count}.from(0).to(1)
end
@@ -52,7 +52,7 @@ Feature: change matcher
"""ruby
require "counter"
- describe Counter, "#increment" do
+ RSpec.describe Counter, "#increment" do
it "should not increment the count by 1 (using not_to)" do
expect { Counter.increment }.not_to change{Counter.count}
end
View
4 features/built_in_matchers/comparisons.feature
@@ -12,7 +12,7 @@ Feature: comparison matchers
Scenario: numeric operator matchers
Given a file named "numeric_operator_matchers_spec.rb" with:
"""ruby
- describe do
+ RSpec.describe do
example { expect(18).to be < 20 }
example { expect(18).to be > 15 }
example { expect(18).to be <= 19 }
@@ -55,7 +55,7 @@ Feature: comparison matchers
Scenario: string operator matchers
Given a file named "string_operator_matchers_spec.rb" with:
"""ruby
- describe do
+ RSpec.describe do
example { expect("Strawberry").to be < "Tomato" }
example { expect("Strawberry").to be > "Apple" }
example { expect("Strawberry").to be <= "Turnip" }
View
2 features/built_in_matchers/contain_exactly.feature
@@ -21,7 +21,7 @@ Feature: contain_exactly matcher
Scenario: array operator matchers
Given a file named "contain_exactly_matcher_spec.rb" with:
"""ruby
- describe do
+ RSpec.describe do
example { expect([1, 2, 3]).to contain_exactly(1, 2, 3) }
example { expect([1, 2, 3]).to contain_exactly(1, 3, 2) }
example { expect([1, 2, 3]).to contain_exactly(2, 1, 3) }
View
30 features/built_in_matchers/cover.feature
@@ -14,25 +14,25 @@ Feature: cover matcher
Scenario: range usage
Given a file named "range_cover_matcher_spec.rb" with:
"""ruby
- describe (1..10) do
- it { should cover(4) }
- it { should cover(6) }
- it { should cover(8) }
- it { should cover(4, 6) }
- it { should cover(4, 6, 8) }
- it { should_not cover(11) }
- it { should_not cover(11, 12) }
+ RSpec.describe (1..10) do
+ it { is_expected.to cover(4) }
+ it { is_expected.to cover(6) }
+ it { is_expected.to cover(8) }
+ it { is_expected.to cover(4, 6) }
+ it { is_expected.to cover(4, 6, 8) }
+ it { is_expected.not_to cover(11) }
+ it { is_expected.not_to cover(11, 12) }
# deliberate failures
- it { should cover(11) }
- it { should_not cover(4) }
- it { should_not cover(6) }
- it { should_not cover(8) }
- it { should_not cover(4, 6, 8) }
+ it { is_expected.to cover(11) }
+ it { is_expected.not_to cover(4) }
+ it { is_expected.not_to cover(6) }
+ it { is_expected.not_to cover(8) }
+ it { is_expected.not_to cover(4, 6, 8) }
# both of these should fail since it covers 5 but not 11
- it { should cover(5, 11) }
- it { should_not cover(5, 11) }
+ it { is_expected.to cover(5, 11) }
+ it { is_expected.not_to cover(5, 11) }
end
"""
When I run `rspec range_cover_matcher_spec.rb`
View
24 features/built_in_matchers/end_with.feature
@@ -12,13 +12,13 @@ Feature: end_with matcher
Scenario: string usage
Given a file named "example_spec.rb" with:
"""ruby
- describe "this string" do
- it { should end_with "string" }
- it { should_not end_with "stringy" }
+ RSpec.describe "this string" do
+ it { is_expected.to end_with "string" }
+ it { is_expected.not_to end_with "stringy" }
# deliberate failures
- it { should_not end_with "string" }
- it { should end_with "stringy" }
+ it { is_expected.not_to end_with "string" }
+ it { is_expected.to end_with "stringy" }
end
"""
When I run `rspec example_spec.rb`
@@ -30,15 +30,15 @@ Feature: end_with matcher
Scenario: array usage
Given a file named "example_spec.rb" with:
"""ruby
- describe [0, 1, 2, 3, 4] do
- it { should end_with 4 }
- it { should end_with 3, 4 }
- it { should_not end_with 3 }
- it { should_not end_with 0, 1, 2, 3, 4, 5 }
+ RSpec.describe [0, 1, 2, 3, 4] do
+ it { is_expected.to end_with 4 }
+ it { is_expected.to end_with 3, 4 }
+ it { is_expected.not_to end_with 3 }
+ it { is_expected.not_to end_with 0, 1, 2, 3, 4, 5 }
# deliberate failures
- it { should_not end_with 4 }
- it { should end_with 3 }
+ it { is_expected.not_to end_with 4 }
+ it { is_expected.to end_with 3 }
end
"""
When I run `rspec example_spec.rb`
View
14 features/built_in_matchers/equality.feature
@@ -28,7 +28,7 @@ Feature: equality matchers
Scenario: compare using eq (==)
Given a file named "compare_using_eq.rb" with:
"""ruby
- describe "a string" do
+ RSpec.describe "a string" do
it "is equal to another string of the same value" do
expect("this string").to eq("this string")
end
@@ -38,7 +38,7 @@ Feature: equality matchers
end
end
- describe "an integer" do
+ RSpec.describe "an integer" do
it "is equal to a float of the same value" do
expect(5).to eq(5.0)
end
@@ -50,7 +50,7 @@ Feature: equality matchers
Scenario: compare using ==
Given a file named "compare_using_==.rb" with:
"""ruby
- describe "a string" do
+ RSpec.describe "a string" do
it "is equal to another string of the same value" do
expect("this string").to be == "this string"
end
@@ -60,7 +60,7 @@ Feature: equality matchers
end
end
- describe "an integer" do
+ RSpec.describe "an integer" do
it "is equal to a float of the same value" do
expect(5).to be == 5.0
end
@@ -72,7 +72,7 @@ Feature: equality matchers
Scenario: compare using eql (eql?)
Given a file named "compare_using_eql.rb" with:
"""ruby
- describe "an integer" do
+ RSpec.describe "an integer" do
it "is equal to another integer of the same value" do
expect(5).to eql(5)
end
@@ -93,7 +93,7 @@ Feature: equality matchers
Scenario: compare using equal (equal?)
Given a file named "compare_using_equal.rb" with:
"""ruby
- describe "a string" do
+ RSpec.describe "a string" do
it "is equal to itself" do
string = "this string"
expect(string).to equal(string)
@@ -115,7 +115,7 @@ Feature: equality matchers
Scenario: compare using be (equal?)
Given a file named "compare_using_be.rb" with:
"""ruby
- describe "a string" do
+ RSpec.describe "a string" do
it "is equal to itself" do
string = "this string"
expect(string).to be(string)
View
4 features/built_in_matchers/exist.feature
@@ -26,13 +26,13 @@ Feature: exist matcher
end
end
- describe "Earth" do
+ RSpec.describe "Earth" do
let(:earth) { Planet.new("Earth") }
specify { expect(earth).to exist }
specify { expect(earth).not_to exist } # deliberate failure
end
- describe "Tatooine" do
+ RSpec.describe "Tatooine" do
let(:tatooine) { Planet.new("Tatooine") }
specify { expect(tatooine).to exist } # deliberate failure
specify { expect(tatooine).not_to exist }
View
94 features/built_in_matchers/include.feature
@@ -30,25 +30,25 @@ Feature: include matcher
Scenario: array usage
Given a file named "array_include_matcher_spec.rb" with:
"""ruby
- describe [1, 3, 7] do
- it { should include(1) }
- it { should include(3) }
- it { should include(7) }
- it { should include(1, 7) }
- it { should include(1, 3, 7) }
- it { should_not include(17) }
- it { should_not include(43, 100) }
+ RSpec.describe [1, 3, 7] do
+ it { is_expected.to include(1) }
+ it { is_expected.to include(3) }
+ it { is_expected.to include(7) }
+ it { is_expected.to include(1, 7) }
+ it { is_expected.to include(1, 3, 7) }
+ it { is_expected.not_to include(17) }
+ it { is_expected.not_to include(43, 100) }
# deliberate failures
- it { should include(4) }
- it { should_not include(1) }
- it { should_not include(3) }
- it { should_not include(7) }
- it { should_not include(1, 3, 7) }
+ it { is_expected.to include(4) }
+ it { is_expected.not_to include(1) }
+ it { is_expected.not_to include(3) }
+ it { is_expected.not_to include(7) }
+ it { is_expected.not_to include(1, 3, 7) }
# both of these should fail since it includes 1 but not 9
- it { should include(1, 9) }
- it { should_not include(1, 9) }
+ it { is_expected.to include(1, 9) }
+ it { is_expected.not_to include(1, 9) }
end
"""
When I run `rspec array_include_matcher_spec.rb`
@@ -65,17 +65,17 @@ Feature: include matcher
Scenario: string usage
Given a file named "string_include_matcher_spec.rb" with:
"""ruby
- describe "a string" do
- it { should include("str") }
- it { should include("a", "str", "ng") }
- it { should_not include("foo") }
- it { should_not include("foo", "bar") }
+ RSpec.describe "a string" do
+ it { is_expected.to include("str") }
+ it { is_expected.to include("a", "str", "ng") }
+ it { is_expected.not_to include("foo") }
+ it { is_expected.not_to include("foo", "bar") }
# deliberate failures
- it { should include("foo") }
- it { should_not include("str") }
- it { should include("str", "foo") }
- it { should_not include("str", "foo") }
+ it { is_expected.to include("foo") }
+ it { is_expected.not_to include("str") }
+ it { is_expected.to include("str", "foo") }
+ it { is_expected.not_to include("str", "foo") }
end
"""
When I run `rspec string_include_matcher_spec.rb`
@@ -89,36 +89,36 @@ Feature: include matcher
Scenario: hash usage
Given a file named "hash_include_matcher_spec.rb" with:
"""ruby
- describe Hash do
+ RSpec.describe Hash do
subject { { :a => 7, :b => 5 } }
- it { should include(:a) }
- it { should include(:b, :a) }
- it { should include(:a => 7) }
- it { should include(:b => 5, :a => 7) }
- it { should_not include(:c) }
- it { should_not include(:c, :d) }
- it { should_not include(:d => 2) }
- it { should_not include(:a => 5) }
- it { should_not include(:b => 7, :a => 5) }
+ it { is_expected.to include(:a) }
+ it { is_expected.to include(:b, :a) }
+ it { is_expected.to include(:a => 7) }
+ it { is_expected.to include(:b => 5, :a => 7) }
+ it { is_expected.not_to include(:c) }
+ it { is_expected.not_to include(:c, :d) }
+ it { is_expected.not_to include(:d => 2) }
+ it { is_expected.not_to include(:a => 5) }
+ it { is_expected.not_to include(:b => 7, :a => 5) }
# deliberate failures
- it { should_not include(:a) }
- it { should_not include(:b, :a) }
- it { should_not include(:a => 7) }
- it { should_not include(:a => 7, :b => 5) }
- it { should include(:c) }
- it { should include(:c, :d) }
- it { should include(:d => 2) }
- it { should include(:a => 5) }
- it { should include(:a => 5, :b => 7) }
+ it { is_expected.not_to include(:a) }
+ it { is_expected.not_to include(:b, :a) }
+ it { is_expected.not_to include(:a => 7) }
+ it { is_expected.not_to include(:a => 7, :b => 5) }
+ it { is_expected.to include(:c) }
+ it { is_expected.to include(:c, :d) }
+ it { is_expected.to include(:d => 2) }
+ it { is_expected.to include(:a => 5) }
+ it { is_expected.to include(:a => 5, :b => 7) }
# Mixed cases--the hash includes one but not the other.
# All 4 of these cases should fail.
- it { should include(:a, :d) }
- it { should_not include(:a, :d) }
- it { should include(:a => 7, :d => 3) }
- it { should_not include(:a => 7, :d => 3) }
+ it { is_expected.to include(:a, :d) }
+ it { is_expected.not_to include(:a, :d) }
+ it { is_expected.to include(:a => 7, :d => 3) }
+ it { is_expected.not_to include(:a => 7, :d => 3) }
end
"""
When I run `rspec hash_include_matcher_spec.rb`
View
20 features/built_in_matchers/match.feature
@@ -17,13 +17,13 @@ Feature: match matcher
Scenario: string usage
Given a file named "string_match_spec.rb" with:
"""ruby
- describe "a string" do
- it { should match(/str/) }
- it { should_not match(/foo/) }
+ RSpec.describe "a string" do
+ it { is_expected.to match(/str/) }
+ it { is_expected.not_to match(/foo/) }
# deliberate failures
- it { should_not match(/str/) }
- it { should match(/foo/) }
+ it { is_expected.not_to match(/str/) }
+ it { is_expected.to match(/foo/) }
end
"""
When I run `rspec string_match_spec.rb`
@@ -35,13 +35,13 @@ Feature: match matcher
Scenario: regular expression usage
Given a file named "regexp_match_spec.rb" with:
"""ruby
- describe /foo/ do
- it { should match("food") }
- it { should_not match("drinks") }
+ RSpec.describe /foo/ do
+ it { is_expected.to match("food") }
+ it { is_expected.not_to match("drinks") }
# deliberate failures
- it { should_not match("food") }
- it { should match("drinks") }
+ it { is_expected.not_to match("food") }
+ it { is_expected.to match("drinks") }
end
"""
When I run `rspec regexp_match_spec.rb`
View
4 features/built_in_matchers/output.feature
@@ -16,7 +16,7 @@ Feature: output matcher
Scenario: output_to_stdout matcher
Given a file named "output_to_stdout_spec.rb" with:
"""ruby
- describe "output.to_stdout matcher" do
+ RSpec.describe "output.to_stdout matcher" do
specify { expect { print('foo') }.to output.to_stdout }
specify { expect { print('foo') }.to output('foo').to_stdout }
specify { expect { print('foo') }.to output(/foo/).to_stdout }
@@ -44,7 +44,7 @@ Feature: output matcher
Scenario: output_to_stderr matcher
Given a file named "output_to_stderr.rb" with:
"""ruby
- describe "output_to_stderr matcher" do
+ RSpec.describe "output_to_stderr matcher" do
specify { expect { warn('foo') }.to output.to_stderr }
specify { expect { warn('foo') }.to output("foo\n").to_stderr }
specify { expect { warn('foo') }.to output(/foo/).to_stderr }
View
42 features/built_in_matchers/predicates.feature
@@ -51,12 +51,12 @@ Feature: predicate matchers
Scenario: should be_zero (based on Fixnum#zero?)
Given a file named "should_be_zero_spec.rb" with:
"""ruby
- describe 0 do
- it { should be_zero }
+ RSpec.describe 0 do
+ it { is_expected.to be_zero }
end
- describe 7 do
- it { should be_zero } # deliberate failure
+ RSpec.describe 7 do
+ it { is_expected.to be_zero } # deliberate failure
end
"""
When I run `rspec should_be_zero_spec.rb`
@@ -66,12 +66,12 @@ Feature: predicate matchers
Scenario: should_not be_empty (based on Array#empty?)
Given a file named "should_not_be_empty_spec.rb" with:
"""ruby
- describe [1, 2, 3] do
- it { should_not be_empty }
+ RSpec.describe [1, 2, 3] do
+ it { is_expected.not_to be_empty }
end
- describe [] do
- it { should_not be_empty } # deliberate failure
+ RSpec.describe [] do
+ it { is_expected.not_to be_empty } # deliberate failure
end
"""
When I run `rspec should_not_be_empty_spec.rb`
@@ -81,10 +81,10 @@ Feature: predicate matchers
Scenario: should have_key (based on Hash#has_key?)
Given a file named "should_have_key_spec.rb" with:
"""ruby
- describe Hash do
+ RSpec.describe Hash do
subject { { :foo => 7 } }
- it { should have_key(:foo) }
- it { should have_key(:bar) } # deliberate failure
+ it { is_expected.to have_key(:foo) }
+ it { is_expected.to have_key(:bar) } # deliberate failure
end
"""
When I run `rspec should_have_key_spec.rb`
@@ -100,15 +100,15 @@ Feature: predicate matchers
end
end
- describe Hash do
+ RSpec.describe Hash do
context 'with symbol keys' do
subject { { :foo => 7, :bar => 5 } }
- it { should_not have_all_string_keys }
+ it { is_expected.not_to have_all_string_keys }
end
context 'with string keys' do
subject { { 'foo' => 7, 'bar' => 5 } }
- it { should_not have_all_string_keys } # deliberate failure
+ it { is_expected.not_to have_all_string_keys } # deliberate failure
end
end
"""
@@ -125,13 +125,13 @@ Feature: predicate matchers
end
end
- describe 12 do
- it { should be_multiple_of(3) }
- it { should_not be_multiple_of(7) }
+ RSpec.describe 12 do
+ it { is_expected.to be_multiple_of(3) }
+ it { is_expected.not_to be_multiple_of(7) }
# deliberate failures
- it { should_not be_multiple_of(4) }
- it { should be_multiple_of(5) }
+ it { is_expected.not_to be_multiple_of(4) }
+ it { is_expected.to be_multiple_of(5) }
end
"""
When I run `rspec predicate_matcher_argument_spec.rb`
@@ -149,11 +149,11 @@ Feature: predicate matchers
private :secret?
end
- describe 'private methods' do
+ RSpec.describe 'private methods' do
subject { WithPrivateMethods.new }
# deliberate failure
- it { should be_secret }
+ it { is_expected.to be_secret }
end
"""
When I run `rspec attempting_to_match_private_method_spec.rb`
View
18 features/built_in_matchers/raise_error.feature
@@ -31,7 +31,7 @@ Feature: raise_error matcher
Scenario: expect any error
Given a file named "example_spec" with:
"""
- describe "calling a missing method" do
+ RSpec.describe "calling a missing method" do
it "raises" do
expect { Object.new.foo }.to raise_error
end
@@ -43,7 +43,7 @@ Feature: raise_error matcher
Scenario: expect specific error
Given a file named "example_spec" with:
"""
- describe "calling a missing method" do
+ RSpec.describe "calling a missing method" do
it "raises" do
expect { Object.new.foo }.to raise_error(NameError)
end
@@ -55,7 +55,7 @@ Feature: raise_error matcher
Scenario: match message with a string
Given a file named "example_spec.rb" with:
"""ruby
- describe "matching error message with string" do
+ RSpec.describe "matching error message with string" do
it "matches the error message" do
expect { raise StandardError, 'this message exactly'}.
to raise_error('this message exactly')
@@ -68,7 +68,7 @@ Feature: raise_error matcher
Scenario: match message with a regexp
Given a file named "example_spec.rb" with:
"""ruby
- describe "matching error message with regex" do
+ RSpec.describe "matching error message with regex" do
it "matches the error message" do
expect { raise StandardError, "my message" }.
to raise_error(/my mess/)
@@ -81,7 +81,7 @@ Feature: raise_error matcher
Scenario: matching message with `with_message`
Given a file named "example_spec.rb" with:
"""ruby
- describe "matching error message with regex" do
+ RSpec.describe "matching error message with regex" do
it "matches the error message" do
expect { raise StandardError, "my message" }.
to raise_error.with_message(/my mess/)
@@ -94,7 +94,7 @@ Feature: raise_error matcher
Scenario: match type + message with string
Given a file named "example_spec.rb" with:
"""ruby
- describe "matching error message with string" do
+ RSpec.describe "matching error message with string" do
it "matches the error message" do
expect { raise StandardError, 'this message exactly'}.
to raise_error(StandardError, 'this message exactly')
@@ -107,7 +107,7 @@ Feature: raise_error matcher
Scenario: match type + message with regexp
Given a file named "example_spec.rb" with:
"""ruby
- describe "matching error message with regex" do
+ RSpec.describe "matching error message with regex" do
it "matches the error message" do
expect { raise StandardError, "my message" }.
to raise_error(StandardError, /my mess/)
@@ -120,7 +120,7 @@ Feature: raise_error matcher
Scenario: set expectations on error object passed to block
Given a file named "example_spec" with:
"""
- describe "#foo" do
+ RSpec.describe "#foo" do
it "raises NameError" do
expect { Object.new.foo }.to raise_error { |error|
expect(error).to be_a(NameError)
@@ -134,7 +134,7 @@ Feature: raise_error matcher
Scenario: expect no error at all
Given a file named "example_spec" with:
"""
- describe "#to_s" do
+ RSpec.describe "#to_s" do
it "does not raise" do
expect { Object.new.to_s }.not_to raise_error
end
View
40 features/built_in_matchers/respond_to.feature
@@ -29,22 +29,22 @@ Feature: respond_to matcher
Scenario: basic usage
Given a file named "respond_to_matcher_spec.rb" with:
"""ruby
- describe "a string" do
- it { should respond_to(:length) }
- it { should respond_to(:hash, :class, :to_s) }
- it { should_not respond_to(:to_model) }
- it { should_not respond_to(:compact, :flatten) }
+ RSpec.describe "a string" do
+ it { is_expected.to respond_to(:length) }
+ it { is_expected.to respond_to(:hash, :class, :to_s) }
+ it { is_expected.not_to respond_to(:to_model) }
+ it { is_expected.not_to respond_to(:compact, :flatten) }
# deliberate failures
- it { should respond_to(:to_model) }
- it { should respond_to(:compact, :flatten) }
- it { should_not respond_to(:length) }
- it { should_not respond_to(:hash, :class, :to_s) }
+ it { is_expected.to respond_to(:to_model) }
+ it { is_expected.to respond_to(:compact, :flatten) }
+ it { is_expected.not_to respond_to(:length) }
+ it { is_expected.not_to respond_to(:hash, :class, :to_s) }
# mixed examples--String responds to :length but not :flatten
# both specs should fail
- it { should respond_to(:length, :flatten) }
- it { should_not respond_to(:length, :flatten) }
+ it { is_expected.to respond_to(:length, :flatten) }
+ it { is_expected.not_to respond_to(:length, :flatten) }
end
"""
When I run `rspec respond_to_matcher_spec.rb`
@@ -60,19 +60,19 @@ Feature: respond_to matcher
Scenario: specify arguments
Given a file named "respond_to_matcher_argument_checking_spec.rb" with:
"""ruby
- describe 7 do
- it { should respond_to(:zero?).with(0).arguments }
- it { should_not respond_to(:zero?).with(1).argument }
+ RSpec.describe 7 do
+ it { is_expected.to respond_to(:zero?).with(0).arguments }
+ it { is_expected.not_to respond_to(:zero?).with(1).argument }
- it { should respond_to(:between?).with(2).arguments }
- it { should_not respond_to(:between?).with(7).arguments }
+ it { is_expected.to respond_to(:between?).with(2).arguments }
+ it { is_expected.not_to respond_to(:between?).with(7).arguments }
# deliberate failures
- it { should respond_to(:zero?).with(1).argument }
- it { should_not respond_to(:zero?).with(0).arguments }
+ it { is_expected.to respond_to(:zero?).with(1).argument }
+ it { is_expected.not_to respond_to(:zero?).with(0).arguments }
- it { should respond_to(:between?).with(7).arguments }
- it { should_not respond_to(:between?).with(2).arguments }
+ it { is_expected.to respond_to(:between?).with(7).arguments }
+ it { is_expected.not_to respond_to(:between?).with(2).arguments }
end
"""
When I run `rspec respond_to_matcher_argument_checking_spec.rb`
View
10 features/built_in_matchers/satisfy.feature
@@ -16,13 +16,13 @@ Feature: satisfy matcher
Scenario: basic usage
Given a file named "satisfy_matcher_spec.rb" with:
"""ruby
- describe 10 do
- it { should satisfy { |v| v > 5 } }
- it { should_not satisfy { |v| v > 15 } }
+ RSpec.describe 10 do
+ it { is_expected.to satisfy { |v| v > 5 } }
+ it { is_expected.not_to satisfy { |v| v > 15 } }
# deliberate failures
- it { should_not satisfy { |v| v > 5 } }
- it { should satisfy { |v| v > 15 } }
+ it { is_expected.not_to satisfy { |v| v > 5 } }
+ it { is_expected.to satisfy { |v| v > 15 } }
end
"""
When I run `rspec satisfy_matcher_spec.rb`
View
24 features/built_in_matchers/start_with.feature
@@ -12,13 +12,13 @@ Feature: start_with matcher
Scenario: with a string
Given a file named "example_spec.rb" with:
"""ruby
- describe "this string" do
- it { should start_with "this" }
- it { should_not start_with "that" }
+ RSpec.describe "this string" do
+ it { is_expected.to start_with "this" }
+ it { is_expected.not_to start_with "that" }
# deliberate failures
- it { should_not start_with "this" }
- it { should start_with "that" }
+ it { is_expected.not_to start_with "this" }
+ it { is_expected.to start_with "that" }
end
"""
When I run `rspec example_spec.rb`
@@ -30,15 +30,15 @@ Feature: start_with matcher
Scenario: with an array
Given a file named "example_spec.rb" with:
"""ruby
- describe [0, 1, 2, 3, 4] do
- it { should start_with 0 }
- it { should start_with(0, 1)}
- it { should_not start_with(2) }
- it { should_not start_with(0, 1, 2, 3, 4, 5) }
+ RSpec.describe [0, 1, 2, 3, 4] do
+ it { is_expected.to start_with 0 }
+ it { is_expected.to start_with(0, 1)}
+ it { is_expected.not_to start_with(2) }
+ it { is_expected.not_to start_with(0, 1, 2, 3, 4, 5) }
# deliberate failures
- it { should_not start_with 0 }
- it { should start_with 3 }
+ it { is_expected.not_to start_with 0 }
+ it { is_expected.to start_with 3 }
end
"""
When I run `rspec example_spec.rb`
View
6 features/built_in_matchers/throw_symbol.feature
@@ -23,7 +23,7 @@ Feature: throw_symbol matcher
Scenario: basic usage
Given a file named "throw_symbol_matcher_spec.rb" with:
"""ruby
- describe "throw" do
+ RSpec.describe "throw" do
specify { expect { throw :foo }.to throw_symbol }
specify { expect { throw :bar, 7 }.to throw_symbol }
specify { expect { 5 + 5 }.not_to throw_symbol }
@@ -44,7 +44,7 @@ Feature: throw_symbol matcher
Scenario: specify thrown symbol
Given a file named "throw_symbol_matcher_spec.rb" with:
"""ruby
- describe "throw symbol" do
+ RSpec.describe "throw symbol" do
specify { expect { throw :foo }.to throw_symbol(:foo) }
specify { expect { throw :foo, 7 }.to throw_symbol(:foo) }
specify { expect { 5 + 5 }.not_to throw_symbol(:foo) }
@@ -68,7 +68,7 @@ Feature: throw_symbol matcher
Scenario: specify thrown symbol and argument
Given a file named "throw_symbol_argument_matcher_spec.rb" with:
"""ruby
- describe "throw symbol with argument" do
+ RSpec.describe "throw symbol with argument" do
specify { expect { throw :foo, 7 }.to throw_symbol(:foo, 7) }
specify { expect { throw :foo, 8 }.not_to throw_symbol(:foo, 7) }
specify { expect { throw :bar, 7 }.not_to throw_symbol(:foo, 7) }
View
84 features/built_in_matchers/types.feature
@@ -26,40 +26,40 @@ Feature: specify types of objects
include MyModule
end
- describe 17 do
+ RSpec.describe 17 do
# the actual class
- it { should be_kind_of(Fixnum) }
- it { should be_a_kind_of(Fixnum) }
- it { should be_a(Fixnum) }
+ it { is_expected.to be_kind_of(Fixnum) }
+ it { is_expected.to be_a_kind_of(Fixnum) }
+ it { is_expected.to be_a(Fixnum) }
# the superclass
- it { should be_kind_of(Integer) }
- it { should be_a_kind_of(Integer) }
- it { should be_an(Integer) }
+ it { is_expected.to be_kind_of(Integer) }
+ it { is_expected.to be_a_kind_of(Integer) }
+ it { is_expected.to be_an(Integer) }
# an included module
- it { should be_kind_of(MyModule) }
- it { should be_a_kind_of(MyModule) }
- it { should be_a(MyModule) }
+ it { is_expected.to be_kind_of(MyModule) }
+ it { is_expected.to be_a_kind_of(MyModule) }
+ it { is_expected.to be_a(MyModule) }
# negative passing case
- it { should_not be_kind_of(String) }
- it { should_not be_a_kind_of(String) }
- it { should_not be_a(String) }
+ it { is_expected.not_to be_kind_of(String) }
+ it { is_expected.not_to be_a_kind_of(String) }
+ it { is_expected.not_to be_a(String) }
# deliberate failures
- it { should_not be_kind_of(Fixnum) }
- it { should_not be_a_kind_of(Fixnum) }
- it { should_not be_a(Fixnum) }
- it { should_not be_kind_of(Integer) }
- it { should_not be_a_kind_of(Integer) }
- it { should_not be_an(Integer) }
- it { should_not be_kind_of(MyModule) }
- it { should_not be_a_kind_of(MyModule) }
- it { should_not be_a(MyModule) }
- it { should be_kind_of(String) }
- it { should be_a_kind_of(String) }
- it { should be_a(String) }
+ it { is_expected.not_to be_kind_of(Fixnum) }
+ it { is_expected.not_to be_a_kind_of(Fixnum) }
+ it { is_expected.not_to be_a(Fixnum) }
+ it { is_expected.not_to be_kind_of(Integer) }
+ it { is_expected.not_to be_a_kind_of(Integer) }
+ it { is_expected.not_to be_an(Integer) }
+ it { is_expected.not_to be_kind_of(MyModule) }
+ it { is_expected.not_to be_a_kind_of(MyModule) }
+ it { is_expected.not_to be_a(MyModule) }
+ it { is_expected.to be_kind_of(String) }
+ it { is_expected.to be_a_kind_of(String) }
+ it { is_expected.to be_a(String) }
end
"""
When I run `rspec be_kind_of_matcher_spec.rb`
@@ -79,32 +79,32 @@ Feature: specify types of objects
include MyModule
end
- describe 17 do
+ RSpec.describe 17 do
# the actual class
- it { should be_instance_of(Fixnum) }
- it { should be_an_instance_of(Fixnum) }
+ it { is_expected.to be_instance_of(Fixnum) }
+ it { is_expected.to be_an_instance_of(Fixnum) }
# the superclass
- it { should_not be_instance_of(Integer) }
- it { should_not be_an_instance_of(Integer) }
+ it { is_expected.not_to be_instance_of(Integer) }
+ it { is_expected.not_to be_an_instance_of(Integer) }
# an included module
- it { should_not be_instance_of(MyModule) }
- it { should_not be_an_instance_of(MyModule) }
+ it { is_expected.not_to be_instance_of(MyModule) }
+ it { is_expected.not_to be_an_instance_of(MyModule) }
# another class with no relation to the subject's hierarchy
- it { should_not be_instance_of(String) }
- it { should_not be_an_instance_of(String) }
+ it { is_expected.not_to be_instance_of(String) }
+ it { is_expected.not_to be_an_instance_of(String) }
# deliberate failures
- it { should_not be_instance_of(Fixnum) }
- it { should_not be_an_instance_of(Fixnum) }
- it { should be_instance_of(Integer) }
- it { should be_an_instance_of(Integer) }
- it { should be_instance_of(MyModule) }
- it { should be_an_instance_of(MyModule) }
- it { should be_instance_of(String) }
- it { should be_an_instance_of(String) }
+ it { is_expected.not_to be_instance_of(Fixnum) }
+ it { is_expected.not_to be_an_instance_of(Fixnum) }
+ it { is_expected.to be_instance_of(Integer) }
+ it { is_expected.to be_an_instance_of(Integer) }
+ it { is_expected.to be_instance_of(MyModule) }
+ it { is_expected.to be_an_instance_of(MyModule) }
+ it { is_expected.to be_instance_of(String) }
+ it { is_expected.to be_an_instance_of(String) }
end
"""
When I run `rspec be_instance_of_matcher_spec.rb`
View
8 features/built_in_matchers/yield.feature
@@ -48,7 +48,7 @@ Feature: yield matchers
"""ruby
require './my_class'
- describe "yield_control matcher" do
+ RSpec.describe "yield_control matcher" do
specify { expect { |b| MyClass.yield_once_with(1, &b) }.to yield_control }
specify { expect { |b| MyClass.dont_yield(&b) }.not_to yield_control }
specify { expect { |b| MyClass.yield_twice_with(1, &b) }.to yield_control.twice }
@@ -79,7 +79,7 @@ Feature: yield matchers
"""ruby
require './my_class'
- describe "yield_with_args matcher" do
+ RSpec.describe "yield_with_args matcher" do
specify { expect { |b| MyClass.yield_once_with("foo", &b) }.to yield_with_args }
specify { expect { |b| MyClass.yield_once_with("foo", &b) }.to yield_with_args("foo") }
specify { expect { |b| MyClass.yield_once_with("foo", &b) }.to yield_with_args(String) }
@@ -112,7 +112,7 @@ Feature: yield matchers
"""ruby
require './my_class'
- describe "yield_with_no_args matcher" do
+ RSpec.describe "yield_with_no_args matcher" do
specify { expect { |b| MyClass.raw_yield(&b) }.to yield_with_no_args }
specify { expect { |b| MyClass.dont_yield(&b) }.not_to yield_with_no_args }
specify { expect { |b| MyClass.yield_once_with("a", &b) }.not_to yield_with_no_args }
@@ -141,7 +141,7 @@ Feature: yield matchers
[[:a, :b], [:c, :d]]
end
- describe "yield_successive_args matcher" do
+ RSpec.describe "yield_successive_args matcher" do
specify { expect { |b| array.each(&b) }.to yield_successive_args(1, 2, 3) }
specify { expect { |b| array_of_tuples.each(&b) }.to yield_successive_args([:a, :b], [:c, :d]) }
specify { expect { |b| array.each(&b) }.to yield_successive_args(Fixnum, Fixnum, Fixnum) }
View
24 features/composing_matchers.feature
@@ -51,7 +51,7 @@ Feature: Composing Matchers
Scenario: Composing matchers with `change`
Given a file named "change_spec.rb" with:
"""
- describe "Passing matchers to `change`" do
+ RSpec.describe "Passing matchers to `change`" do
specify "you can pass a matcher to `by`" do
k = 0
expect { k += 1.05 }.to change { k }.
@@ -72,7 +72,7 @@ Feature: Composing Matchers
Scenario: Composing matchers with `contain_exactly`
Given a file named "contain_exactly_spec.rb" with:
"""
- describe "Passing matchers to `contain_exactly`" do
+ RSpec.describe "Passing matchers to `contain_exactly`" do
specify "you can pass matchers in place of exact values" do
expect(["barn", 2.45]).to contain_exactly(
a_value_within(0.1).of(2.5),
@@ -87,7 +87,7 @@ Feature: Composing Matchers
Scenario: Composing matchers with `end_with`
Given a file named "end_with_spec.rb" with:
"""
- describe "Passing matchers to `end_with`" do
+ RSpec.describe "Passing matchers to `end_with`" do
specify "you can pass matchers in place of exact values" do
expect(["barn", "food", 2.45]).to end_with(
a_string_matching("foo"),
@@ -102,7 +102,7 @@ Feature: Composing Matchers
Scenario: Composing matchers with `include`
Given a file named "include_spec.rb" with:
"""
- describe "Passing matchers to `contain_exactly`" do
+ RSpec.describe "Passing matchers to `contain_exactly`" do
specify "you can use matchers in place of array values" do
expect(["barn", 2.45]).to include( a_string_starting_with("bar") )
end
@@ -122,7 +122,7 @@ Feature: Composing Matchers
Scenario: Composing matchers with `match`:
Given a file named "match_spec.rb" with:
"""
- describe "Passing matchers to `match`" do
+ RSpec.describe "Passing matchers to `match`" do
specify "you can match nested data structures against matchers" do
hash = {
:a => {
@@ -149,7 +149,7 @@ Feature: Composing Matchers
Scenario: Composing matchers with `output`
Given a file named "output_spec.rb" with:
"""
- describe "Passing matchers to `output`" do
+ RSpec.describe "Passing matchers to `output`" do
specify "you can pass a matcher in place of the output (to_stdout)" do
expect {
print 'foo'
@@ -168,7 +168,7 @@ Feature: Composing Matchers
Scenario: Composing matchers with `raise_error`
Given a file named "raise_error_spec.rb" with:
"""
- describe "Passing matchers to `raise_error`" do
+ RSpec.describe "Passing matchers to `raise_error`" do
specify "you can pass a matcher in place of the message" do
expect {
raise RuntimeError, "this goes boom"
@@ -182,7 +182,7 @@ Feature: Composing Matchers
Scenario: Composing matchers with `start_with`
Given a file named "start_with_spec.rb" with:
"""
- describe "Passing matchers to `start_with`" do
+ RSpec.describe "Passing matchers to `start_with`" do
specify "you can pass matchers in place of exact values" do
expect(["barn", "food", 2.45]).to start_with(
a_string_matching("bar"),
@@ -197,7 +197,7 @@ Feature: Composing Matchers
Scenario: Composing matchers with `throw_symbol`
Given a file named "throw_symbol_spec.rb" with:
"""
- describe "Passing matchers to `throw_symbol`" do
+ RSpec.describe "Passing matchers to `throw_symbol`" do
specify "you can pass a matcher in place of a throw arg" do
expect {
throw :pi, Math::PI
@@ -211,7 +211,7 @@ Feature: Composing Matchers
Scenario: Composing matchers with `yield_with_args`
Given a file named "yield_with_args_spec.rb" with:
"""
- describe "Passing matchers to `yield_with_args`" do
+ RSpec.describe "Passing matchers to `yield_with_args`" do
specify "you can pass matchers in place of the args" do
expect { |probe|
"food".tap(&probe)
@@ -225,7 +225,7 @@ Feature: Composing Matchers
Scenario: Composing matchers with `yield_successive_args`
Given a file named "yield_successive_args_spec.rb" with:
"""
- describe "Passing matchers to `yield_successive_args`" do
+ RSpec.describe "Passing matchers to `yield_successive_args`" do
specify "you can pass matchers in place of the args" do
expect { |probe|
[1, 2, 3].each(&probe)
@@ -239,7 +239,7 @@ Feature: Composing Matchers
Scenario: Composing matchers using a compound `and` expression
Given a file named "include_spec.rb" with:
"""
- describe "Passing a compound matcher expression to `include`" do
+ RSpec.describe "Passing a compound matcher expression to `include`" do
example do
expect(["food", "drink"]).to include( a_string_starting_with("f").and ending_with("d"))
end
View
4 features/compound_expectations.feature
@@ -5,7 +5,7 @@ Feature: Compound Expectations
Scenario: Use `and` to chain expectations
Given a file named "compound_and_matcher_spec.rb" with:
"""ruby
- describe "A compound `and` matcher" do
+ RSpec.describe "A compound `and` matcher" do
let(:string) { "foo bar bazz" }
it "passes when both are true" do
@@ -33,7 +33,7 @@ Feature: Compound Expectations
end
end
- describe StopLight, "#color" do
+ RSpec.describe StopLight, "#color" do
it "is green, yellow or red" do
light = StopLight.new
expect(light.color).to eq("green").or eq("yellow").or eq("red")
View
4 features/custom_matchers/access_running_example.feature
@@ -14,7 +14,7 @@ Feature: access running example
end
end
- describe "something" do
+ RSpec.describe "something" do
def foo
"foo"
end
@@ -36,7 +36,7 @@ Feature: access running example
end
end
- describe "something" do
+ RSpec.describe "something" do
it "does something" do
expect("foo").to bar
end
View
4 features/custom_matchers/define_diffable_matcher.feature
@@ -15,8 +15,8 @@ Feature: define diffable matcher
diffable
end
- describe "two\nlines" do
- it { should be_just_like("three\nlines") }
+ RSpec.describe "two\nlines" do
+ it { is_expected.to be_just_like("three\nlines") }
end
"""
When I run `rspec ./diffable_matcher_spec.rb`
View
86 features/custom_matchers/define_matcher.feature
@@ -15,32 +15,31 @@ Feature: define matcher
end
end
- describe 9 do
- it {should be_a_multiple_of(3)}
+ RSpec.describe 9 do
+ it { is_expected.to be_a_multiple_of(3) }
end
- describe 9 do
- it {should_not be_a_multiple_of(4)}
+ RSpec.describe 9 do
+ it { is_expected.not_to be_a_multiple_of(4) }
end
# fail intentionally to generate expected output
- describe 9 do
- it {should be_a_multiple_of(4)}
+ RSpec.describe 9 do
+ it { is_expected.to be_a_multiple_of(4) }
end
# fail intentionally to generate expected output
- describe 9 do
- it {should_not be_a_multiple_of(3)}
+ RSpec.describe 9 do
+ it { is_expected.not_to be_a_multiple_of(3) }
end
-
"""
When I run `rspec ./matcher_with_default_message_spec.rb --format documentation`
Then the exit status should not be 0
And the output should contain "should be a multiple of 3"
And the output should contain "should not be a multiple of 4"
- And the output should contain "Failure/Error: it {should be_a_multiple_of(4)}"
- And the output should contain "Failure/Error: it {should_not be_a_multiple_of(3)}"
+ And the output should contain "Failure/Error: it { is_expected.to be_a_multiple_of(4) }"
+ And the output should contain "Failure/Error: it { is_expected.not_to be_a_multiple_of(3) }"
And the output should contain "4 examples, 2 failures"
And the output should contain "expected 9 to be a multiple of 4"
@@ -61,8 +60,8 @@ Feature: define matcher
end
# fail intentionally to generate expected output
- describe 9 do
- it {should be_a_multiple_of(4)}
+ RSpec.describe 9 do
+ it { is_expected.to be_a_multiple_of(4) }
end
"""
When I run `rspec ./matcher_with_failure_message_spec.rb`
@@ -85,8 +84,8 @@ Feature: define matcher
end
# fail intentionally to generate expected output
- describe 9 do
- it {should_not be_a_multiple_of(3)}
+ RSpec.describe 9 do
+ it { is_expected.not_to be_a_multiple_of(3) }
end
"""
When I run `rspec ./matcher_with_failure_for_message_spec.rb`
@@ -108,12 +107,12 @@ Feature: define matcher
end
end
- describe 9 do
- it {should be_a_multiple_of(3)}
+ RSpec.describe 9 do
+ it { is_expected.to be_a_multiple_of(3) }
end
- describe 9 do
- it {should_not be_a_multiple_of(4)}
+ RSpec.describe 9 do
+ it { is_expected.not_to be_a_multiple_of(4) }
end
"""
When I run `rspec ./matcher_overriding_description_spec.rb --format documentation`
@@ -137,8 +136,8 @@ Feature: define matcher
def fingers; (1..7).collect {"finger"}; end
end
- describe Thing do
- it {should have_7_fingers}
+ RSpec.describe Thing do
+ it { is_expected.to have_7_fingers }
end
"""
When I run `rspec ./matcher_with_no_args_spec.rb --format documentation`
@@ -157,8 +156,8 @@ Feature: define matcher
end
end
- describe 10 do
- it {should be_the_sum_of(1,2,3,4)}
+ RSpec.describe 10 do
+ it { is_expected.to be_the_sum_of(1,2,3,4) }
end
"""
When I run `rspec ./matcher_with_multiple_args_spec.rb --format documentation`
@@ -181,7 +180,7 @@ Feature: define matcher
end
end
- describe "these two arrays" do
+ RSpec.describe "these two arrays" do
specify "should be similar" do
expect([1,2,3]).to have_same_elements_as([2,3,1])
end
@@ -204,14 +203,14 @@ Feature: define matcher
end
end
- describe "group with MyHelpers" do
+ RSpec.describe "group with MyHelpers" do
include MyHelpers
it "has access to the defined matcher" do
expect(5).to be_just_like(5)
end
end
- describe "group without MyHelpers" do
+ RSpec.describe "group without MyHelpers" do
it "does not have access to the defined matcher" do
expect do
expect(5).to be_just_like(5)
@@ -228,7 +227,7 @@ Feature: define matcher
"""ruby
require 'rspec/expectations'
- describe "group with matcher" do
+ RSpec.describe "group with matcher" do
matcher :be_just_like do |expected|
match {|actual| actual == expected}
end
@@ -242,10 +241,9 @@ Feature: define matcher
expect(5).to be_just_like(5)
end
end
-
end
- describe "group without matcher" do
+ RSpec.describe "group without matcher" do
it "does not have access to the defined matcher" do
expect do
expect(5).to be_just_like(5)
@@ -270,13 +268,13 @@ Feature: define matcher
end
end
- describe [1, 2, 3] do
- it { should contain(1, 2) }
- it { should_not contain(4, 5, 6) }
+ RSpec.describe [1, 2, 3] do
+ it { is_expected.to contain(1, 2) }
+ it { is_expected.not_to contain(4, 5, 6) }
# deliberate failures
- it { should contain(1, 4) }
- it { should_not contain(1, 4) }
+ it { is_expected.to contain(1, 4) }
+ it { is_expected.not_to contain(1, 4) }
end
"""
When I run `rspec matcher_with_separate_should_not_logic_spec.rb`
@@ -295,13 +293,13 @@ Feature: define matcher
match { |actual| is_multiple?(actual) }
end
- describe 9 do
- it { should be_a_multiple_of(3) }
- it { should_not be_a_multiple_of(4) }
+ RSpec.describe 9 do
+ it { is_expected.to be_a_multiple_of(3) }
+ it { is_expected.not_to be_a_multiple_of(4) }
# deliberate failures
- it { should be_a_multiple_of(2) }
- it { should_not be_a_multiple_of(3) }
+ it { is_expected.to be_a_multiple_of(2) }
+ it { is_expected.not_to be_a_multiple_of(3) }
end
"""
When I run `rspec define_method_spec.rb`
@@ -324,13 +322,13 @@ Feature: define matcher
match { |actual| is_multiple?(actual, expected) }
end
- describe 9 do
- it { should be_a_multiple_of(3) }
- it { should_not be_a_multiple_of(4) }
+ RSpec.describe 9 do
+ it { is_expected.to be_a_multiple_of(3) }
+ it { is_expected.not_to be_a_multiple_of(4) }
# deliberate failures
- it { should be_a_multiple_of(2) }
- it { should_not be_a_multiple_of(3) }
+ it { is_expected.to be_a_multiple_of(2) }
+ it { is_expected.not_to be_a_multiple_of(3) }
end
"""
When I run `rspec include_module_spec.rb`
View
4 features/custom_matchers/define_matcher_with_fluent_interface.feature
@@ -15,8 +15,8 @@ Feature: define matcher with fluent interface
end
end
- describe 5 do
- it { should be_bigger_than(4).but_smaller_than(6) }
+ RSpec.describe 5 do
+ it { is_expected.to be_bigger_than(4).but_smaller_than(6) }
end
"""
When I run `rspec between_spec.rb --format documentation`
View
4 features/customized_message.feature
@@ -7,7 +7,7 @@ Feature: customized message
Scenario: customize failure message
Given a file named "example_spec.rb" with:
"""ruby
- describe Array do
+ RSpec.describe Array do
context "when created with `new`" do
it "is empty" do
array = Array.new
@@ -24,7 +24,7 @@ Feature: customized message
Scenario: customize failure message with a proc
Given a file named "example_spec.rb" with:
"""ruby
- describe Array do
+ RSpec.describe Array do
context "when created with `new`" do
it "is empty" do
array = Array.new
View
8 features/diffing.feature
@@ -5,7 +5,7 @@ Feature: diffing
Scenario: diff for a multiline string
Given a file named "example_spec.rb" with:
"""ruby
- describe "a multiline string" do
+ RSpec.describe "a multiline string" do
it "is like another string" do
expected = <<-EXPECTED
this is the
@@ -35,7 +35,7 @@ Feature: diffing
Scenario: diff for a multiline string and a regexp
Given a file named "example_spec.rb" with:
"""ruby
- describe "a multiline string" do
+ RSpec.describe "a multiline string" do
it "is like another string" do
expected = /expected/m
actual = <<-ACTUAL
@@ -61,7 +61,7 @@ Feature: diffing
Scenario: no diff for a single line strings
Given a file named "example_spec.rb" with:
"""ruby
- describe "a single line string" do
+ RSpec.describe "a single line string" do
it "is like another string" do
expected = "this string"
actual = "that string"
@@ -75,7 +75,7 @@ Feature: diffing
Scenario: no diff for numbers
Given a file named "example_spec.rb" with:
"""ruby
- describe "a number" do
+ RSpec.describe "a number" do
it "is like another number" do
expect(1).to eq(2)
end
View
4 features/implicit_docstrings.feature
@@ -17,7 +17,7 @@ Feature: implicit docstrings
Scenario: run passing examples
Given a file named "implicit_docstrings_spec.rb" with:
"""ruby
- describe "Examples with no docstrings generate their own:" do
+ RSpec.describe "Examples with no docstrings generate their own:" do
specify { expect(3).to be < 5 }
specify { expect([1,2,3]).to include(2) }
specify { expect([1,2,3]).to respond_to(:size) }
@@ -33,7 +33,7 @@ Feature: implicit docstrings
Scenario: run failing examples
Given a file named "failing_implicit_docstrings_spec.rb" with:
"""ruby
- describe "Failing examples with no descriptions" do
+ RSpec.describe "Failing examples with no descriptions" do
# description is auto-generated as "to equal(5)" based on the last #expect
it do
expect(3).to equal(2)
View
34 features/support/disallow_certain_apis.rb
@@ -0,0 +1,34 @@
+# This file is designed to prevent the use of certain APIs that
+# we don't want used from our cukes, since they function as documentation.
+
+if defined?(Cucumber)
+ require 'shellwords'
+ Before('~@allow-disallowed-api') do
+ set_env('SPEC_OPTS', "-r#{Shellwords.escape(__FILE__)}")
+ end
+else
+ module DisallowOneLinerShould
+ def should(*)
+ raise "one-liner should is not allowed"
+ end
+
+ def should_not(*)
+ raise "one-liner should_not is not allowed"
+ end
+ end
+
+ RSpec.configure do |rspec|
+ rspec.expose_dsl_globally = false
+
+ rspec.mock_with :rspec do |mocks|
+ mocks.syntax = :expect
+ end
+
+ rspec.expect_with :rspec do |expectations|
+ expectations.syntax = :expect
+ end
+
+ rspec.include DisallowOneLinerShould
+ end
+end
+
View
5 features/syntax_configuration.feature
@@ -1,3 +1,4 @@
+@allow-disallowed-api
Feature: Syntax Configuration
In addition to the long-supported `should` syntax, rspec-expectations
@@ -7,14 +8,14 @@ Feature: Syntax Configuration
Background:
Given a file named "syntaxes_spec.rb" with:
"""ruby
- describe "using the should syntax" do
+ RSpec.describe "using the should syntax" do
specify { 3.should eq(3) }
specify { 3.should_not eq(4) }
specify { lambda { raise "boom" }.should raise_error("boom") }
specify { lambda { }.should_not raise_error }
end
- describe "using the expect syntax" do
+ RSpec.describe "using the expect syntax" do
specify { expect(3).to eq(3) }
specify { expect(3).not_to eq(4) }
specify { expect { raise "boom" }.to raise_error("boom") }

0 comments on commit 75a470f

Please sign in to comment.
Something went wrong with that request. Please try again.