-
-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 8338a78
Showing
73 changed files
with
2,139 additions
and
1,816 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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). |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.