Module: Test::Spec::Rails::ShouldNotExpectations
- Defined in:
- lib/test/spec/rails/expectations.rb
Instance Method Summary collapse
-
#differ(*expected) ⇒ Object
(also: #change)
Tests that the evaluation of the expression shouldn’t change.
-
#dom_equal(expected) ⇒ Object
Test that two HTML strings are not equivalent.
-
#equal_list(expected) ⇒ Object
Tests if the array of records is not the same, order may vary.
-
#equal_set(expected) ⇒ Object
Tests if the array of records is not the same, order may vary.
-
#validate ⇒ Object
Test that an object is not valid.
Instance Method Details
#differ(*expected) ⇒ Object Also known as: change
Tests that the evaluation of the expression shouldn’t change
lambda { Norm.new }.should.not.differ('Norm.count')
lambda { Norm.new }.should.not.differ('Norm.count', 'Option.count')
norm = lambda { Norm.new }.should.not.differ('Norm.count')
norm.token.should.match /(\d\w){4}/
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/test/spec/rails/expectations.rb', line 143 def differ(*expected) block_binding = @object.send(:binding) before = expected.map do |expression| eval(expression, block_binding) end block_result = @object.call expected.each_with_index do |expression, index| difference = eval(expression, block_binding) - before[index] error = "#{expression.inspect} changed by #{difference}, expected no change" test_case.assert_equal(0, difference, error) end block_result end |
#dom_equal(expected) ⇒ Object
Test that two HTML strings are not equivalent
163 164 165 |
# File 'lib/test/spec/rails/expectations.rb', line 163 def dom_equal(expected) test_case.assert_dom_not_equal expected, @object end |
#equal_list(expected) ⇒ Object
Tests if the array of records is not the same, order may vary
178 179 180 181 182 183 184 185 |
# File 'lib/test/spec/rails/expectations.rb', line 178 def equal_list(expected) = "#{Helpers.inspect_records(@object)} has the same records as #{Helpers.inspect_records(expected)}" left = @object.map(&:id) right = expected.map(&:id) test_case.assert(left != right, ) end |
#equal_set(expected) ⇒ Object
Tests if the array of records is not the same, order may vary
168 169 170 171 172 173 174 175 |
# File 'lib/test/spec/rails/expectations.rb', line 168 def equal_set(expected) = "#{Helpers.inspect_records(@object)} has the same records as #{Helpers.inspect_records(expected)}" left = @object.map(&:id).sort right = expected.map(&:id).sort test_case.assert(left != right, ) end |
#validate ⇒ Object
Test that an object is not valid
132 133 134 |
# File 'lib/test/spec/rails/expectations.rb', line 132 def validate test_case.assert !@object.valid? end |