Class: Warp::ControllerMatchers::AssignWithANewMatcher

Inherits:
AssignMatcher show all
Defined in:
lib/warp/controller_matchers/assign_matcher.rb

Instance Attribute Summary collapse

Attributes inherited from AssignMatcher

#assign_key, #controller

Instance Method Summary collapse

Methods inherited from AssignMatcher

#matches?

Constructor Details

#initialize(controller, assign_key, assign_with_a_new) ⇒ AssignWithANewMatcher

Returns a new instance of AssignWithANewMatcher.



144
145
146
147
# File 'lib/warp/controller_matchers/assign_matcher.rb', line 144

def initialize(controller, assign_key, assign_with_a_new)
  super(controller, assign_key)
  @assign_with_a_new = assign_with_a_new
end

Instance Attribute Details

#assign_with_a_newObject (readonly)

Returns the value of attribute assign_with_a_new.



142
143
144
# File 'lib/warp/controller_matchers/assign_matcher.rb', line 142

def assign_with_a_new
  @assign_with_a_new
end

Instance Method Details

#descriptionObject



149
150
151
# File 'lib/warp/controller_matchers/assign_matcher.rb', line 149

def description
  "assign @#{assign_key} with a new instance of #{assign_with_a_new.name}"
end

#failure_messageObject



153
154
155
156
157
158
159
# File 'lib/warp/controller_matchers/assign_matcher.rb', line 153

def failure_message
  if assign_value.nil?
    "expected @#{assign_key} to be assigned with a new instance of #{assign_with_a_new.name} but was not assigned"
  else
    "expected @#{assign_key} to be assigned with a new instance of #{assign_with_a_new.name} but was assigned with a #{assign_value.try(:persisted?) ? "persisted" : "new"} instance of #{assign_value.class.name}"
  end
end

#failure_message_when_negatedObject



161
162
163
# File 'lib/warp/controller_matchers/assign_matcher.rb', line 161

def failure_message_when_negated
  "expected @#{assign_key} to not be assigned with a new instance of #{assign_with_a_new.name}"
end