features/step_definitions/pickle_steps.rb in pickle-0.5.0 vs features/step_definitions/pickle_steps.rb in pickle-0.5.1

- old
+ new

@@ -5,11 +5,11 @@ create_model(name, fields) end # create n models Given(/^(\d+) #{capture_plural_factory} exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields| - count.to_i.times { create_model(plural_factory.singularize, fields) } + create_models(count, plural_factory.singularize, fields) end # create models from a table Given(/^the following #{capture_plural_factory} exists?:?$/) do |plural_factory, table| create_models_from_table(plural_factory, table) @@ -24,14 +24,19 @@ Then(/^#{capture_model} should not exist(?: with #{capture_fields})?$/) do |name, fields| expect(find_model(name, fields)).to be_nil end # find models with a table -Then(/^the following #{capture_plural_factory} should exists?:?$/) do |plural_factory, table| +Then(/^the following #{capture_plural_factory} should exist:?$/) do |plural_factory, table| expect(find_models_from_table(plural_factory, table)).not_to be_any(&:nil?) end +# not find models with a table +Then(/^the following #{capture_plural_factory} should not exists?:?$/) do |plural_factory, table| + find_models_from_table(plural_factory, table).should be_all(&:nil?) +end + # find exactly n models Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields| expect(find_models(plural_factory.singularize, fields).size).to eq(count.to_i) end @@ -58,11 +63,11 @@ # assert model is not another model's has_one/belongs_to assoc Then(/^#{capture_model} should not be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association| expect(model!(owner).send(association)).not_to eq(model!(target)) end -# assert model.predicate? +# assert model.predicate? Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate| if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}") expect(model!(name)).to send("have_#{predicate.gsub(' ', '_')}") else expect(model!(name)).to send("be_#{predicate.gsub(' ', '_')}") @@ -81,10 +86,10 @@ # expect(model.attribute).to eq(value) # expect(model.attribute).not_to eq(value) Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}$/) do |name, attribute, expectation, expected| actual_value = model(name).send(attribute) expectation = expectation.gsub("should", "to").gsub(" ", "_") - + case expected when 'nil', 'true', 'false' expect(actual_value).send(expectation, eq(eval(expected))) when /^[+-]?[0-9_]+(\.\d+)?$/ expect(actual_value).send(expectation, eq(expected.to_f))