mrflip-pickle 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +147 -0
- data/License.txt +20 -0
- data/README.rdoc +202 -0
- data/Todo.txt +4 -0
- data/lib/pickle.rb +26 -0
- data/lib/pickle/adapter.rb +87 -0
- data/lib/pickle/config.rb +48 -0
- data/lib/pickle/email.rb +36 -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 +44 -0
- data/lib/pickle/path/world.rb +5 -0
- data/lib/pickle/session.rb +151 -0
- data/lib/pickle/session/parser.rb +24 -0
- data/lib/pickle/version.rb +9 -0
- data/lib/pickle/world.rb +9 -0
- data/rails_generators/pickle/pickle_generator.rb +41 -0
- data/rails_generators/pickle/templates/email_steps.rb +50 -0
- data/rails_generators/pickle/templates/env.rb +14 -0
- data/rails_generators/pickle/templates/paths.rb +20 -0
- data/rails_generators/pickle/templates/pickle_steps.rb +41 -0
- data/spec/lib/pickle_adapter_spec.rb +164 -0
- data/spec/lib/pickle_config_spec.rb +97 -0
- data/spec/lib/pickle_email_parser_spec.rb +49 -0
- data/spec/lib/pickle_email_spec.rb +131 -0
- data/spec/lib/pickle_parser_matchers_spec.rb +70 -0
- data/spec/lib/pickle_parser_spec.rb +154 -0
- data/spec/lib/pickle_path_spec.rb +77 -0
- data/spec/lib/pickle_session_spec.rb +337 -0
- data/spec/lib/pickle_spec.rb +24 -0
- metadata +94 -0
@@ -0,0 +1,337 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
2
|
+
|
3
|
+
describe Pickle::Session do
|
4
|
+
include Pickle::Session
|
5
|
+
|
6
|
+
describe "Pickle::Session proxy missing methods to parser", :shared => true do
|
7
|
+
it "should forward to pickle_parser it responds_to them" do
|
8
|
+
@it.pickle_parser.should_receive(:parse_model)
|
9
|
+
@it.parse_model
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise error if pickle_parser don't know about em" do
|
13
|
+
lambda { @it.parse_infinity }.should raise_error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "including Pickle::Session" do
|
18
|
+
before do
|
19
|
+
@it = self
|
20
|
+
end
|
21
|
+
|
22
|
+
it_should_behave_like "Pickle::Session proxy missing methods to parser"
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "extending Pickle::Session" do
|
26
|
+
before do
|
27
|
+
@it = Object.new
|
28
|
+
@it.extend Pickle::Session
|
29
|
+
end
|
30
|
+
|
31
|
+
it_should_behave_like "Pickle::Session proxy missing methods to parser"
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "after storing a single user", :shared => true do
|
35
|
+
it "created_models('user') should be array containing the original user" do
|
36
|
+
created_models('user').should == [@user]
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "the original user should be retrievable with" do
|
40
|
+
it "created_model('the user')" do
|
41
|
+
created_model('the user').should == @user
|
42
|
+
end
|
43
|
+
|
44
|
+
it "created_model('1st user')" do
|
45
|
+
created_model('1st user').should == @user
|
46
|
+
end
|
47
|
+
|
48
|
+
it "created_model('last user')" do
|
49
|
+
created_model('last user').should == @user
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "(found from db)" do
|
54
|
+
before do
|
55
|
+
@user.stub!(:id).and_return(100)
|
56
|
+
@user.class.should_receive(:find).with(100).and_return(@user_from_db = @user.dup)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "models('user') should be array containing user" do
|
60
|
+
models('user').should == [@user_from_db]
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "user should be retrievable with" do
|
64
|
+
it "model('the user')" do
|
65
|
+
model('the user').should == @user_from_db
|
66
|
+
end
|
67
|
+
|
68
|
+
it "model('1st user')" do
|
69
|
+
model('1st user').should == @user_from_db
|
70
|
+
end
|
71
|
+
|
72
|
+
it "model('last user')" do
|
73
|
+
model('last user').should == @user_from_db
|
74
|
+
end
|
75
|
+
|
76
|
+
it "model!('last user')" do
|
77
|
+
model('last user').should == @user_from_db
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#create_model" do
|
84
|
+
before do
|
85
|
+
@user = mock_model(User)
|
86
|
+
Factory.stub!(:create).and_return(@user)
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "('a user')" do
|
90
|
+
def do_create_model
|
91
|
+
create_model('a user')
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should call Factory.create('user', {})" do
|
95
|
+
Factory.should_receive(:create).with('user', {}).and_return(@user)
|
96
|
+
do_create_model
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "after create," do
|
100
|
+
before { do_create_model }
|
101
|
+
|
102
|
+
it_should_behave_like "after storing a single user"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "('1 user', 'foo: \"bar\", baz: \"bing bong\"')" do
|
107
|
+
def do_create_model
|
108
|
+
create_model('1 user', 'foo: "bar", baz: "bing bong"')
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should call Factory.create('user', {'foo' => 'bar', 'baz' => 'bing bong'})" do
|
112
|
+
Factory.should_receive(:create).with('user', {'foo' => 'bar', 'baz' => 'bing bong'}).and_return(@user)
|
113
|
+
do_create_model
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "after create," do
|
117
|
+
before { do_create_model }
|
118
|
+
|
119
|
+
it_should_behave_like "after storing a single user"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "('an user: \"fred\")" do
|
124
|
+
def do_create_model
|
125
|
+
create_model('an user: "fred"')
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should call Factory.create('user', {})" do
|
129
|
+
Factory.should_receive(:create).with('user', {}).and_return(@user)
|
130
|
+
do_create_model
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "after create," do
|
134
|
+
before { do_create_model }
|
135
|
+
|
136
|
+
it_should_behave_like "after storing a single user"
|
137
|
+
|
138
|
+
it "created_model('the user: \"fred\"') should retrieve the user" do
|
139
|
+
created_model('the user: "fred"').should == @user
|
140
|
+
end
|
141
|
+
|
142
|
+
it "created_model?('the user: \"shirl\"') should be false" do
|
143
|
+
created_model?('the user: "shirl"').should == false
|
144
|
+
end
|
145
|
+
|
146
|
+
it "model?('the user: \"shirl\"') should be false" do
|
147
|
+
model?('the user: "shirl"').should == false
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe '#find_model' do
|
154
|
+
before do
|
155
|
+
@user = mock_model(User)
|
156
|
+
User.stub!(:find).and_return(@user)
|
157
|
+
end
|
158
|
+
|
159
|
+
def do_find_model
|
160
|
+
find_model('a user', 'hair: "pink"')
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should call User.find :first, :conditions => {'hair' => 'pink'}" do
|
164
|
+
User.should_receive(:find).with(:first, :conditions => {'hair' => 'pink'}).and_return(@user)
|
165
|
+
do_find_model
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "after find," do
|
169
|
+
before { do_find_model }
|
170
|
+
|
171
|
+
it_should_behave_like "after storing a single user"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "#find_models" do
|
176
|
+
before do
|
177
|
+
@user = mock_model(User)
|
178
|
+
User.stub!(:find).and_return([@user])
|
179
|
+
end
|
180
|
+
|
181
|
+
def do_find_models
|
182
|
+
find_models('user', 'hair: "pink"')
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should call User.find :all, :conditions => {'hair' => 'pink'}" do
|
186
|
+
User.should_receive(:find).with(:all, :conditions => {'hair' => 'pink'}).and_return([@user])
|
187
|
+
do_find_models
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "after find," do
|
191
|
+
before { do_find_models }
|
192
|
+
|
193
|
+
it_should_behave_like "after storing a single user"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe 'creating \'a super admin: "fred"\', then \'a user: "shirl"\', \'then 1 super_admin\'' do
|
198
|
+
before do
|
199
|
+
@user = @fred = mock_model(User)
|
200
|
+
@shirl = mock_model(User)
|
201
|
+
@noname = mock_model(User)
|
202
|
+
Factory.stub!(:create).and_return(@fred, @shirl, @noname)
|
203
|
+
end
|
204
|
+
|
205
|
+
def do_create_users
|
206
|
+
create_model('a super admin: "fred"')
|
207
|
+
create_model('a user: "shirl"')
|
208
|
+
create_model('1 super_admin')
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should call Factory.create with <'super_admin'>, <'user'>, <'super_admin'>" do
|
212
|
+
Factory.should_receive(:create).with('super_admin', {}).twice
|
213
|
+
Factory.should_receive(:create).with('user', {}).once
|
214
|
+
do_create_users
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "after create," do
|
218
|
+
before do
|
219
|
+
do_create_users
|
220
|
+
end
|
221
|
+
|
222
|
+
it "created_models('user') should == [@fred, @shirl, @noname]" do
|
223
|
+
created_models('user').should == [@fred, @shirl, @noname]
|
224
|
+
end
|
225
|
+
|
226
|
+
it "created_models('super_admin') should == [@fred, @noname]" do
|
227
|
+
created_models('super_admin').should == [@fred, @noname]
|
228
|
+
end
|
229
|
+
|
230
|
+
describe "#created_model" do
|
231
|
+
it "'that user' should be @noname (the last user created - as super_admins are users)" do
|
232
|
+
created_model('that user').should == @noname
|
233
|
+
end
|
234
|
+
|
235
|
+
it "'the super admin' should be @noname (the last super admin created)" do
|
236
|
+
created_model('that super admin').should == @noname
|
237
|
+
end
|
238
|
+
|
239
|
+
it "'the 1st super admin' should be @fred" do
|
240
|
+
created_model('the 1st super admin').should == @fred
|
241
|
+
end
|
242
|
+
|
243
|
+
it "'the first user' should be @fred" do
|
244
|
+
created_model('the first user').should == @fred
|
245
|
+
end
|
246
|
+
|
247
|
+
it "'the 2nd user' should be @shirl" do
|
248
|
+
created_model('the 2nd user').should == @shirl
|
249
|
+
end
|
250
|
+
|
251
|
+
it "'the last user' should be @noname" do
|
252
|
+
created_model('the last user').should == @noname
|
253
|
+
end
|
254
|
+
|
255
|
+
it "'the user: \"fred\" should be @fred" do
|
256
|
+
created_model('the user: "fred"').should == @fred
|
257
|
+
end
|
258
|
+
|
259
|
+
it "'the user: \"shirl\" should be @shirl" do
|
260
|
+
created_model('the user: "shirl"').should == @shirl
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
describe "when 'the user: \"me\"' exists and there is a mapping from 'I', 'myself' => 'user: \"me\"" do
|
267
|
+
before do
|
268
|
+
@user = mock_model(User)
|
269
|
+
User.stub!(:find).and_return(@user)
|
270
|
+
Factory.stub!(:create).and_return(@user)
|
271
|
+
self.pickle_parser = Pickle::Parser.new(:config => Pickle::Config.new {|c| c.map 'I', 'myself', :to => 'user: "me"'})
|
272
|
+
create_model('the user: "me"')
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'model("I") should return the user' do
|
276
|
+
model('I').should == @user
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'model("myself") should return the user' do
|
280
|
+
model('myself').should == @user
|
281
|
+
end
|
282
|
+
|
283
|
+
it "#parser.parse_fields 'author: user \"JIM\"' should raise Error, as model deos not refer" do
|
284
|
+
lambda { pickle_parser.parse_fields('author: user "JIM"') }.should raise_error
|
285
|
+
end
|
286
|
+
|
287
|
+
it "#parser.parse_fields 'author: the user' should return {\"author\" => <user>}" do
|
288
|
+
pickle_parser.parse_fields('author: the user').should == {"author" => @user}
|
289
|
+
end
|
290
|
+
|
291
|
+
it "#parser.parse_fields 'author: myself' should return {\"author\" => <user>}" do
|
292
|
+
pickle_parser.parse_fields('author: myself').should == {"author" => @user}
|
293
|
+
end
|
294
|
+
|
295
|
+
it "#parser.parse_fields 'author: the user, approver: I, rating: \"5\"' should return {'author' => <user>, 'approver' => <user>, 'rating' => '5'}" do
|
296
|
+
pickle_parser.parse_fields('author: the user, approver: I, rating: "5"').should == {'author' => @user, 'approver' => @user, 'rating' => '5'}
|
297
|
+
end
|
298
|
+
|
299
|
+
it "#parser.parse_fields 'author: user: \"me\", approver: \"\"' should return {'author' => <user>, 'approver' => \"\"}" do
|
300
|
+
pickle_parser.parse_fields('author: user: "me", approver: ""').should == {'author' => @user, 'approver' => ""}
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
describe "convert_models_to_attributes(ar_class, :user => <a user>)" do
|
305
|
+
before do
|
306
|
+
@user = mock_model(User)
|
307
|
+
end
|
308
|
+
|
309
|
+
describe "(when ar_class has column 'user_id')" do
|
310
|
+
before do
|
311
|
+
@ar_class = mock('ActiveRecord', :column_names => ['user_id'])
|
312
|
+
end
|
313
|
+
|
314
|
+
it "should return {'user_id' => <the user.id>}" do
|
315
|
+
convert_models_to_attributes(@ar_class, :user => @user).should == {'user_id' => @user.id}
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
describe "(when ar_class has columns 'user_id', 'user_type')" do
|
320
|
+
before do
|
321
|
+
@ar_class = mock('ActiveRecord', :column_names => ['user_id', 'user_type'])
|
322
|
+
end
|
323
|
+
|
324
|
+
it "should return {'user_id' => <the user.id>, 'user_type' => <the user.type>}" do
|
325
|
+
convert_models_to_attributes(@ar_class, :user => @user).should == {'user_id' => @user.id, 'user_type' => @user.class.name}
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
it "#model!('unknown') should raise informative error message" do
|
331
|
+
lambda { model!('unknown') }.should raise_error("Can't find pickle model: 'unknown' in this scenario")
|
332
|
+
end
|
333
|
+
|
334
|
+
it "#created_model!('unknown') should raise informative error message" do
|
335
|
+
lambda { created_model!('unknown') }.should raise_error("Can't find pickle model: 'unknown' in this scenario")
|
336
|
+
end
|
337
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
2
|
+
|
3
|
+
describe Pickle do
|
4
|
+
it ".config should be same object on multiple calls" do
|
5
|
+
Pickle.config.should == Pickle.config
|
6
|
+
end
|
7
|
+
|
8
|
+
it ".configure should configure the .config object" do
|
9
|
+
Pickle.config.should_receive(:foo).with(:bar)
|
10
|
+
Pickle.configure do |c|
|
11
|
+
c.foo :bar
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it ".parser should create a parser with the default config" do
|
16
|
+
Pickle.instance_variable_set('@parser', nil)
|
17
|
+
Pickle::Parser.should_receive(:new).with(:config => Pickle.config)
|
18
|
+
Pickle.parser
|
19
|
+
end
|
20
|
+
|
21
|
+
it ".parser should be same object on multiple calls" do
|
22
|
+
Pickle.parser.should == Pickle.parser
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mrflip-pickle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.13
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ian White
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-16 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Easy model creation and reference in your cucumber features
|
17
|
+
email: ian.w.white@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/pickle/adapter.rb
|
26
|
+
- lib/pickle/config.rb
|
27
|
+
- lib/pickle/email/parser.rb
|
28
|
+
- lib/pickle/email/world.rb
|
29
|
+
- lib/pickle/email.rb
|
30
|
+
- lib/pickle/parser/matchers.rb
|
31
|
+
- lib/pickle/parser.rb
|
32
|
+
- lib/pickle/path/world.rb
|
33
|
+
- lib/pickle/path.rb
|
34
|
+
- lib/pickle/session/parser.rb
|
35
|
+
- lib/pickle/session.rb
|
36
|
+
- lib/pickle/version.rb
|
37
|
+
- lib/pickle/world.rb
|
38
|
+
- lib/pickle.rb
|
39
|
+
- rails_generators/pickle/pickle_generator.rb
|
40
|
+
- rails_generators/pickle/templates/email_steps.rb
|
41
|
+
- rails_generators/pickle/templates/env.rb
|
42
|
+
- rails_generators/pickle/templates/paths.rb
|
43
|
+
- rails_generators/pickle/templates/pickle_steps.rb
|
44
|
+
- License.txt
|
45
|
+
- README.rdoc
|
46
|
+
- Todo.txt
|
47
|
+
- History.txt
|
48
|
+
- spec/lib/pickle_adapter_spec.rb
|
49
|
+
- spec/lib/pickle_config_spec.rb
|
50
|
+
- spec/lib/pickle_email_parser_spec.rb
|
51
|
+
- spec/lib/pickle_email_spec.rb
|
52
|
+
- spec/lib/pickle_parser_matchers_spec.rb
|
53
|
+
- spec/lib/pickle_parser_spec.rb
|
54
|
+
- spec/lib/pickle_path_spec.rb
|
55
|
+
- spec/lib/pickle_session_spec.rb
|
56
|
+
- spec/lib/pickle_spec.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://github.com/ianwhite/pickle/tree
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --title
|
62
|
+
- Pickle
|
63
|
+
- --line-numbers
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.2.0
|
82
|
+
signing_key:
|
83
|
+
specification_version: 2
|
84
|
+
summary: Easy model creation and reference in your cucumber features
|
85
|
+
test_files:
|
86
|
+
- spec/lib/pickle_adapter_spec.rb
|
87
|
+
- spec/lib/pickle_config_spec.rb
|
88
|
+
- spec/lib/pickle_email_parser_spec.rb
|
89
|
+
- spec/lib/pickle_email_spec.rb
|
90
|
+
- spec/lib/pickle_parser_matchers_spec.rb
|
91
|
+
- spec/lib/pickle_parser_spec.rb
|
92
|
+
- spec/lib/pickle_path_spec.rb
|
93
|
+
- spec/lib/pickle_session_spec.rb
|
94
|
+
- spec/lib/pickle_spec.rb
|