Permalink
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...
myronmarston committed Feb 20, 2014
1 parent 2cf24eb commit 75a470fddb22074c90405b009d3869b188ba1047
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
@@ -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
@@ -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
@@ -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 }
@@ -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`
@@ -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
@@ -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" }
@@ -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) }
@@ -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`
@@ -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`
@@ -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)
@@ -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 }
Oops, something went wrong.

0 comments on commit 75a470f

Please sign in to comment.