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
|
Feature: configure any test framework to use rspec-mocks
Test frameworks that want to use rspec-mocks can use
RSpec::Mocks::setup(self) to hook into rspec-mocks. Doing so adds the
following:
To the object passed to setup:
double # creates a test double
mock # creates a test double
stub # creates a test double
To every object in the system:
should_receive
should_not_receive
stub
NOTICE: the stub() method that is added to the object passed to setup is not
the same stub() method that is added to every other object.
Scenario: RSpec::Mocks::setup(object) adds double, mock, and stub methods to the submitted object
Given a file named "foo.rb" with:
"""ruby
require 'rspec/mocks'
class CodeExample
def init
RSpec::Mocks::setup(self)
end
end
example = CodeExample.new
example.init
puts example.respond_to?(:double)
puts example.respond_to?(:mock)
puts example.respond_to?(:stub)
"""
When I run `ruby foo.rb`
Then the output should contain "true"
But the output should not contain "false"
Scenario: RSpec::Mocks::setup(anything) adds methods to Object
Given a file named "foo.rb" with:
"""ruby
require 'rspec/mocks'
RSpec::Mocks::setup(Object.new)
obj = Object.new
puts obj.respond_to?(:should_receive)
puts obj.respond_to?(:should_not_receive)
puts obj.respond_to?(:stub)
"""
When I run `ruby foo.rb`
Then the output should contain "true"
But the output should not contain "false"
|