class Contractinator::ContractHelpers::ContractAdapter
Public Class Methods
new(object, context)
click to toggle source
# File lib/contractinator/contract_helpers.rb, line 112 def initialize(object, context) @object = object @context = context end
Public Instance Methods
must(matcher)
click to toggle source
# File lib/contractinator/contract_helpers.rb, line 117 def must(matcher) @matcher = matcher if defined?(RSpec::Rails::Matchers::RoutingMatchers::RouteToMatcher) if matcher.is_a?(RSpec::Rails::Matchers::RoutingMatchers::RouteToMatcher) contract_route_to_matcher else contract_receive_matcher end else contract_receive_matcher end end
Private Instance Methods
contract_receive_matcher()
click to toggle source
# File lib/contractinator/contract_helpers.rb, line 139 def contract_receive_matcher @message = @matcher.instance_variable_get('@message') @arguments = customization(@matcher, :with) @return_value = customization(@matcher, :and_return) create_contract create_expectation end
contract_route_to_matcher()
click to toggle source
# File lib/contractinator/contract_helpers.rb, line 133 def contract_route_to_matcher @expected = @matcher.instance_variable_get('@expected').with_indifferent_access create_route_contract create_route_expectation end
create_contract()
click to toggle source
# File lib/contractinator/contract_helpers.rb, line 165 def create_contract args = @arguments dbl = @object msg = @message value = @return_value Contractinator::Contract.require(contract_message_signature(dbl, msg, args, value)) end
create_expectation()
click to toggle source
# File lib/contractinator/contract_helpers.rb, line 174 def create_expectation @context.expect(@object).to @matcher.at_least(:once) end
create_route_contract()
click to toggle source
# File lib/contractinator/contract_helpers.rb, line 148 def create_route_contract method = @object.keys.first controller = @expected[:controller] action = @expected[:action] params = @expected.except(:controller, :action) if params.keys.any? Contractinator::Contract.require("#{method} #{controller}##{action} #{params}") else Contractinator::Contract.require("#{method} #{controller}##{action}") end end
create_route_expectation()
click to toggle source
# File lib/contractinator/contract_helpers.rb, line 161 def create_route_expectation @context.expect(@object).to @context.route_to(@expected) end