Class: Warp::ActionMatchers::CreateMatcher

Inherits:
Matcher show all
Defined in:
lib/warp/action_matchers/create_matcher.rb

Constant Summary collapse

CREATE_METHOD =
:create

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Matcher

#description_of, #failure_message_for_should, #failure_message_for_should_not, #values_match?

Constructor Details

#initialize(model) ⇒ CreateMatcher

Returns a new instance of CreateMatcher.



15
16
17
# File 'lib/warp/action_matchers/create_matcher.rb', line 15

def initialize(model)
  @model = model
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



13
14
15
# File 'lib/warp/action_matchers/create_matcher.rb', line 13

def model
  @model
end

Instance Method Details

#descriptionObject



30
31
32
# File 'lib/warp/action_matchers/create_matcher.rb', line 30

def description
  "create a #{model_name}"
end

#failure_messageObject



34
35
36
# File 'lib/warp/action_matchers/create_matcher.rb', line 34

def failure_message
  "expected a #{model_name} to be created"
end

#failure_message_when_negatedObject



38
39
40
# File 'lib/warp/action_matchers/create_matcher.rb', line 38

def failure_message_when_negated
  "expected no #{model_name} to be created"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
# File 'lib/warp/action_matchers/create_matcher.rb', line 19

def matches?(actual)
  check_callable!(actual)

  instrument = Warp::Instrument.for(model, CREATE_METHOD)

  instrument.reset
  instrument.run { actual.call }

  instrument.calls.size > 0
end