Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: bitcababy/pickle
base: e94be0ded6
...
head fork: bitcababy/pickle
compare: 526128c9ab
Checking mergeability… Don't worry, you can still create the pull request.
  • 11 commits
  • 16 files changed
  • 0 commit comments
  • 1 contributor
View
1  .gitignore
@@ -7,6 +7,7 @@
Gemfile.lock
cucumber_test_app
pickle-email*
+coverage*
# built docs
.yardoc
View
3  README.rdoc
@@ -93,12 +93,11 @@ you've written, you can just do stuff like
Then a user should exist with name: "Fred"
And that user should be activated # this uses rspec predicate matchers
-==== Machinist: require your blueprints and reset Shams
+==== Machinist: require your blueprints
In your <tt>features/support/env.rb</tt> add the following lines at the bottom
require "#{Rails.root}/spec/blueprints" # or wherever they live
- Before { Sham.reset } # reset Shams in between scenarios
==== FactoryGirl: make sure factories are loaded
View
3  Rakefile
@@ -17,4 +17,5 @@ Dir["Rakefile.d/*.rake"].sort.each {|t| load_tasks t}
task :default => :spec
-task :ci => ['rcov:verify', 'cucumber']
+# This no longer works
+# task :ci => ['rcov:verify', 'cucumber']
View
6 features/app/blueprints.rb
@@ -1,11 +1,7 @@
# Blueprints
require 'machinist/active_record'
-Sham.spoon_name { |i| "Spoon #{i}" }
-
Spoon.blueprint do
- name { Sham.spoon_name }
+ name { "Spoon #{sn}" }
end
-# reset shams between scenarios
-Before { Sham.reset }
View
2  features/email/email.feature
@@ -3,7 +3,7 @@ Feature: I can test emails are sent
As a feature writer
I want to easily see what emails have been delivered
- Scenario: Deliver an email, and test it's properties
+ Scenario: Deliver an email, and test its properties
Given an email "Gday" with body: "Gday Mate" is delivered to fred@gmail.com
Then 1 email should be delivered
And the email should not be delivered to "frood@fmail.com"
View
1  features/support/pickle.rb
@@ -6,7 +6,6 @@
#
# require 'machinist/active_record' # or your chosen adaptor
# require File.dirname(__FILE__) + '/../../spec/blueprints' # or wherever your blueprints are
-# Before { Sham.reset } # to reset Sham's seed between scenarios so each run has same random sequences
#
# For FactoryGirl add: features/support/factory_girl.rb
#
View
4 lib/pickle/adapter.rb
@@ -92,10 +92,10 @@ def initialize(klass, blueprint)
@klass, @blueprint = klass, blueprint
@name = @klass.name.underscore.gsub('/','_')
@name = "#{@blueprint}_#{@name}" unless @blueprint == :master
- end
+ end
def create(attrs = {})
- if @klass.respond_to?('make!')
+ if @klass.respond_to?('make!')
@klass.send(:make!, @blueprint, attrs)
else
@klass.send(:make, @blueprint, attrs)
View
4 lib/pickle/adapters/active_record.rb
@@ -1,7 +1,7 @@
begin
- require 'activerecord'
-rescue LoadError
require 'active_record'
+rescue LoadError
+ require 'activerecord'
end
class ActiveRecord::Base
View
7 lib/pickle/parser.rb
@@ -26,7 +26,12 @@ def parse_fields(fields)
# given a string like 'foo: expr' returns {key => value}
def parse_field(field)
if field =~ /^#{capture_key_and_value_in_field}$/
- { $1 => eval($2) }
+ k,v = $1,$2
+ if v =~ /^#{match_date}$/
+ {k => Date.parse(v)}
+ else
+ { k => eval(v) }
+ end
else
raise ArgumentError, "The field argument is not in the correct format.\n\n'#{field}' did not match: #{match_field}"
end
View
56 lib/pickle/parser/matchers.rb
@@ -1,6 +1,12 @@
module Pickle
class Parser
module Matchers
+
+ @@year_pat = '(?:(?:19|20)\d\d)'
+ @@day_pat = '(?:(?:3[0-1])|(?:2\d)|(?:1\d)|(?:0?[1-9]))'
+ @@abbr_month_names = Date::ABBR_MONTHNAMES.slice(1..12).join('|')
+ @@month_pat = '(?:(?:1[012])|(?:0?[1-9]))'
+
def match_ordinal
'(?:\d+(?:st|nd|rd|th))'
end
@@ -13,16 +19,50 @@ def match_prefix
'(?:(?:a|an|another|the|that) )'
end
- def match_quoted
- '(?:\\\\"|[^\\"]|\\.)*'
- end
-
+ def match_year
+ @@year_pat
+ end
+
+ def match_month_num
+ @@month_pat
+ end
+
+ def match_day
+ @@day_pat
+ end
+
+ def _match_date1
+ "(?:#{match_year}[-\/]#{match_month_num}[-\/]#{match_day})"
+ end
+
+ def _match_date2
+ "(?:#{match_day}[-\/]#{match_month_num}[-\/]#{match_year})"
+ end
+
+ def _match_date3
+ "(?:(?:#{@@abbr_month_names})\s+#{match_day},?\s*#{match_year})"
+ end
+
+
+ def match_date
+ "(?:#{_match_date1}|#{_match_date2}|#{_match_date3})"
+ end
+
+ def match_quoted
+ '(?:\\\\"|[^\\"]|\\.)*'
+ end
+
def match_label
"(?::? \"#{match_quoted}\")"
end
+ def match_number
+ '\d+'
+ end
+
def match_value
- "(?:\"#{match_quoted}\"|nil|true|false|[+-]?[0-9_]+(?:\\.\\d+)?)"
+ "(?:\"#{match_quoted}\"|#{match_date}|nil|true|false|[+-]?[0-9_]+(?:\\.\\d+)?)"
+ # "(?:\"#{match_quoted}\"|nil|true|false|[+-]?[0-9]+(?:\\.\\d+)?)"
end
def match_field
@@ -79,8 +119,12 @@ def capture_name_in_label
"(?::? \"(#{match_quoted})\")"
end
+ def match_key_and_value_in_field
+ "(?:\\w+: #{match_value})"
+ end
+
def capture_key_and_value_in_field
- "(?:(\\w+): #{capture_value})"
+ "(?:(\\w+): (#{match_value}))"
end
end
end
View
2  pickle.gemspec
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "factory_girl"
s.add_development_dependency "fabrication"
s.add_development_dependency "machinist"
- s.add_development_dependency "rcov"
+ s.add_development_dependency "simplecov"
s.add_development_dependency "database_cleaner"
s.add_development_dependency "capybara"
s.add_development_dependency "sqlite3-ruby"
View
1  rails_generators/pickle/templates/pickle.rb
@@ -6,7 +6,6 @@
#
# require 'machinist/active_record' # or your chosen adaptor
# require File.dirname(__FILE__) + '/../../spec/blueprints' # or wherever your blueprints are
-# Before { Sham.reset } # to reset Sham's seed between scenarios so each run has same random sequences
#
# For FactoryGirl add: features/support/factory_girl.rb
#
View
8 spec/pickle/adapter_spec.rb
@@ -190,8 +190,8 @@
@factory.name.should == 'one'
end
- it "#create(attrs) should call Class.make(:master, attrs)" do
- @klass1.should_receive(:make).with(:master, {:key => "val"})
+ it "#create(attrs) should call Class.make!(:master, attrs)" do
+ @klass1.should_receive(:make!).with(:master, {:key => "val"})
@factory.create(:key => "val")
end
end
@@ -205,8 +205,8 @@
@factory.name.should == 'special_three'
end
- it "#create(attrs) should call Class.make(:special, attrs)" do
- @klass3.should_receive(:make).with(:special, {:key => "val"})
+ it "#create(attrs) should call Class.make!(:special, attrs)" do
+ @klass3.should_receive(:make!).with(:special, {:key => "val"})
@factory.create(:key => "val")
end
end
View
64 spec/pickle/parser/matchers_spec.rb
@@ -32,32 +32,48 @@ def self.atom_should_not_match(atom, strings)
end
end
- atom_should_match :match_ordinal, ['1st', '2nd', '23rd', '104th']
- atom_should_not_match :match_ordinal, ['1', '2']
+ atom_should_match :match_ordinal, ['1st', '2nd', '23rd', '104th']
+ atom_should_not_match :match_ordinal, ['1', '2']
- atom_should_match :match_index, ['first', 'last', '23rd', '104th']
- atom_should_not_match :match_index, ['1', '2', 'foo']
+ atom_should_match :match_index, ['first', 'last', '23rd', '104th']
+ atom_should_not_match :match_index, ['1', '2', 'foo']
- 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"', 'quoted_baz: "words \"in quotes\""', 'boolean: false', 'boolean: true', 'numeric: 10', 'numeric: 12.5', 'numeric: +10', 'numeric: +12.5', 'numeric: -10', 'numeric: -12.5', 'nil_field: nil']
- 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"']
+ atom_should_match :match_label, [': "gday"', ': "gday mate"']
+ atom_should_not_match :match_label, [': "gday""', ': gday']
- atom_should_match :match_model, ['a user', '1st fast car', 'the 23rd fast_car', 'the user: "fred flinstone"']
- atom_should_not_match :match_model, ['a giraffe', 'a 1st faster car: "jim"', 'an event created']
-
- atom_should_match :match_predicate, ['name', 'status', 'fancy', 'super fancy', 'super_fancy', 'style', 'super style', 'super_style']
- atom_should_not_match :match_predicate, ['nameo', 'increment', 'not a predicate', 'has style']
-
- atom_should_match :match_factory, ['user', 'fast car', 'fast_car', 'car']
- atom_should_not_match :match_factory, ['users', 'faster car', 'event created']
-
- atom_should_match :match_plural_factory, ['users', 'fast cars']
- atom_should_not_match :match_plural_factory, ['usereres', 'fasts cars']
+ atom_should_match :match_field, ['foo: "this is the life"', 'bar_man: "and so is this"', 'quoted_baz: "words \"in quotes\""', 'boolean: false', 'boolean: true', 'numeric: 10', 'numeric: 12.5', 'numeric: +10', 'numeric: +12.5', 'numeric: -10', 'numeric: -12.5', 'nil_field: nil']
+ 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"']
+
+ atom_should_match :match_model, ['a user', '1st fast car', 'the 23rd fast_car', 'the user: "fred flinstone"']
+ atom_should_not_match :match_model, ['a giraffe', 'a 1st faster car: "jim"', 'an event created']
+
+ atom_should_match :match_predicate, ['name', 'status', 'fancy', 'super fancy', 'super_fancy', 'style', 'super style', 'super_style']
+ atom_should_not_match :match_predicate, ['nameo', 'increment', 'not a predicate', 'has style']
+
+ atom_should_match :match_factory, ['user', 'fast car', 'fast_car', 'car']
+ atom_should_not_match :match_factory, ['users', 'faster car', 'event created']
+
+ atom_should_match :match_plural_factory, ['users', 'fast cars']
+ atom_should_not_match :match_plural_factory, ['usereres', 'fasts cars']
+
+ atom_should_match :match_year, ['2012']
+ atom_should_match :match_month_num, ['01']
+ atom_should_not_match :match_month_num, ['22']
+ atom_should_match :match_day, ['1', '31', '15']
+
+ atom_should_match :match_date, ['2012-02-15', 'Feb 15, 2002']
+ atom_should_not_match :match_date, ['32-24-48']
+
+ atom_should_match :match_number, ['32']
+
+ atom_should_match :match_value, ['32']
+ atom_should_match :match_value, ['2012-02-15']
+
+ atom_should_match :match_key_and_value_in_field, ['a: "b"']
+ atom_should_match :capture_key_and_value_in_field, ['a: 2012-02-15']
end
end
@@ -66,5 +82,7 @@ def self.atom_should_not_match(atom, strings)
should_receive(:match_field).and_return('MATCH_FIELD')
capture_field.should == '(MATCH_FIELD)'
end
+
end
+
end
View
14 spec/pickle/parser_spec.rb
@@ -35,7 +35,11 @@
@parser.parse_field('a: "b"').should == {'a' => 'b'}
end
- it "should raise error for invalid field 'a : b'" do
+ it "should return {'a' => Date(2012,2,15)} for 'a: 2012-02-15'" do
+ @parser.parse_field('a: 2012-02-15').should == {"a" => Date.new(2012, 2, 15)}
+ end
+
+ it "should raise error for invalid field 'a : b'" do
lambda { @parser.parse_field('a : b') }.should raise_error(ArgumentError)
end
end
@@ -74,6 +78,14 @@
@parser.parse_fields('float: 10.1').should == {"float" => 10.1}
end
+ it "should return {'a' => Date.new(2012,2,15)} for 'a: 2012-02-15" do
+ @parser.parse_fields('date: 2012-02-15').should == {"date" => Date.new(2012, 2, 15)}
+ end
+
+ it "should return {'a' => Date.new(2012,2,15)} for 'a: Feb 15, 2012" do
+ @parser.parse_fields('date: Feb 15, 2012').should == {"date" => Date.new(2012, 2, 15)}
+ end
+
it '(\'foo: "bar", bar_man: "wonga wonga", baz_woman: "one \"two\" three", gump: 123\') should == {"foo" => "bar", "bar_man" => "wonga wonga", "gump" => 123}' do
@parser.parse_fields('foo: "bar", bar_man: "wonga wonga", baz_woman: "one \"two\" three", gump: 123').should == {"foo" => "bar", "bar_man" => "wonga wonga", "baz_woman" => "one \"two\" three", "gump" => 123}
end
View
2  spec/spec_helper.rb
@@ -2,6 +2,8 @@
require 'rspec'
require 'active_support'
require 'active_record'
+require 'simplecov'
+SimpleCov.start
$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'pickle'

No commit comments for this range

Something went wrong with that request. Please try again.