Sha256: 3831726051572f6695455616013ed0677d6ad350d1fd7de5cd8a59fde3b66b14

Contents?: true

Size: 1.04 KB

Versions: 20

Compression:

Stored size: 1.04 KB

Contents

module RSpecCandy
  module Helpers
    module ShouldReceiveChain

      def should_receive_chain(*parts)
        setup_expectation_chain(parts)
      end

      def should_not_receive_chain(*parts)
        setup_expectation_chain(parts, :negate => true)
      end

      private

      def setup_expectation_chain(parts, options = {})
        obj = self
        for part in parts
          if part == parts.last
            expectation = options[:negate] ? :should_not_receive : :should_receive
            obj = add_expectation_chain_link(obj, expectation, part)
          else
            next_obj = Switcher.new_mock('chain link')
            add_expectation_chain_link(obj, :stub, part).and_return(next_obj)
            obj = next_obj
          end
        end
        obj
      end

      def add_expectation_chain_link(obj, expectation, part)
        if part.is_a?(Array)
          obj.send(expectation, part.first).with(*part[1..-1])
        else
          obj.send(expectation, part)
        end
      end

      Object.send(:include, self)

    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rspec_candy-0.5.1 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.5.0 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.4.1 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.4.0 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.3.1 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.3.0 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.2.10 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.2.9 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.2.8 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.2.7 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.2.6 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.2.5 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.2.4 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.2.3 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.2.2 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.2.1 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.2.0 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.1.2 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.1.1 lib/rspec_candy/helpers/should_receive_chain.rb
rspec_candy-0.1.0 lib/rspec_candy/helpers/should_receive_chain.rb