Class: Riot::AssignsMacro
- Inherits:
-
AssertionMacro
- Object
- AssertionMacro
- Riot::AssignsMacro
- Defined in:
- lib/riot/assertion_macros/assigns.rb
Overview
In the positive case, asserts that an instance variable is defined for the result of the assertion. Value of instance variable is expected to not be nil.
setup { User.new(:email => "[email protected]") }
asserts_topic.assigns(:email)
If a value is provided in addition to the variable name, the actual value of the instance variable must equal the expected value.
setup { User.new(:email => "[email protected]") }
asserts_topic.assigns(:email, "[email protected]")
In the negative case, asserts that an instance variables *is not* defined or has a nil value. If a value is provided in addition to the name, then ensure that the actual value does not equal the expected value.
setup { User.new(:email => "[email protected]") }
denies("topic") { topic }.assigns(:first_name)
denies("topic") { topic }.assigns(:email, "[email protected]")
Instance Attribute Summary
Attributes inherited from AssertionMacro
Instance Method Summary collapse
-
#devaluate(actual, *expectings) ⇒ Array
Supports negative/converse assertion testing.
-
#evaluate(actual, *expectings) ⇒ Array
Supports positive assertion testing.
Methods inherited from AssertionMacro
#error, #expected_message, expects_exception!, #expects_exception?, #fail, #new_message, #pass, register, #should_have_message
Instance Method Details
#devaluate(actual, *expectings) ⇒ Array
Supports negative/converse assertion testing. This is also where magic happens.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/riot/assertion_macros/assigns.rb', line 45 def devaluate(actual, *expectings) prepare(actual, *expectings) do |variable, expected_value, actual_value| if actual_value.nil? || (expected_value && expected_value != actual_value) if expected_value && actual_value pass .assigns(variable).with(expected_value) else pass .assigns(variable) end else = (variable).to_not_be fail(expected_value.nil? ? .assigned_a_value : .assigned_with(expected_value)) end end end |
#evaluate(actual, *expectings) ⇒ Array
Supports positive assertion testing. This is where magic happens.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/riot/assertion_macros/assigns.rb', line 26 def evaluate(actual, *expectings) prepare(actual, *expectings) do |variable, expected_value, actual_value| if actual_value.nil? fail (variable).to_be_assigned_a_value elsif !expected_value.nil? && expected_value != actual_value fail (variable).to_be_assigned_with(expected_value).not(actual_value) else if expected_value && actual_value pass .assigns(variable).with(expected_value) else pass .assigns(variable) end end end end |