Skip to content

Commit

Permalink
match_value now matches numbers preceded with a positive and negative…
Browse files Browse the repository at this point in the history
… sign eg +1.5 and -1
  • Loading branch information
Michael MacDonald authored and ianwhite committed Oct 26, 2009
1 parent 509de7d commit 09521f5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
10 changes: 5 additions & 5 deletions README.rdoc
Expand Up @@ -107,11 +107,11 @@ You can refer to other models in the fields
And a person: "ethel" exists
And a fatherhood exists with parent: user "fred", child: user "ethel"

"Given <b>n</b> models exist", e.g.
"Given <b>n models</b> exist", e.g.

Given 10 users exist

"Given <b>n</b> <b>models</b> exist with <b>fields</b>", examples:
"Given <b>n models</b> exist with <b>fields</b>", examples:

Given 10 users exist with activated: false

Expand All @@ -133,11 +133,11 @@ You can use other models, booleans, numerics, and strings as fields
Then a user should exist with activated: false
Then a user should exist with activated: true, email: "fred@gmail.com"

"Then <b>n</b> <b>models</b> should exist", e.g.
"Then <b>n models</b> should exist", e.g.

Then 10 events should exist

"Then <b>n</b> <b>models</b> should exist with <b>fields</b>", e.g.
"Then <b>n models</b> should exist with <b>fields</b>", e.g.

Then 2 people should exist with father: person "fred"

Expand All @@ -159,7 +159,7 @@ Many-to-one assocs: "Then <b>a model</b> should be [in|one of] <b>other model</b
Then the user should have a status # => user.status?.should == true
Then the car: "batmobile" should be fast # => car.fast?.should == true

"Then <b>a model</b> should [be|have] [a|an] <b>predicate</b>", e.g.
"Then <b>a model</b> should not [be|have] [a|an] <b>predicate</b>", e.g.

Then person: "fred" should not be childless # => fred.childless?.should == false

Expand Down
8 changes: 6 additions & 2 deletions features/app/app.rb
Expand Up @@ -28,6 +28,7 @@

create_table :users, :force => true do |t|
t.string :name, :status, :email
t.decimal :attitude_score, :precision => 4, :scale => 2
end
end
end
Expand All @@ -52,19 +53,22 @@ class Tine < ActiveRecord::Base
belongs_to :fork
end

# Machinist bluepriint for this
# Machinist blueprint for this
class Spoon < ActiveRecord::Base
validates_presence_of :name
end

# we don;t want abstract classes getting in there
# we don't want abstract classes getting in there
class AbstractUser < ActiveRecord::Base
self.abstract_class = true
end

# No factory or blueprint for this
class User < AbstractUser
validates_presence_of :name
def positive_person?
!attitude_score.nil? && attitude_score > 0
end
end

# controllers
Expand Down
8 changes: 7 additions & 1 deletion features/pickle/create_from_active_record.feature
Expand Up @@ -17,4 +17,10 @@ Feature: I can easily create models from my blueprints
Given I exist with status: "pwned", name: "fred"
Then I should have a status
And the user: "me" should have a status


Scenario: I create positive and negative users
Given a user exists with name: "Fred", attitude_score: +5.42
And another user exists with name: "Ethel", attitude_score: -1.46
Then 2 users should exist
And the 1st user should be a positive person
And the 2nd user should not be a positive person
2 changes: 1 addition & 1 deletion lib/pickle/parser/matchers.rb
Expand Up @@ -22,7 +22,7 @@ def match_label
end

def match_value
"(?:\"#{match_quoted}\"|true|false|\\d+(?:\\.\\d+)?)"
"(?:\"#{match_quoted}\"|true|false|[+-]?\\d+(?:\\.\\d+)?)"
end

def match_field
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/pickle_parser_matchers_spec.rb
Expand Up @@ -41,8 +41,8 @@ def self.atom_should_not_match(atom, strings)
atom_should_match :match_label, [': "gday"', ': "gday mate"']
atom_should_not_match :match_label, [': "gday""', ': gday']

atom_should_match :match_field, ['foo: "this is the life"', 'bar_man: "and so is this"', 'boolean: false', 'boolean: true', 'numeric: 10', 'numeric: 12.5']
atom_should_not_match :match_field, ['foo bar: "this aint workin"']
atom_should_match :match_field, ['foo: "this is the life"', 'bar_man: "and so is this"', 'boolean: false', 'boolean: true', 'numeric: 10', 'numeric: 12.5', 'numeric: +10', 'numeric: +12.5', 'numeric: -10', 'numeric: -12.5']
atom_should_not_match :match_field, ['foo bar: "this aint workin"', 'not_numeric: --10', 'not_numeric: -ten']

atom_should_match :match_fields, ['foo: "bar"', 'foo: "bar", baz: "bah"']
atom_should_not_match :match_fields, ['foo bar: "baz"', 'email: "a", password: "b", and password_confirmation: "c"']
Expand Down

0 comments on commit 09521f5

Please sign in to comment.