Permalink
Browse files

Rewrite cucumber features.

The old cukes were a mess:

- Lots of duplication and inconsistencies.
- Functioned poorly as documentation.
- Didn't highlight the new syntax well.
- Didn't really cover all of rspec-mocks' features.

The new ones were structurd specifically with documentation in mind.
The specs are meant more for regression coverage. We've limited the
cukes to just things people may actually want to read as part of
docs.

I've also reworked the test unit cuke as a minitest cuke.

For reference, here's the before/after from cucumber:

Before:

77 scenarios (77 passed)
276 steps (276 passed)
0m48.014s

After:

89 scenarios (89 passed)
328 steps (328 passed)
0m57.844s

Fixes #591.
  • Loading branch information...
1 parent 0ecaa32 commit 8338a78be01e5638c0758b42c70377d571b0cdc7 @myronmarston myronmarston committed Jun 5, 2014
Showing with 2,139 additions and 1,816 deletions.
  1. +0 −1 Gemfile
  2. +35 −25 features/.nav
  3. +47 −46 features/README.md
  4. +0 −17 features/Scope.md
  5. +0 −27 features/argument_matchers/README.md
  6. +0 −31 features/argument_matchers/explicit.feature
  7. +0 −85 features/argument_matchers/general_matchers.feature
  8. +0 −26 features/argument_matchers/type_matchers.feature
  9. +35 −0 features/basics/allowing_messages.feature
  10. +73 −0 features/basics/expecting_messages.feature
  11. +35 −0 features/basics/null_object_doubles.feature
  12. +70 −0 features/basics/partial_test_doubles.feature
  13. +99 −0 features/basics/scope.feature
  14. +144 −0 features/basics/spies.feature
  15. +41 −0 features/basics/test_doubles.feature
  16. +12 −0 features/configuring_responses/README.md
  17. +131 −0 features/configuring_responses/block_implementation.feature
  18. +52 −0 features/configuring_responses/calling_the_original_implementation.feature
  19. +28 −0 features/configuring_responses/raising_an_error.feature
  20. +52 −0 features/configuring_responses/returning_a_value.feature
  21. +36 −0 features/configuring_responses/throwing.feature
  22. +76 −0 features/configuring_responses/yielding.feature
  23. +0 −75 features/message_expectations/README.md
  24. +0 −26 features/message_expectations/allow_any_instance_of.feature
  25. +0 −43 features/message_expectations/any_instance.feature
  26. +0 −55 features/message_expectations/block_local_expectations.feature.pending
  27. +0 −23 features/message_expectations/call_original.feature
  28. +0 −107 features/message_expectations/expect_message_using_expect.feature
  29. +0 −118 features/message_expectations/expect_message_using_should_receive.feature
  30. +0 −49 features/message_expectations/message_chains_using_expect.feature
  31. +0 −209 features/message_expectations/receive_counts.feature
  32. +0 −50 features/message_expectations/warn_when_expectation_is_set_on_nil.feature
  33. +0 −77 features/method_stubs/README.md
  34. +0 −136 features/method_stubs/allow_any_instance_of.feature
  35. +0 −40 features/method_stubs/as_null_object.feature
  36. +0 −51 features/method_stubs/receive_message_chain.feature
  37. +0 −44 features/method_stubs/simple_return_value_with_allow.feature
  38. +0 −64 features/method_stubs/simple_return_value_with_stub.feature
  39. +0 −48 features/method_stubs/stub_implementation.feature
  40. +0 −51 features/method_stubs/to_ary.feature
  41. +9 −13 features/mutating_constants/README.md
  42. +4 −4 features/mutating_constants/{hiding_defined_constant.feature → hide_defined_constant.feature}
  43. +22 −0 features/mutating_constants/hide_undefined_constant.feature
  44. +5 −6 features/mutating_constants/stub_defined_constant.feature
  45. +6 −6 features/mutating_constants/stub_undefined_constant.feature
  46. +35 −0 features/old_syntax/README.md
  47. +105 −0 features/old_syntax/any_instance.feature
  48. +90 −0 features/old_syntax/should_receive.feature
  49. +51 −0 features/old_syntax/stub.feature
  50. +69 −0 features/old_syntax/stub_chain.feature
  51. +43 −0 features/old_syntax/unstub.feature
  52. +80 −0 features/outside_rspec/minitest.feature
  53. +10 −10 features/outside_rspec/standalone.feature
  54. +6 −0 features/setting_constraints/README.md
  55. +97 −0 features/setting_constraints/matching_arguments.feature
  56. +63 −0 features/setting_constraints/message_order.feature
  57. +189 −0 features/setting_constraints/receive_counts.feature
  58. +0 −34 features/spies/spy_partial_mock_method.feature
  59. +0 −76 features/spies/spy_pure_mock_method.feature
  60. +0 −18 features/spies/spy_unstubbed_method.feature
  61. +15 −5 features/step_definitions/additional_cli_steps.rb
  62. +24 −0 features/support/disallow_certain_apis.rb
  63. +0 −54 features/test_frameworks/test_unit.feature
  64. +11 −15 features/verifying_doubles/README.md
  65. +8 −11 features/verifying_doubles/class_doubles.feature
  66. +8 −10 features/verifying_doubles/dynamic_classes.feature
  67. +6 −8 features/verifying_doubles/instance_doubles.feature
  68. +13 −16 features/verifying_doubles/object_doubles.feature
  69. +5 −5 features/verifying_doubles/partial_doubles.feature
  70. +3 −0 features/working_with_legacy_code/README.md
  71. +115 −0 features/working_with_legacy_code/any_instance.feature
  72. +79 −0 features/working_with_legacy_code/message_chains.feature
  73. +2 −1 rspec-mocks.gemspec
View
@@ -27,7 +27,6 @@ end
platforms :rbx do
gem 'rubysl'
- gem 'rubysl-test-unit'
end
eval File.read('Gemfile-custom') if File.exist?('Gemfile-custom')
View
@@ -1,33 +1,43 @@
-- Upgrade.md
-- Scope.md
-- Changelog.md
-- method_stubs:
- - simple_return_value.feature
- - stub_implementation.feature
- - stub_chain.feature
- - stub_with_arguments.feature
- - any_instance.feature
- - as_null_object.feature
- - to_ary.feature
-- message_expectations:
- - expect_message.feature
- - any_instance.feature
- - block_local_expectations.feature.pending
- - warn_when_expectation_is_set_on_nil.feature
-- argument_matchers:
- - explicit.feature
- - general_matchers.feature
- - type_matchers.feature
-- mutating_constants:
- - stub_defined_constant.feature
- - stub_undefined_constant.feature
- - hiding_defined_constant.feature
+- basics:
+ - scope.feature
+ - test_doubles.feature
+ - allowing_messages.feature
+ - expecting_messages.feature
+ - partial_test_doubles.feature
+ - null_object_doubles.feature
+ - spies.feature
- verifying_doubles:
- instance_doubles.feature
- class_doubles.feature
- object_doubles.feature
- dynamic_classes.feature
- partial_doubles.feature
+- configuring_responses:
+ - returning_a_value.feature
+ - raising_an_error.feature
+ - throwing.feature
+ - yielding.feature
+ - calling_the_original_implementation.feature
+ - block_implementation.feature
+- setting_constraints:
+ - matching_arguments.feature
+ - receive_counts.feature
+ - message_order.feature
+- mutating_constants:
+ - stub_defined_constant.feature
+ - stub_undefined_constant.feature
+ - hide_defined_constant.feature
+ - hide_undefined_constant.feature
+- working_with_legacy_code:
+ - any_instance.feature
+ - message_chains.feature
+- old_syntax:
+ - stub.feature
+ - should_receive.feature
+ - any_instance.feature
+ - stub_chain.feature
+ - unstub.feature
- outside_rspec:
- - configuration.feature
+ - minitest.feature
- standalone.feature
+- Changelog
View
@@ -1,75 +1,76 @@
-rspec-mocks helps to control the context in a code example by letting you set
-known return values, fake implementations of methods, and even expectations
-that specific messages are received by an object.
+rspec-mocks helps to control the context in a code example by letting you set known return
+values, fake implementations of methods, and even set expectations that specific messages
+are received by an object.
-You can do these three things on test doubles that rspec-mocks creates for you
-on the fly, or you can do them on objects that are part of your system.
+You can do these three things on test doubles that rspec-mocks creates for you on the fly, or
+you can do them on objects that are part of your system.
## Messages and Methods
-_Message_ and _method_ are metaphors that we use somewhat interchangeably, but
-they are subtly different. In Object Oriented Programming, objects communicate
-by sending _messages_ to one another. When an object receives a message, it
-invokes a _method_ with the same name as the message.
+_Message_ and _method_ are metaphors that we use somewhat interchangeably, but they are
+subtly different. In Object Oriented Programming, objects communicate by sending
+_messages_ to one another. When an object receives a message, it invokes a _method_ with the
+same name as the message.
## Test Doubles
-A test double is an object that stands in for another object in your system
-during a code example. Use the `double` method, passing in an optional identifier, to create one:
+A test double is an object that stands in for another object in your system during a code
+example. Use the `double` method, passing in an optional identifier, to create one:
- book = double("book")
+```ruby
+book = double("book")
+```
-Most of the time you will want some confidence that your doubles resemble an
-existing object in your system. Verifying doubles are provided for this
-purpose. If the existing object is available, they will prevent you from adding
-stubs and expectations for methods that do not exist or that have an invalid
-number of parameters.
+Most of the time you will want some confidence that your doubles resemble an existing
+object in your system. Verifying doubles are provided for this purpose. If the existing object
+is available, they will prevent you from adding stubs and expectations for methods that do
+not exist or that have invalid arguments.
- book = instance_double("Book", :pages => 250)
+```ruby
+book = instance_double("Book", :pages => 250)
+```
-Verifying doubles have some clever tricks to enable you to both test in
-isolation without your dependencies loaded while still being able to validate
-them against real objects.
+[Verifying doubles](./docs/verifying-doubles) have some clever tricks to enable you to both test in isolation without your
+dependencies loaded while still being able to validate them against real objects.
## Method Stubs
A method stub is an instruction to an object (real or test double) to return a
known value in response to a message:
- allow(die).to receive(:roll) { 3 }
+```ruby
+allow(die).to receive(:roll) { 3 }
+```
-This tells the `die` object to return the value `3` when it receives the `roll`
-message.
+This tells the `die` object to return the value `3` when it receives the `roll` message.
## Message Expectations
-A message expectation is an expectation that an object should receive a
-specific message during the course of a code example:
+A message expectation is an expectation that an object should receive a specific message
+during the course of a code example:
- describe Account do
- context "when closed" do
- it "logs an 'account closed' message" do
- logger = double()
- account = Account.new
- account.logger = logger
+```ruby
+describe Account do
+ context "when closed" do
+ it "logs an 'account closed' message" do
+ logger = double()
+ account = Account.new
+ account.logger = logger
- expect(logger).to receive(:account_closed).with(account)
+ expect(logger).to receive(:account_closed).with(account)
- account.close
- end
- end
+ account.close
end
+ end
+end
+```
-This example specifies that the `account` object sends the `logger` the
-`account_closed` message (with itself as an argument) when it receives the
-`close` message.
+This example specifies that the `account` object sends the `logger` the `account_closed`
+message (with itself as an argument) when it receives the `close` message.
## Issues
-The documentation for rspec-mocks is a work in progress. We'll be adding
-Cucumber features over time, and clarifying existing ones. If you have
-specific features you'd like to see added, find the existing documentation
-incomplete or confusing, or, better yet, wish to write a missing Cucumber
-feature yourself, please [submit an
-issue](http://github.com/rspec/rspec-mocks/issues) or a [pull
-request](http://github.com/rspec/rspec-mocks).
+The documentation for rspec-mocks is a work in progress. We'll be adding Cucumber
+features over time, and clarifying existing ones. If you have specific features you'd like to see
+added, find the existing documentation incomplete or confusing, or, better yet, wish to write
+a missing Cucumber feature yourself, please [submit an issue](http://github.com/rspec/rspec-mocks/issues) or a [pull request](http://github.com/rspec/rspec-mocks).
View
@@ -1,17 +0,0 @@
-Doubles, stubs, and message expectations are all cleaned out after each
-example. This ensures that each example can be run in isolation, and in any
-order.
-
-### `before(:example)`
-
-It is perfectly fine to set up doubles, stubs, and message expectations in
-a `before(:example)` hook, as that hook is executed in the scope of the example:
-
- before(:example) do
- @account = double('account')
- end
-
-### Do not create doubles, stubs, or message expectations in `before(:context)`
-
-If you do, they'll get cleaned out after the first example, and you will be
-very confused as to what's going on in the second example.
@@ -1,27 +0,0 @@
-### Introduction
-
-Argument matchers can be used:
-
-* In stubs to constrain the scope of the stubbed method
-
- allow(obj).to receive(:foo).with(:bar) do |arg|
- #do something for :bar
- end
- allow(obj).to receive(:foo).with(:baz) do |arg|
- #do something for :baz
- end
-
-* In expectations to validate the arguments that should be received in a method call
-
- #create a double
- obj = double()
-
- #expect a message with given args
- expect(obj).to receive(:message).with('an argument')
-
-If more control is needed, one can use a block
-
- expect(obj).to receive(:message) do |arg1, arg2|
- # set expectations about the args in this block
- # and optionally set a return value
- end
@@ -1,31 +0,0 @@
-Feature: explicit arguments
-
- Allows you to explicitly specify the argument values
-
- Scenario: explicit arguments
- Given a file named "stub_explicit_args_spec.rb" with:
- """ruby
- describe "stubbed explicit arguments" do
- it "works on stubs" do
- object = Object.new
- allow(object).to receive(:foo).with(:this) do |arg|
- "got this"
- end
- allow(object).to receive(:foo).with(:that) do |arg|
- "got that"
- end
-
- expect(object.foo(:this)).to eq("got this")
- expect(object.foo(:that)).to eq("got that")
- end
-
- it "works on doubles and expectations" do
- object = double('foo')
- expect(object).to receive(:bar).with(:foo)
-
- object.bar(:foo)
- end
- end
- """
- When I run `rspec stub_explicit_args_spec.rb`
- Then the output should contain "2 examples, 0 failures"
@@ -1,85 +0,0 @@
-Feature: General matchers
-
- The `anything`, `any_args`, and `no_args` matchers can be used to require the method
- to have arguments (or not) without constraining the details of the argument, such as its
- type, pattern or value. The `anything` matcher only reflects a single argument, while
- the `any_args` matcher matches any arity.
-
- Scenario: anything argument matcher
- Given a file named "stub_anything_args_spec.rb" with:
- """ruby
- describe "stubbed anything() args spec" do
- it "works" do
- object = Object.new
- allow(object).to receive(:foo).with(anything) do
- "anything"
- end
-
- expect(object.foo(1)).to eq("anything")
- expect(object.foo(:that)).to eq("anything")
- end
- end
- """
- When I run `rspec stub_anything_args_spec.rb`
- Then the output should contain "1 example, 0 failures"
-
- Scenario: any_args argument matcher
- Given a file named "stub_any_args_spec.rb" with:
- """ruby
- describe "stubbed any_args() args spec" do
- it "works" do
- object = Object.new
- allow(object).to receive(:foo).with(any_args) do
- "anything"
- end
-
- expect(object.foo(1)).to eq("anything")
- expect(object.foo(:that)).to eq("anything")
- expect(object.foo).to eq("anything")
- end
- end
- """
- When I run `rspec stub_any_args_spec.rb`
- Then the output should contain "1 example, 0 failures"
-
- Scenario: no_args argument matcher
- Given a file named "stub_no_args_spec.rb" with:
- """ruby
- describe "stubbed no_args() args spec" do
- it "works for no args" do
- object = Object.new
- allow(object).to receive(:foo).with(no_args) do
- "nothing"
- end
- allow(object).to receive(:foo).with(anything) do
- "something"
- end
-
- expect(object.foo(:that)).to eq("something")
- expect(object.foo).to eq("nothing")
- end
- end
- """
- When I run `rspec stub_no_args_spec.rb`
- Then the output should contain "1 example, 0 failures"
-
- Scenario: no_args argument matcher for expectations
- Given a file named "stub_no_args_expectations_spec.rb" with:
- """ruby
- describe "stubbed no_args() args spec for expectations" do
- it "works for no args" do
- object = Object.new
- expect(object).to receive(:foo).with(no_args)
-
- object.foo
- end
- it "fails for args" do
- object = Object.new
- expect(object).to receive(:foo).with(no_args)
-
- object.foo(:bar)
- end
- end
- """
- When I run `rspec stub_no_args_expectations_spec.rb`
- Then the output should contain "2 examples, 1 failure"
@@ -1,26 +0,0 @@
-Feature: stub with argument constraints
-
- You can further specify the behavior by constraining the type,
- format and/or number of arguments with the `#with()` method
- chained off of `#stub()`
-
- Scenario: an_instance_of argument matcher
- Given a file named "stub_an_instance_of_args_spec.rb" with:
- """ruby
- describe "stubbed an_instance_of() args spec" do
- it "works" do
- object = Object.new
- allow(object).to receive(:foo).with(an_instance_of(Symbol)) do
- "symbol"
- end
- allow(object).to receive(:foo).with(an_instance_of(String)) do
- "string"
- end
-
- expect(object.foo("bar")).to eq("string")
- expect(object.foo(:that)).to eq("symbol")
- end
- end
- """
- When I run `rspec stub_an_instance_of_args_spec.rb`
- Then the output should contain "1 example, 0 failures"
Oops, something went wrong.

0 comments on commit 8338a78

Please sign in to comment.