spbtv_pickle 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Gemfile +3 -0
- data/Gemfile.lock.development +158 -0
- data/History.txt +499 -0
- data/License.txt +20 -0
- data/README.md +566 -0
- data/Rakefile +20 -0
- data/Rakefile.d/cucumber.rake +27 -0
- data/Rakefile.d/release.rake +44 -0
- data/Rakefile.d/rspec.rake +3 -0
- data/Rakefile.d/yard.rake +5 -0
- data/Todo.txt +3 -0
- data/autotest/discover.rb +9 -0
- data/features/app/app.rb +128 -0
- data/features/app/blueprints.rb +6 -0
- data/features/app/fabricators.rb +6 -0
- data/features/app/factories.rb +25 -0
- data/features/app/views/notifier/email.erb +1 -0
- data/features/app/views/notifier/user_email.erb +6 -0
- data/features/email/email.feature +64 -0
- data/features/generator/generators.feature +59 -0
- data/features/path/models_page.feature +44 -0
- data/features/path/named_route_page.feature +10 -0
- data/features/pickle/create_from_active_record.feature +83 -0
- data/features/pickle/create_from_fabrication.feature +46 -0
- data/features/pickle/create_from_factory_girl.feature +66 -0
- data/features/pickle/create_from_machinist.feature +46 -0
- data/features/step_definitions/email_steps.rb +1 -0
- data/features/step_definitions/extra_email_steps.rb +12 -0
- data/features/step_definitions/fork_steps.rb +4 -0
- data/features/step_definitions/generator_steps.rb +52 -0
- data/features/step_definitions/path_steps.rb +14 -0
- data/features/step_definitions/pickle_steps.rb +1 -0
- data/features/step_definitions/raise_error_steps.rb +7 -0
- data/features/support/email.rb +1 -0
- data/features/support/env.rb +14 -0
- data/features/support/paths.rb +47 -0
- data/features/support/pickle.rb +27 -0
- data/features/support/pickle_app.rb +4 -0
- data/init.rb +0 -0
- data/lib/generators/pickle_generator.rb +44 -0
- data/lib/pickle.rb +26 -0
- data/lib/pickle/adapter.rb +183 -0
- data/lib/pickle/adapters/active_record.rb +67 -0
- data/lib/pickle/adapters/data_mapper.rb +42 -0
- data/lib/pickle/adapters/mongoid.rb +54 -0
- data/lib/pickle/config.rb +49 -0
- data/lib/pickle/email.rb +87 -0
- data/lib/pickle/email/parser.rb +18 -0
- data/lib/pickle/email/world.rb +13 -0
- data/lib/pickle/parser.rb +65 -0
- data/lib/pickle/parser/matchers.rb +87 -0
- data/lib/pickle/path.rb +45 -0
- data/lib/pickle/path/world.rb +5 -0
- data/lib/pickle/session.rb +244 -0
- data/lib/pickle/session/parser.rb +34 -0
- data/lib/pickle/version.rb +3 -0
- data/lib/pickle/world.rb +14 -0
- data/lib/spbtv_pickle.rb +1 -0
- data/rails_generators/pickle/pickle_generator.rb +31 -0
- data/rails_generators/pickle/templates/email.rb +21 -0
- data/rails_generators/pickle/templates/email_steps.rb +65 -0
- data/rails_generators/pickle/templates/paths.rb +47 -0
- data/rails_generators/pickle/templates/pickle.rb +29 -0
- data/rails_generators/pickle/templates/pickle_steps.rb +105 -0
- data/spbtv_pickle.gemspec +38 -0
- data/spec/pickle/adapter_spec.rb +203 -0
- data/spec/pickle/config_spec.rb +112 -0
- data/spec/pickle/email/parser_spec.rb +51 -0
- data/spec/pickle/email_spec.rb +187 -0
- data/spec/pickle/parser/matchers_spec.rb +70 -0
- data/spec/pickle/parser_spec.rb +165 -0
- data/spec/pickle/path_spec.rb +120 -0
- data/spec/pickle/session_spec.rb +448 -0
- data/spec/pickle_spec.rb +24 -0
- data/spec/spec_helper.rb +78 -0
- metadata +370 -0
@@ -0,0 +1,112 @@
|
|
1
|
+
require '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
|
+
expect(@config.adapters).to eq([:machinist, :factory_girl, :fabrication, :orm])
|
10
|
+
end
|
11
|
+
|
12
|
+
it "#adapter_classes should default to Adapter::Machinist, Adapter::FactoryGirl, Adapter::Orm" do
|
13
|
+
expect(@config.adapter_classes).to eq([Pickle::Adapter::Machinist, Pickle::Adapter::FactoryGirl, Pickle::Adapter::Fabrication, 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
|
+
expect(@config.adapter_classes).to eq([Pickle::Adapter::Machinist, SomeAdapter])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#factories" do
|
29
|
+
it "should call adaptor.factories for each adaptor" do
|
30
|
+
expect(Pickle::Adapter::Machinist).to receive(:factories).and_return([])
|
31
|
+
expect(Pickle::Adapter::FactoryGirl).to receive(:factories).and_return([])
|
32
|
+
expect(Pickle::Adapter::Fabrication).to receive(:factories).and_return([])
|
33
|
+
expect(Pickle::Adapter::Orm).to receive(:factories).and_return([])
|
34
|
+
@config.factories
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should aggregate factories into a hash using factory name as key" do
|
38
|
+
expect(Pickle::Adapter::Machinist).to receive(:factories).and_return([@machinist = double('machinist', :name => 'machinist')])
|
39
|
+
expect(Pickle::Adapter::FactoryGirl).to receive(:factories).and_return([@factory_girl = double('factory_girl', :name => 'factory_girl')])
|
40
|
+
expect(Pickle::Adapter::Fabrication).to receive(:factories).and_return([@fabrication = double('fabrication', :name => 'fabrication')])
|
41
|
+
expect(Pickle::Adapter::Orm).to receive(:factories).and_return([@orm = double('orm', :name => 'orm')])
|
42
|
+
expect(@config.factories).to eq({'machinist' => @machinist, 'factory_girl' => @factory_girl, 'fabrication' => @fabrication, 'orm' => @orm})
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should give preference to adaptors first in the list" do
|
46
|
+
expect(Pickle::Adapter::Machinist).to receive(:factories).and_return([@machinist_one = double('one', :name => 'one')])
|
47
|
+
expect(Pickle::Adapter::FactoryGirl).to receive(:factories).and_return([@factory_girl_one = double('one', :name => 'one'), @factory_girl_two = double('two', :name => 'two')])
|
48
|
+
expect(Pickle::Adapter::Fabrication).to receive(:factories).and_return([@fabrication_one = double('one', :name => 'one'), @fabrication_three = double('three', :name => 'three')])
|
49
|
+
expect(Pickle::Adapter::Orm).to receive(:factories).and_return([@orm_two = double('two', :name => 'two'), @orm_four = double('four', :name => 'four')])
|
50
|
+
expect(@config.factories).to eq({'one' => @machinist_one, 'two' => @factory_girl_two, 'three' => @fabrication_three, 'four' => @orm_four})
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "#mappings should default to []" do
|
55
|
+
expect(@config.mappings).to eq([])
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#predicates' do
|
59
|
+
it "should be list of all non object ? public instance methods + columns methods of Adapter.model_classes" do
|
60
|
+
class1 = double('Class1',
|
61
|
+
:public_instance_methods => ['nope', 'foo?', 'bar?'],
|
62
|
+
:column_names => ['one', 'two'],
|
63
|
+
:const_get => ::ActiveRecord::Base::PickleAdapter
|
64
|
+
)
|
65
|
+
class2 = double('Class2',
|
66
|
+
:public_instance_methods => ['not', 'foo?', 'faz?'],
|
67
|
+
:column_names => ['two', 'three'],
|
68
|
+
:const_get => ::ActiveRecord::Base::PickleAdapter
|
69
|
+
)
|
70
|
+
allow(Pickle::Adapter).to receive(:model_classes).and_return([class1, class2])
|
71
|
+
|
72
|
+
expect(@config.predicates.to_set).to eq(['foo?', 'faz?', 'bar?', 'one', 'two', 'three'].to_set)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should be overridable" do
|
76
|
+
@config.predicates = %w(lame?)
|
77
|
+
expect(@config.predicates).to eq(%w(lame?))
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#map 'foo', :to => 'faz'" do
|
82
|
+
before do
|
83
|
+
@config.map 'foo', :to => 'faz'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should create Mapping('foo', 'faz') mapping" do
|
87
|
+
@config.mappings.first.tap do |mapping|
|
88
|
+
expect(mapping).to be_kind_of Pickle::Config::Mapping
|
89
|
+
expect(mapping.search).to eq('foo')
|
90
|
+
expect(mapping.replacement).to eq('faz')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#map 'foo', 'bar' :to => 'faz'" do
|
96
|
+
before do
|
97
|
+
@config.map 'foo', 'bar', :to => 'faz'
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should create 2 mappings" do
|
101
|
+
expect(@config.mappings.first).to eq(Pickle::Config::Mapping.new('foo', 'faz'))
|
102
|
+
expect(@config.mappings.last).to eq(Pickle::Config::Mapping.new('bar', 'faz'))
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it "#configure(&block) should execiute on self" do
|
107
|
+
expect(@config).to receive(:foo).with(:bar)
|
108
|
+
@config.configure do |c|
|
109
|
+
c.foo :bar
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require '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
|
+
expect('the email').to match(/^#{match_email}$/)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should match 'the first email'" do
|
15
|
+
expect('the first email').to match(/^#{match_email}$/)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should match 'the last email'" do
|
19
|
+
expect('the last email').to match(/^#{match_email}$/)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should match 'the 3rd email'" do
|
23
|
+
expect('the 3rd email').to match(/^#{match_email}$/)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should match 'an email'" do
|
27
|
+
expect('an email').to match(/^#{match_email}$/)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "#capture_email should just capture match_email" do
|
32
|
+
expect(capture_email).to eq("(#{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
|
+
expect(match[1]).to eq('2nd')
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should extract nil from 'the email'" do
|
42
|
+
match = 'the email'.match(/^#{capture_index_in_email}$/)
|
43
|
+
expect(match[1]).to eq(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
|
+
expect(match[1]).to eq('last')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'pickle/email'
|
4
|
+
require 'pickle/email/parser'
|
5
|
+
require 'action_mailer'
|
6
|
+
|
7
|
+
describe Pickle::Email do
|
8
|
+
include Pickle::Session
|
9
|
+
include Pickle::Email
|
10
|
+
include Pickle::Email::Parser
|
11
|
+
|
12
|
+
before do
|
13
|
+
@email1 = double("Email 1")
|
14
|
+
@email2 = double("Email 2")
|
15
|
+
allow(ActionMailer::Base).to receive(:deliveries).and_return([@email1, @email2])
|
16
|
+
if defined?(ActiveRecord::Base)
|
17
|
+
allow(ActiveRecord::Base::PickleAdapter).to receive(:model_classes).and_return([])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#emails" do
|
22
|
+
it "should return ordered deliveries" do
|
23
|
+
expect(emails).to eq([@email1, @email2])
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "(after)" do
|
27
|
+
before do
|
28
|
+
emails
|
29
|
+
end
|
30
|
+
|
31
|
+
it "#email('the email') should return the last delivery" do
|
32
|
+
expect(email('the email')).to eq(@email2)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "#email('the 1st email') should return the first delivery" do
|
36
|
+
expect(email('the 1st email')).to eq(@email1)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "#email('the first email') should return the first delivery" do
|
40
|
+
expect(email('the first email')).to eq(@email1)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "#email('the 2nd email') should return the second delivery" do
|
44
|
+
expect(email('the 2nd email')).to eq(@email2)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "#email('the last email') should return the second delivery" do
|
48
|
+
expect(email('the last email')).to eq(@email2)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "#email2('the 3rd email') should be nil" do
|
52
|
+
expect(email('the 3rd email')).to eq(nil)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "when email1 is to fred & joe, and email2 is to joe" do
|
57
|
+
before do
|
58
|
+
allow(@email1).to receive(:to).and_return(['fred@gmail.com', 'joe@gmail.com'])
|
59
|
+
allow(@email2).to receive(:to).and_return('joe@gmail.com')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "#emails('to: \"fred@gmail.com\"') should just return email1" do
|
63
|
+
expect(emails('to: "fred@gmail.com"')).to eq([@email1])
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "after #emails('to: \"fred@gmail.com\"')" do
|
67
|
+
before do
|
68
|
+
emails('to: "fred@gmail.com"')
|
69
|
+
end
|
70
|
+
|
71
|
+
it "#email('first') should be #email('last')" do
|
72
|
+
expect(email('first email')).to eq(email('last email'))
|
73
|
+
expect(email('first email')).to eq(@email1)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "#email('the email', 'to: \"blah\") should be nil" do
|
77
|
+
expect(email('the email', 'to: "blah"')).to eq(nil)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "#email('the email', 'to: \"fred@gmail.com\") should be email1" do
|
81
|
+
expect(email('the email', 'to: "fred@gmail.com"')).to eq(@email1)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it "#emails('to: \"joe@gmail.com\"') should return both emails" do
|
86
|
+
expect(emails('to: "joe@gmail.com"')).to eq([@email1, @email2])
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "and emails have subjects 'email1', 'email2'" do
|
90
|
+
before do
|
91
|
+
allow(@email1).to receive(:subject).and_return('email1')
|
92
|
+
allow(@email2).to receive(:subject).and_return('email2')
|
93
|
+
end
|
94
|
+
|
95
|
+
it "#emails('to: \"joe@gmail.com\", subject: \"email1\"') should return email1" do
|
96
|
+
expect(emails('to: "joe@gmail.com", subject: "email1"')).to eq([@email1])
|
97
|
+
end
|
98
|
+
|
99
|
+
it "#emails('to: \"fred@gmail.com\", subject: \"email2\"') should return empty array" do
|
100
|
+
expect(emails('to: "fred@gmail.com", subject: "email2"')).to eq([])
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#save_and_open_emails" do
|
107
|
+
before do
|
108
|
+
allow(self).to receive(:open_in_browser)
|
109
|
+
allow(self).to receive(:emails).and_return(["Contents of Email 1"])
|
110
|
+
@now = "2008-01-01".to_time
|
111
|
+
allow(Time).to receive(:now).and_return(@now)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should call #emails to get emails" do
|
115
|
+
expect(self).to receive(:emails).and_return([])
|
116
|
+
save_and_open_emails
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "when emails have been already been found" do
|
120
|
+
before { @emails = [] }
|
121
|
+
|
122
|
+
it "should not call #emails" do
|
123
|
+
expect(self).not_to receive(:emails)
|
124
|
+
save_and_open_emails
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should create a file in Rails/tmp with the emails in it" do
|
129
|
+
save_and_open_emails
|
130
|
+
expect(File.read("pickle-email-#{@now.to_i}.html")).to eq("<h1>Email 1</h1><pre>Contents of Email 1</pre><hr />")
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should call open_in_browser on created tmp file" do
|
134
|
+
expect(self).to receive(:open_in_browser).with("pickle-email-#{@now.to_i}.html")
|
135
|
+
save_and_open_emails
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "following links in emails" do
|
140
|
+
let(:body) { 'some text <a href="http://example.com/page">example page</a> more text' }
|
141
|
+
|
142
|
+
before do
|
143
|
+
allow(self).to receive(:open_in_browser)
|
144
|
+
end
|
145
|
+
|
146
|
+
shared_examples_for 'an email with links' do
|
147
|
+
it "should find a link for http://example.com/page" do
|
148
|
+
expect(self).to receive(:visit).with('http://example.com/page')
|
149
|
+
visit_in_email(@email1, 'http://example.com/page')
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should find a link for \"example page\"" do
|
153
|
+
expect(self).to receive(:visit).with('http://example.com/page')
|
154
|
+
visit_in_email(@email1, 'example page')
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should follow the first link in an email" do
|
158
|
+
expect(self).to receive(:visit).with('http://example.com/page')
|
159
|
+
click_first_link_in_email(@email1)
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should not raise an error when the email body is not a string, but needs to_s [#26]" do
|
163
|
+
allow(self).to receive(:visit)
|
164
|
+
allow(@email1).to receive(:body).and_return(:a_string_body)
|
165
|
+
expect { click_first_link_in_email(@email1) }.not_to raise_error
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "non multi-part emails" do
|
170
|
+
before do
|
171
|
+
allow(@email1).to receive(:multipart?).and_return(false)
|
172
|
+
allow(@email1).to receive(:body).and_return(body)
|
173
|
+
end
|
174
|
+
|
175
|
+
it_behaves_like 'an email with links'
|
176
|
+
end
|
177
|
+
|
178
|
+
context "multi-part emails" do
|
179
|
+
before do
|
180
|
+
allow(@email1).to receive(:multipart?).and_return(true)
|
181
|
+
allow(@email1).to receive_message_chain(:html_part, :body).and_return(body)
|
182
|
+
end
|
183
|
+
|
184
|
+
it_behaves_like 'an email with links'
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pickle::Parser::Matchers do
|
4
|
+
include Pickle::Parser::Matchers
|
5
|
+
|
6
|
+
describe "(config: [factories: user, car, fast_car] [predicates: name, status, fancy?, super_fancy?, has_style?, has_super_style?]" do
|
7
|
+
def config
|
8
|
+
@config ||= Pickle::Config.new do |c|
|
9
|
+
c.factories = {
|
10
|
+
'user' => double('factory'),
|
11
|
+
'car' => double('factory'),
|
12
|
+
'fast_car' => double('factory')
|
13
|
+
}
|
14
|
+
c.predicates = %w(name status fancy? super_fancy? has_style? has_super_style?)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "Match atoms" do
|
19
|
+
def self.atom_should_match(atom, strings)
|
20
|
+
Array(strings).each do |string|
|
21
|
+
it "#{atom} should match '#{string}'" do
|
22
|
+
expect(string).to match(/^#{send atom}$/)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.atom_should_not_match(atom, strings)
|
28
|
+
Array(strings).each do |string|
|
29
|
+
it "#{atom} should NOT match '#{string}'" do
|
30
|
+
expect(string).not_to match(/^#{send atom}$/)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
atom_should_match :match_ordinal, ['1st', '2nd', '23rd', '104th']
|
36
|
+
atom_should_not_match :match_ordinal, ['1', '2']
|
37
|
+
|
38
|
+
atom_should_match :match_index, ['first', 'last', '23rd', '104th']
|
39
|
+
atom_should_not_match :match_index, ['1', '2', 'foo']
|
40
|
+
|
41
|
+
atom_should_match :match_label, [': "gday"', ': "gday mate"']
|
42
|
+
atom_should_not_match :match_label, [': "gday""', ': gday']
|
43
|
+
|
44
|
+
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']
|
45
|
+
atom_should_not_match :match_field, ['foo bar: "this aint workin"', 'not_numeric: --10', 'not_numeric: -ten']
|
46
|
+
|
47
|
+
atom_should_match :match_fields, ['foo: "bar"', 'foo: "bar", baz: "bah"']
|
48
|
+
atom_should_not_match :match_fields, ['foo bar: "baz"', 'email: "a", password: "b", and password_confirmation: "c"']
|
49
|
+
|
50
|
+
atom_should_match :match_model, ['a user', '1st fast car', 'the 23rd fast_car', 'the user: "fred flinstone"']
|
51
|
+
atom_should_not_match :match_model, ['a giraffe', 'a 1st faster car: "jim"', 'an event created']
|
52
|
+
|
53
|
+
atom_should_match :match_predicate, ['name', 'status', 'fancy', 'super fancy', 'super_fancy', 'style', 'super style', 'super_style']
|
54
|
+
atom_should_not_match :match_predicate, ['nameo', 'increment', 'not a predicate', 'has style']
|
55
|
+
|
56
|
+
atom_should_match :match_factory, ['user', 'fast car', 'fast_car', 'car']
|
57
|
+
atom_should_not_match :match_factory, ['users', 'faster car', 'event created']
|
58
|
+
|
59
|
+
atom_should_match :match_plural_factory, ['users', 'fast cars']
|
60
|
+
atom_should_not_match :match_plural_factory, ['usereres', 'fasts cars']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "capture methods" do
|
65
|
+
it "capture_field should == '(' + match_field + ')'" do
|
66
|
+
expect(self).to receive(:match_field).and_return('MATCH_FIELD')
|
67
|
+
expect(capture_field).to eq('(MATCH_FIELD)')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pickle::Parser do
|
4
|
+
before do
|
5
|
+
@parser = Pickle::Parser.new(:config => Pickle::Config.new)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should raise error when created with no config" do
|
9
|
+
expect{ Pickle::Parser.new }.to raise_error(ArgumentError)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "when a 'user' factory exists in config" do
|
13
|
+
before do
|
14
|
+
allow(@parser.config).to receive(:factories).and_return('user' => double('User'))
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'misc regexps' do
|
18
|
+
describe '/^#{capture_model} exists/' do
|
19
|
+
before do
|
20
|
+
@regexp = /^(#{@parser.capture_model}) exists$/
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should match 'a user exists'" do
|
24
|
+
expect('a user exists').to match(@regexp)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should caputure 'a user' from 'a user exists'" do
|
28
|
+
expect('a user exists'.match(@regexp)[1]).to eq('a user')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#parse_field' do
|
34
|
+
it "should return {'a' => 'b'} for 'a: \"b\"'" do
|
35
|
+
expect(@parser.parse_field('a: "b"')).to eq({'a' => 'b'})
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should raise error for invalid field 'a : b'" do
|
39
|
+
expect { @parser.parse_field('a : b') }.to raise_error(ArgumentError)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#parse_fields' do
|
44
|
+
it 'should return {} for blank argument' do
|
45
|
+
expect(@parser.parse_fields(nil)).to eq({})
|
46
|
+
expect(@parser.parse_fields('')).to eq({})
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should raise error for invalid argument' do
|
50
|
+
expect { @parser.parse_fields('foo foo') }.to raise_error(ArgumentError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it '(\'foo: "bar"\') should == { "foo" => "bar"}' do
|
54
|
+
expect(@parser.parse_fields('foo: "bar"')).to eq({ "foo" => "bar"})
|
55
|
+
end
|
56
|
+
|
57
|
+
it '(\'foo: "something \"quoted\""\') should == { "foo" => "bar"}' do
|
58
|
+
expect(@parser.parse_fields('foo: "something \"quoted\""')).to eq({ "foo" => 'something "quoted"' })
|
59
|
+
end
|
60
|
+
|
61
|
+
it '("bool: true") should == { "bool" => true}' do
|
62
|
+
expect(@parser.parse_fields('bool: true')).to eq({"bool" => true})
|
63
|
+
end
|
64
|
+
|
65
|
+
it '("bool: false") should == { "bool" => false}' do
|
66
|
+
expect(@parser.parse_fields('bool: false')).to eq({"bool" => false})
|
67
|
+
end
|
68
|
+
|
69
|
+
it '("int: 10") should == { "int" => 10 }' do
|
70
|
+
expect(@parser.parse_fields('int: 10')).to eq({"int" => 10})
|
71
|
+
end
|
72
|
+
|
73
|
+
it '("float: 10.1") should == { "float" => 10.1 }' do
|
74
|
+
expect(@parser.parse_fields('float: 10.1')).to eq({"float" => 10.1})
|
75
|
+
end
|
76
|
+
|
77
|
+
it '(\'foo: "bar", bar_man: "wonga wonga", baz_woman: "one \"two\" three", gump: 123\') should == {"foo" => "bar", "bar_man" => "wonga wonga", "gump" => 123}' do
|
78
|
+
expect(@parser.parse_fields('foo: "bar", bar_man: "wonga wonga", baz_woman: "one \"two\" three", gump: 123')).to eq({"foo" => "bar", "bar_man" => "wonga wonga", "baz_woman" => "one \"two\" three", "gump" => 123})
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#parse_model' do
|
83
|
+
it '("a user") should == ["user", ""]' do
|
84
|
+
expect(@parser.parse_model("a user")).to eq(["user", ""])
|
85
|
+
end
|
86
|
+
|
87
|
+
it '("the user") should == ["user", ""]' do
|
88
|
+
expect(@parser.parse_model("the user")).to eq(["user", ""])
|
89
|
+
end
|
90
|
+
|
91
|
+
it '("1 user") should == ["user", ""]' do
|
92
|
+
expect(@parser.parse_model("1 user")).to eq(["user", ""])
|
93
|
+
end
|
94
|
+
|
95
|
+
it '(\'an user: "jim jones"\') should == ["user", "jim_jones"]' do
|
96
|
+
expect(@parser.parse_model('an user: "jim jones"')).to eq(["user", "jim_jones"])
|
97
|
+
end
|
98
|
+
|
99
|
+
it '(\'that user: "herbie"\') should == ["user", "herbie"]' do
|
100
|
+
expect(@parser.parse_model('that user: "herbie"')).to eq(["user", "herbie"])
|
101
|
+
end
|
102
|
+
|
103
|
+
it '(\'the 12th user\') should == ["user", 11]' do
|
104
|
+
expect(@parser.parse_model('the 12th user')).to eq(["user", 11])
|
105
|
+
end
|
106
|
+
|
107
|
+
it '(\'the last user\') should == ["user", -1]' do
|
108
|
+
expect(@parser.parse_model('the last user')).to eq(["user", -1])
|
109
|
+
end
|
110
|
+
|
111
|
+
it '("the first user") should == ["user", 0]' do
|
112
|
+
expect(@parser.parse_model('the first user')).to eq(["user", 0])
|
113
|
+
end
|
114
|
+
|
115
|
+
it '("the 1st user") should == ["user", 0]' do
|
116
|
+
expect(@parser.parse_model('the 1st user')).to eq(["user", 0])
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "#parse_index" do
|
121
|
+
it '("1st") should == 0' do
|
122
|
+
expect(@parser.parse_index("1st")).to eq(0)
|
123
|
+
end
|
124
|
+
|
125
|
+
it '("24th") should == 23' do
|
126
|
+
expect(@parser.parse_index("24th")).to eq(23)
|
127
|
+
end
|
128
|
+
it '("first") should == 0' do
|
129
|
+
expect(@parser.parse_index("first")).to eq(0)
|
130
|
+
end
|
131
|
+
|
132
|
+
it '("last") should == -1' do
|
133
|
+
expect(@parser.parse_index("last")).to eq(-1)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "customised mappings" do
|
139
|
+
describe "config maps 'I|myself' to 'user: \"me\"'" do
|
140
|
+
before do
|
141
|
+
@config = Pickle::Config.new do |c|
|
142
|
+
c.map 'I', 'myself', :to => 'user: "me"'
|
143
|
+
end
|
144
|
+
@parser = Pickle::Parser.new(:config => @config)
|
145
|
+
allow(@parser.config).to receive(:factories).and_return('user' => double('User'))
|
146
|
+
end
|
147
|
+
|
148
|
+
it "'I' should match /\#{match_model}/" do
|
149
|
+
expect('I').to match(/#{@parser.match_model}/)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "'myself' should match /\#{match_model}/" do
|
153
|
+
expect('myself').to match(/#{@parser.match_model}/)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "parse_model('I') should == ['user', 'me']" do
|
157
|
+
expect(@parser.parse_model('I')).to eq(["user", "me"])
|
158
|
+
end
|
159
|
+
|
160
|
+
it "parse_model('myself') should == ['user', 'me']" do
|
161
|
+
expect(@parser.parse_model('myself')).to eq(["user", "me"])
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|