judit-pickle 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +20 -0
  3. data/Gemfile.lock +98 -0
  4. data/History.txt +409 -0
  5. data/License.txt +20 -0
  6. data/README.rdoc +367 -0
  7. data/Rakefile +20 -0
  8. data/Rakefile.d/cucumber.rake +24 -0
  9. data/Rakefile.d/jeweler.rake +23 -0
  10. data/Rakefile.d/rcov.rake +18 -0
  11. data/Rakefile.d/rspec.rake +7 -0
  12. data/Rakefile.d/yard.rake +5 -0
  13. data/Todo.txt +3 -0
  14. data/VERSION +1 -0
  15. data/features/app/app.rb +122 -0
  16. data/features/app/blueprints.rb +11 -0
  17. data/features/app/factories.rb +23 -0
  18. data/features/app/views/notifier/email.erb +1 -0
  19. data/features/app/views/notifier/user_email.erb +6 -0
  20. data/features/email/email.feature +64 -0
  21. data/features/generator/generators.feature +59 -0
  22. data/features/path/models_page.feature +44 -0
  23. data/features/path/named_route_page.feature +10 -0
  24. data/features/pickle/create_from_active_record.feature +76 -0
  25. data/features/pickle/create_from_factory_girl.feature +63 -0
  26. data/features/pickle/create_from_machinist.feature +39 -0
  27. data/features/step_definitions/email_steps.rb +63 -0
  28. data/features/step_definitions/extra_email_steps.rb +7 -0
  29. data/features/step_definitions/fork_steps.rb +4 -0
  30. data/features/step_definitions/generator_steps.rb +46 -0
  31. data/features/step_definitions/path_steps.rb +14 -0
  32. data/features/step_definitions/pickle_steps.rb +100 -0
  33. data/features/step_definitions/raise_error_steps.rb +3 -0
  34. data/features/support/email.rb +21 -0
  35. data/features/support/env.rb +52 -0
  36. data/features/support/paths.rb +47 -0
  37. data/features/support/pickle.rb +26 -0
  38. data/features/support/pickle_app.rb +4 -0
  39. data/init.rb +0 -0
  40. data/lib/generators/pickle_generator.rb +69 -0
  41. data/lib/pickle/adapter.rb +137 -0
  42. data/lib/pickle/adapters/active_record.rb +57 -0
  43. data/lib/pickle/adapters/data_mapper.rb +42 -0
  44. data/lib/pickle/adapters/mongoid.rb +44 -0
  45. data/lib/pickle/config.rb +49 -0
  46. data/lib/pickle/email/parser.rb +18 -0
  47. data/lib/pickle/email/world.rb +13 -0
  48. data/lib/pickle/email.rb +77 -0
  49. data/lib/pickle/parser/matchers.rb +87 -0
  50. data/lib/pickle/parser.rb +65 -0
  51. data/lib/pickle/path/world.rb +5 -0
  52. data/lib/pickle/path.rb +45 -0
  53. data/lib/pickle/session/parser.rb +34 -0
  54. data/lib/pickle/session.rb +205 -0
  55. data/lib/pickle/version.rb +9 -0
  56. data/lib/pickle/world.rb +14 -0
  57. data/lib/pickle.rb +26 -0
  58. data/pickle.gemspec +134 -0
  59. data/rails_generators/pickle/pickle_generator.rb +33 -0
  60. data/rails_generators/pickle/templates/email.rb +21 -0
  61. data/rails_generators/pickle/templates/email_steps.rb +63 -0
  62. data/rails_generators/pickle/templates/paths.rb +47 -0
  63. data/rails_generators/pickle/templates/pickle.rb +28 -0
  64. data/rails_generators/pickle/templates/pickle_steps.rb +100 -0
  65. data/spec/pickle/adapter_spec.rb +186 -0
  66. data/spec/pickle/config_spec.rb +109 -0
  67. data/spec/pickle/email/parser_spec.rb +51 -0
  68. data/spec/pickle/email_spec.rb +166 -0
  69. data/spec/pickle/parser/matchers_spec.rb +70 -0
  70. data/spec/pickle/parser_spec.rb +161 -0
  71. data/spec/pickle/path_spec.rb +101 -0
  72. data/spec/pickle/session_spec.rb +434 -0
  73. data/spec/pickle_spec.rb +24 -0
  74. data/spec/spec_helper.rb +8 -0
  75. metadata +199 -0
@@ -0,0 +1,63 @@
1
+ # this file generated by script/generate pickle email
2
+ #
3
+ # add email mappings in features/support/email.rb
4
+
5
+ ActionMailer::Base.delivery_method = :test
6
+ ActionMailer::Base.perform_deliveries = true
7
+
8
+ Before do
9
+ ActionMailer::Base.deliveries.clear
10
+ end
11
+
12
+ # Clear the deliveries array, useful if your background sends email that you want to ignore
13
+ Given(/^all emails? (?:have|has) been delivered$/) do
14
+ ActionMailer::Base.deliveries.clear
15
+ end
16
+
17
+ Given(/^(\d)+ emails? should be delivered$/) do |count|
18
+ emails.size.should == count.to_i
19
+ end
20
+
21
+ When(/^(?:I|they) follow "([^"]*?)" in #{capture_email}$/) do |link, email_ref|
22
+ visit_in_email(email(email_ref), link)
23
+ end
24
+
25
+ When(/^(?:I|they) click the first link in #{capture_email}$/) do |email_ref|
26
+ click_first_link_in_email(email(email_ref))
27
+ end
28
+
29
+ Then(/^(\d)+ emails? should be delivered to (.*)$/) do |count, to|
30
+ emails("to: \"#{email_for(to)}\"").size.should == count.to_i
31
+ end
32
+
33
+ Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fields|
34
+ emails(fields).size.should == count.to_i
35
+ end
36
+
37
+ Then(/^#{capture_email} should be delivered to (.+)$/) do |email_ref, to|
38
+ email(email_ref, "to: \"#{email_for(to)}\"").should_not be_nil
39
+ end
40
+
41
+ Then(/^#{capture_email} should not be delivered to (.+)$/) do |email_ref, to|
42
+ email(email_ref, "to: \"#{email_for(to)}\"").should be_nil
43
+ end
44
+
45
+ Then(/^#{capture_email} should have #{capture_fields}$/) do |email_ref, fields|
46
+ email(email_ref, fields).should_not be_nil
47
+ end
48
+
49
+ Then(/^#{capture_email} should contain "(.*)"$/) do |email_ref, text|
50
+ email(email_ref).body.should =~ /#{text}/
51
+ end
52
+
53
+ Then(/^#{capture_email} should not contain "(.*)"$/) do |email_ref, text|
54
+ email(email_ref).body.should_not =~ /#{text}/
55
+ end
56
+
57
+ Then(/^#{capture_email} should link to (.+)$/) do |email_ref, page|
58
+ email(email_ref).body.should =~ /#{path_to(page)}/
59
+ end
60
+
61
+ Then(/^show me the emails?$/) do
62
+ save_and_open_emails
63
+ end
@@ -0,0 +1,47 @@
1
+ module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in web_steps.rb
7
+ #
8
+ def path_to(page_name)
9
+ case page_name
10
+
11
+ when /the home\s?page/
12
+ '/'
13
+
14
+ # the following are examples using path_to_pickle
15
+
16
+ when /^#{capture_model}(?:'s)? page$/ # eg. the forum's page
17
+ path_to_pickle $1
18
+
19
+ when /^#{capture_model}(?:'s)? #{capture_model}(?:'s)? page$/ # eg. the forum's post's page
20
+ path_to_pickle $1, $2
21
+
22
+ when /^#{capture_model}(?:'s)? #{capture_model}'s (.+?) page$/ # eg. the forum's post's comments page
23
+ path_to_pickle $1, $2, :extra => $3 # or the forum's post's edit page
24
+
25
+ when /^#{capture_model}(?:'s)? (.+?) page$/ # eg. the forum's posts page
26
+ path_to_pickle $1, :extra => $2 # or the forum's edit page
27
+
28
+ # Add more mappings here.
29
+ # Here is an example that pulls values out of the Regexp:
30
+ #
31
+ # when /^(.*)'s profile page$/i
32
+ # user_profile_path(User.find_by_login($1))
33
+
34
+ else
35
+ begin
36
+ page_name =~ /the (.*) page/
37
+ path_components = $1.split(/\s+/)
38
+ self.send(path_components.push('path').join('_').to_sym)
39
+ rescue Object => e
40
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
41
+ "Now, go and add a mapping in #{__FILE__}"
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ World(NavigationHelpers)
@@ -0,0 +1,28 @@
1
+ # this file generated by script/generate pickle [paths] [email]
2
+ #
3
+ # Make sure that you are loading your factory of choice in your cucumber environment
4
+ #
5
+ # For machinist add: features/support/machinist.rb
6
+ #
7
+ # require 'machinist/active_record' # or your chosen adaptor
8
+ # require File.dirname(__FILE__) + '/../../spec/blueprints' # or wherever your blueprints are
9
+ # Before { Sham.reset } # to reset Sham's seed between scenarios so each run has same random sequences
10
+ #
11
+ # For FactoryGirl add: features/support/factory_girl.rb
12
+ #
13
+ # require 'factory_girl'
14
+ # require File.dirname(__FILE__) + '/../../spec/factories' # or wherever your factories are
15
+ #
16
+ # You may also need to add gem dependencies on your factory of choice in <tt>config/environments/cucumber.rb</tt>
17
+
18
+ require 'pickle/world'
19
+ # Example of configuring pickle:
20
+ #
21
+ # Pickle.configure do |config|
22
+ # config.adapters = [:machinist]
23
+ # config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
24
+ # end
25
+ <%- if pickle_path -%>require 'pickle/path/world'
26
+ <%- end -%>
27
+ <%- if pickle_email -%>require 'pickle/email/world'
28
+ <%- end -%>
@@ -0,0 +1,100 @@
1
+ # this file generated by script/generate pickle
2
+
3
+ # create a model
4
+ Given(/^#{capture_model} exists?(?: with #{capture_fields})?$/) do |name, fields|
5
+ create_model(name, fields)
6
+ end
7
+
8
+ # create n models
9
+ Given(/^(\d+) #{capture_plural_factory} exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
10
+ count.to_i.times { create_model(plural_factory.singularize, fields) }
11
+ end
12
+
13
+ # create models from a table
14
+ Given(/^the following #{capture_plural_factory} exists?:?$/) do |plural_factory, table|
15
+ create_models_from_table(plural_factory, table)
16
+ end
17
+
18
+ # find a model
19
+ Then(/^#{capture_model} should exist(?: with #{capture_fields})?$/) do |name, fields|
20
+ find_model!(name, fields)
21
+ end
22
+
23
+ # not find a model
24
+ Then(/^#{capture_model} should not exist(?: with #{capture_fields})?$/) do |name, fields|
25
+ find_model(name, fields).should be_nil
26
+ end
27
+
28
+ # find models with a table
29
+ Then(/^the following #{capture_plural_factory} should exists?:?$/) do |plural_factory, table|
30
+ find_models_from_table(plural_factory, table).should_not be_any(&:nil?)
31
+ end
32
+
33
+ # find exactly n models
34
+ Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
35
+ find_models(plural_factory.singularize, fields).size.should == count.to_i
36
+ end
37
+
38
+ # assert equality of models
39
+ Then(/^#{capture_model} should be #{capture_model}$/) do |a, b|
40
+ model!(a).should == model!(b)
41
+ end
42
+
43
+ # assert model is in another model's has_many assoc
44
+ Then(/^#{capture_model} should be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
45
+ model!(owner).send(association).should include(model!(target))
46
+ end
47
+
48
+ # assert model is not in another model's has_many assoc
49
+ Then(/^#{capture_model} should not be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
50
+ model!(owner).send(association).should_not include(model!(target))
51
+ end
52
+
53
+ # assert model is another model's has_one/belongs_to assoc
54
+ Then(/^#{capture_model} should be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
55
+ model!(owner).send(association).should == model!(target)
56
+ end
57
+
58
+ # assert model is not another model's has_one/belongs_to assoc
59
+ Then(/^#{capture_model} should not be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
60
+ model!(owner).send(association).should_not == model!(target)
61
+ end
62
+
63
+ # assert model.predicate?
64
+ Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
65
+ if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
66
+ model!(name).should send("have_#{predicate.gsub(' ', '_')}")
67
+ else
68
+ model!(name).should send("be_#{predicate.gsub(' ', '_')}")
69
+ end
70
+ end
71
+
72
+ # assert not model.predicate?
73
+ Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
74
+ if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
75
+ model!(name).should_not send("have_#{predicate.gsub(' ', '_')}")
76
+ else
77
+ model!(name).should_not send("be_#{predicate.gsub(' ', '_')}")
78
+ end
79
+ end
80
+
81
+ # model.attribute.should eql(value)
82
+ # model.attribute.should_not eql(value)
83
+ Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}$/) do |name, attribute, expectation, expected|
84
+ actual_value = model(name).send(attribute)
85
+ expectation = expectation.gsub(' ', '_')
86
+
87
+ case expected
88
+ when 'nil', 'true', 'false'
89
+ actual_value.send(expectation, send("be_#{expected}"))
90
+ when /^[+-]?[0-9_]+(\.\d+)?$/
91
+ actual_value.send(expectation, eql(expected.to_f))
92
+ else
93
+ actual_value.to_s.send(expectation, eql(eval(expected)))
94
+ end
95
+ end
96
+
97
+ # assert size of association
98
+ Then /^#{capture_model} should have (\d+) (\w+)$/ do |name, size, association|
99
+ model!(name).send(association).size.should == size.to_i
100
+ end
@@ -0,0 +1,186 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ require 'active_record'
4
+ require 'factory_girl'
5
+ require 'machinist/active_record'
6
+ require 'pickle/adapters/active_record'
7
+
8
+ describe Pickle::Adapter do
9
+ it ".factories should raise NotImplementedError" do
10
+ lambda { Pickle::Adapter.factories }.should raise_error(NotImplementedError)
11
+ end
12
+
13
+ it "#create should raise NotImplementedError" do
14
+ lambda { Pickle::Adapter.new.create }.should raise_error(NotImplementedError)
15
+ end
16
+
17
+ describe ".model_classes" do
18
+ before do
19
+ Pickle::Adapter.model_classes = nil
20
+ end
21
+
22
+ it "should only include #suitable_for_pickle classes" do
23
+ klass1 = Class.new(ActiveRecord::Base)
24
+ klass2 = Class.new(ActiveRecord::Base)
25
+ klass3 = Class.new(ActiveRecord::Base)
26
+ klass4 = Class.new(ActiveRecord::Base)
27
+ klass5 = Class.new(ActiveRecord::Base)
28
+ klass6 = Class.new(ActiveRecord::Base)
29
+ [klass1, klass2, klass3, klass4, klass5, klass6].each { |k| k.stub!(:table_exists?).and_return(true) }
30
+
31
+ klass2.stub!(:name).and_return("CGI::Session::ActiveRecordStore::Session")
32
+ klass3.stub!(:name).and_return("ActiveRecord::SessionStore::Session")
33
+ klass4.stub!(:table_exists?).and_return(false)
34
+ klass5.stub!(:abstract_class?).and_return(true)
35
+ Pickle::Adapter.model_classes.should include(klass1, klass6)
36
+ Pickle::Adapter.model_classes.should_not include(klass2, klass3, klass4, klass5)
37
+ end
38
+ end
39
+
40
+ describe "adapters: " do
41
+ before do
42
+ @klass1 = returning(Class.new(ActiveRecord::Base)) { |k| k.stub!(:name).and_return('One') }
43
+ @klass2 = returning(Class.new(ActiveRecord::Base)) { |k| k.stub!(:name).and_return('One::Two') }
44
+ @klass3 = returning(Class.new(ActiveRecord::Base)) { |k| k.stub!(:name).and_return('Three') }
45
+ end
46
+
47
+ describe 'ActiveRecord' do
48
+
49
+ #DEPRECATION WARNING: subclasses is deprecated and will be removed from Rails 3.0 (use descendants instead). (called from __send__ at /Users/pivotal/workspace/factorylabs/protosite/vendor/cache/ruby/1.8/gems/pickle-0.3.1/lib/pickle/adapters/active_record.rb:21)
50
+
51
+ describe ".model_classes" do
52
+ it "calls .descendants" do
53
+ ::ActiveRecord::Base.should_receive(:descendants).and_return([])
54
+ ::ActiveRecord::Base.should_not_receive(:subclasses).and_return([])
55
+
56
+ ActiveRecord::Base::PickleAdapter.model_classes
57
+ end
58
+
59
+ it "calls .subclasses when .descendants doesn't respond" do
60
+ ::ActiveRecord::Base.should_receive(:subclasses).and_return([])
61
+
62
+ ActiveRecord::Base::PickleAdapter.model_classes
63
+ end
64
+
65
+ end
66
+
67
+ describe 'with class stubs' do
68
+ before do
69
+ Pickle::Adapter::Orm.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
70
+ end
71
+
72
+ it ".factories should create one for each active record class" do
73
+ Pickle::Adapter::Orm.should_receive(:new).with(@klass1).once
74
+ Pickle::Adapter::Orm.should_receive(:new).with(@klass2).once
75
+ Pickle::Adapter::Orm.should_receive(:new).with(@klass3).once
76
+ Pickle::Adapter::Orm.factories.length.should == 3
77
+ end
78
+
79
+ describe ".new(Class)" do
80
+ before do
81
+ @factory = Pickle::Adapter::Orm.new(@klass2)
82
+ end
83
+
84
+ it "should have underscored (s/_) name of Class as #name" do
85
+ @factory.name.should == 'one_two'
86
+ end
87
+
88
+ it "#create(attrs) should call Class.create!(attrs)" do
89
+ @klass2.should_receive(:create!).with({:key => "val"})
90
+ @factory.create(:key => "val")
91
+ end
92
+ end
93
+ end
94
+
95
+
96
+ end
97
+
98
+ describe 'FactoryGirl' do
99
+ before do
100
+ Pickle::Adapter::FactoryGirl.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
101
+ @orig_factories, Factory.factories = Factory.factories, {}
102
+
103
+ Factory.define(:one, :class => @klass1) {}
104
+ Factory.define(:two, :class => @klass2) {}
105
+ @factory1 = Factory.factories[:one]
106
+ @factory2 = Factory.factories[:two]
107
+ end
108
+
109
+ after do
110
+ Factory.factories = @orig_factories
111
+ end
112
+
113
+ it ".factories should create one for each factory" do
114
+ Pickle::Adapter::FactoryGirl.should_receive(:new).with(@factory1).once
115
+ Pickle::Adapter::FactoryGirl.should_receive(:new).with(@factory2).once
116
+ Pickle::Adapter::FactoryGirl.factories
117
+ end
118
+
119
+ describe ".new(factory)" do
120
+ before do
121
+ @factory = Pickle::Adapter::FactoryGirl.new(@factory1)
122
+ end
123
+
124
+ it "should have name of factory_name" do
125
+ @factory.name.should == 'one'
126
+ end
127
+
128
+ it "should have klass of build_class" do
129
+ @factory.klass.should == @klass1
130
+ end
131
+
132
+ it "#create(attrs) should call Factory(<:key>, attrs)" do
133
+ Factory.should_receive(:create).with("one", {:key => "val"})
134
+ @factory.create(:key => "val")
135
+ end
136
+ end
137
+ end
138
+
139
+ describe 'Machinist' do
140
+ before do
141
+ Pickle::Adapter::Machinist.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
142
+
143
+ @klass1.blueprint {}
144
+ @klass3.blueprint {}
145
+ @klass3.blueprint(:special) {}
146
+ end
147
+
148
+ it ".factories should create one for each master blueprint, and special case" do
149
+ Pickle::Adapter::Machinist.should_receive(:new).with(@klass1, :master).once
150
+ Pickle::Adapter::Machinist.should_receive(:new).with(@klass3, :master).once
151
+ Pickle::Adapter::Machinist.should_receive(:new).with(@klass3, :special).once
152
+ Pickle::Adapter::Machinist.factories
153
+ end
154
+
155
+ describe ".new(Class, :master)" do
156
+ before do
157
+ @factory = Pickle::Adapter::Machinist.new(@klass1, :master)
158
+ end
159
+
160
+ it "should have underscored (s/_) name of Class as #name" do
161
+ @factory.name.should == 'one'
162
+ end
163
+
164
+ it "#create(attrs) should call Class.make(:master, attrs)" do
165
+ @klass1.should_receive(:make).with(:master, {:key => "val"})
166
+ @factory.create(:key => "val")
167
+ end
168
+ end
169
+
170
+ describe ".new(Class, :special)" do
171
+ before do
172
+ @factory = Pickle::Adapter::Machinist.new(@klass3, :special)
173
+ end
174
+
175
+ it "should have 'special_<Class name>' as #name" do
176
+ @factory.name.should == 'special_three'
177
+ end
178
+
179
+ it "#create(attrs) should call Class.make(:special, attrs)" do
180
+ @klass3.should_receive(:make).with(:special, {:key => "val"})
181
+ @factory.create(:key => "val")
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,109 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Pickle::Config do
4
+ before do
5
+ @config = Pickle::Config.new
6
+ end
7
+
8
+ it "#adapters should default to :machinist, :factory_girl, :orm" do
9
+ @config.adapters.should == [:machinist, :factory_girl, :orm]
10
+ end
11
+
12
+ it "#adapter_classes should default to Adapter::Machinist, Adapter::FactoryGirl, Adapter::Orm" do
13
+ @config.adapter_classes.should == [Pickle::Adapter::Machinist, Pickle::Adapter::FactoryGirl, Pickle::Adapter::Orm]
14
+ end
15
+
16
+ describe "setting adapters to [:machinist, SomeAdapter]" do
17
+ class SomeAdapter; end
18
+
19
+ before do
20
+ @config.adapters = [:machinist, SomeAdapter]
21
+ end
22
+
23
+ it "#adapter_classes should be Adapter::Machinist, SomeAdapter" do
24
+ @config.adapter_classes.should == [Pickle::Adapter::Machinist, SomeAdapter]
25
+ end
26
+ end
27
+
28
+ describe "#factories" do
29
+ it "should call adaptor.factories for each adaptor" do
30
+ Pickle::Adapter::Machinist.should_receive(:factories).and_return([])
31
+ Pickle::Adapter::FactoryGirl.should_receive(:factories).and_return([])
32
+ Pickle::Adapter::Orm.should_receive(:factories).and_return([])
33
+ @config.factories
34
+ end
35
+
36
+ it "should aggregate factories into a hash using factory name as key" do
37
+ Pickle::Adapter::Machinist.should_receive(:factories).and_return([@machinist = mock('machinist', :name => 'machinist')])
38
+ Pickle::Adapter::FactoryGirl.should_receive(:factories).and_return([@factory_girl = mock('factory_girl', :name => 'factory_girl')])
39
+ Pickle::Adapter::Orm.should_receive(:factories).and_return([@orm = mock('orm', :name => 'orm')])
40
+ @config.factories.should == {'machinist' => @machinist, 'factory_girl' => @factory_girl, 'orm' => @orm}
41
+ end
42
+
43
+ it "should give preference to adaptors first in the list" do
44
+ Pickle::Adapter::Machinist.should_receive(:factories).and_return([@machinist_one = mock('one', :name => 'one')])
45
+ Pickle::Adapter::FactoryGirl.should_receive(:factories).and_return([@factory_girl_one = mock('one', :name => 'one'), @factory_girl_two = mock('two', :name => 'two')])
46
+ Pickle::Adapter::Orm.should_receive(:factories).and_return([@orm_two = mock('two', :name => 'two'), @orm_three = mock('three', :name => 'three')])
47
+ @config.factories.should == {'one' => @machinist_one, 'two' => @factory_girl_two, 'three' => @orm_three}
48
+ end
49
+ end
50
+
51
+ it "#mappings should default to []" do
52
+ @config.mappings.should == []
53
+ end
54
+
55
+ describe '#predicates' do
56
+ it "should be list of all non object ? public instance methods + columns methods of Adapter.model_classes" do
57
+ class1 = mock('Class1',
58
+ :public_instance_methods => ['nope', 'foo?', 'bar?'],
59
+ :column_names => ['one', 'two'],
60
+ :const_get => ::ActiveRecord::Base::PickleAdapter
61
+ )
62
+ class2 = mock('Class2',
63
+ :public_instance_methods => ['not', 'foo?', 'faz?'],
64
+ :column_names => ['two', 'three'],
65
+ :const_get => ::ActiveRecord::Base::PickleAdapter
66
+ )
67
+ Pickle::Adapter.stub!(:model_classes).and_return([class1, class2])
68
+
69
+ @config.predicates.to_set.should == ['foo?', 'faz?', 'bar?', 'one', 'two', 'three'].to_set
70
+ end
71
+
72
+ it "should be overridable" do
73
+ @config.predicates = %w(lame?)
74
+ @config.predicates.should == %w(lame?)
75
+ end
76
+ end
77
+
78
+ describe "#map 'foo', :to => 'faz'" do
79
+ before do
80
+ @config.map 'foo', :to => 'faz'
81
+ end
82
+
83
+ it "should create Mapping('foo', 'faz') mapping" do
84
+ @config.mappings.first.tap do |mapping|
85
+ mapping.should be_kind_of Pickle::Config::Mapping
86
+ mapping.search.should == 'foo'
87
+ mapping.replacement.should == 'faz'
88
+ end
89
+ end
90
+ end
91
+
92
+ describe "#map 'foo', 'bar' :to => 'faz'" do
93
+ before do
94
+ @config.map 'foo', 'bar', :to => 'faz'
95
+ end
96
+
97
+ it "should create 2 mappings" do
98
+ @config.mappings.first.should == Pickle::Config::Mapping.new('foo', 'faz')
99
+ @config.mappings.last.should == Pickle::Config::Mapping.new('bar', 'faz')
100
+ end
101
+ end
102
+
103
+ it "#configure(&block) should execiute on self" do
104
+ @config.should_receive(:foo).with(:bar)
105
+ @config.configure do |c|
106
+ c.foo :bar
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ require 'pickle/email/parser'
4
+
5
+ describe Pickle::Email::Parser do
6
+ include Pickle::Parser::Matchers
7
+ include Pickle::Email::Parser
8
+
9
+ describe "#match_email" do
10
+ it "should match 'the email'" do
11
+ 'the email'.should match(/^#{match_email}$/)
12
+ end
13
+
14
+ it "should match 'the first email'" do
15
+ 'the first email'.should match(/^#{match_email}$/)
16
+ end
17
+
18
+ it "should match 'the last email'" do
19
+ 'the last email'.should match(/^#{match_email}$/)
20
+ end
21
+
22
+ it "should match 'the 3rd email'" do
23
+ 'the 3rd email'.should match(/^#{match_email}$/)
24
+ end
25
+
26
+ it "should match 'an email'" do
27
+ 'an email'.should match(/^#{match_email}$/)
28
+ end
29
+ end
30
+
31
+ it "#capture_email should just capture match_email" do
32
+ capture_email.should == "(#{match_email})"
33
+ end
34
+
35
+ describe "#capture_index_in_email" do
36
+ it "should extract the '2nd' from 'the 2nd email'" do
37
+ match = 'the 2nd email'.match(/^#{capture_index_in_email}$/)
38
+ match[1].should == '2nd'
39
+ end
40
+
41
+ it "should extract nil from 'the email'" do
42
+ match = 'the email'.match(/^#{capture_index_in_email}$/)
43
+ match[1].should == nil
44
+ end
45
+
46
+ it "should extract the 'last' from 'the last email'" do
47
+ match = 'the last email'.match(/^#{capture_index_in_email}$/)
48
+ match[1].should == 'last'
49
+ end
50
+ end
51
+ end