features/step_definitions/pickle_steps.rb in pickle-0.2.8 vs features/step_definitions/pickle_steps.rb in pickle-0.2.9
- old
+ new
@@ -60,16 +60,24 @@
model!(owner).send(association).should_not == model!(target)
end
# assert model.predicate?
Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
- model!(name).should send("be_#{predicate.gsub(' ', '_')}")
+ if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
+ model!(name).should send("have_#{predicate.gsub(' ', '_')}")
+ else
+ model!(name).should send("be_#{predicate.gsub(' ', '_')}")
+ end
end
# assert not model.predicate?
Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
- model!(name).should_not send("be_#{predicate.gsub(' ', '_')}")
+ if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
+ model!(name).should_not send("have_#{predicate.gsub(' ', '_')}")
+ else
+ model!(name).should_not send("be_#{predicate.gsub(' ', '_')}")
+ end
end
# model.attribute.should eql(value)
# model.attribute.should_not eql(value)
Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}$/) do |name, attribute, expectation, expected|
@@ -77,11 +85,16 @@
expectation = expectation.gsub(' ', '_')
case expected
when 'nil', 'true', 'false'
actual_value.send(expectation, send("be_#{expected}"))
- when /^-?[0-9_]+$/
- actual_value.send(expectation, eql(expected.to_i))
+ when /^[+-]?[0-9_]+(\.\d+)?$/
+ actual_value.send(expectation, eql(expected.to_f))
else
- actual_value.to_s.send(expectation, eql(expected))
+ actual_value.to_s.send(expectation, eql(eval(expected)))
end
+end
+
+# assert size of association
+Then /^#{capture_model} should have (\d+) (\w+)$/ do |name, size, association|
+ model!(name).send(association).size.should == size.to_i
end