Skip to content

Commit

Permalink
refactor: rename ExpectationChain to PositiveExpectationChain
Browse files Browse the repository at this point in the history
Also extract base ExpectationChain.
  • Loading branch information
dchelimsky committed Jun 15, 2012
1 parent f04d527 commit 980b98f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 46 deletions.
1 change: 0 additions & 1 deletion lib/rspec/mocks/any_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require 'rspec/mocks/any_instance/stub_chain'
require 'rspec/mocks/any_instance/stub_chain_chain'
require 'rspec/mocks/any_instance/expectation_chain'
require 'rspec/mocks/any_instance/negative_expectation_chain'
require 'rspec/mocks/any_instance/message_chains'
require 'rspec/mocks/any_instance/recorder'

Expand Down
42 changes: 32 additions & 10 deletions lib/rspec/mocks/any_instance/expectation_chain.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
module RSpec
module Mocks
module AnyInstance

# @private
# @api private
class ExpectationChain < Chain
def expectation_fulfilled?
@expectation_fulfilled || constrained_to_any_of?(:never, :any_number_of_times)
end

# @private
def initialize(*args, &block)
record(:should_receive, *args, &block)
record(*args, &block)
@expectation_fulfilled = false
end

# @private
def expectation_fulfilled?
@expectation_fulfilled || constrained_to_any_of?(:never, :any_number_of_times)
private
def verify_invocation_order(rspec_method_name, *args, &block)
end
end

# @api private
class PositiveExpectationChain < ExpectationChain
def initialize(*args, &block)
super(:should_receive, *args, &block)
end

private

def verify_invocation_order(rspec_method_name, *args, &block)
def invocation_order
@invocation_order ||= {
:should_receive => [nil],
:with => [:should_receive],
:and_return => [:with, :should_receive],
:and_raise => [:with, :should_receive]
}
end
end

# @api private
class NegativeExpectationChain < ExpectationChain
def initialize(*args, &block)
super(:should_not_receive, *args, &block)
end

private

def invocation_order
@invocation_order ||= {
:should_receive => [nil],
:should_not_receive => [nil],
:with => [:should_receive],
:and_return => [:with, :should_receive],
:and_raise => [:with, :should_receive]
Expand All @@ -32,4 +54,4 @@ def invocation_order
end
end
end
end
end
33 changes: 0 additions & 33 deletions lib/rspec/mocks/any_instance/negative_expectation_chain.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/rspec/mocks/any_instance/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def stub_chain(*method_names_and_optional_return_values, &block)
def should_receive(method_name, &block)
@expectation_set = true
observe!(method_name)
message_chains.add(method_name, ExpectationChain.new(method_name, &block))
message_chains.add(method_name, PositiveExpectationChain.new(method_name, &block))
end

def should_not_receive(method_name, &block)
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/mocks/any_instance/message_chains_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe RSpec::Mocks::AnyInstance::MessageChains do
let(:chains) { RSpec::Mocks::AnyInstance::MessageChains.new }
let(:stub_chain) { RSpec::Mocks::AnyInstance::StubChain.new }
let(:expectation_chain) { RSpec::Mocks::AnyInstance::ExpectationChain.new }
let(:expectation_chain) { RSpec::Mocks::AnyInstance::PositiveExpectationChain.new }

it "knows if a method does not have an expectation set on it" do
chains.add(:method_name, stub_chain)
Expand Down

0 comments on commit 980b98f

Please sign in to comment.