Byclosure-common_steps 0.0.1 → 0.0.2
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/README.rdoc +1 -0
- data/Rakefile +23 -1
- data/VERSION +1 -1
- data/common_steps.gemspec +22 -8
- data/features/step_definitions/common_steps_steps.rb +12 -0
- data/features/support/env.rb +0 -1
- data/lib/common_steps/helpers/conditions.treetop +113 -0
- data/lib/common_steps/helpers/conditions_parser.rb +25 -0
- data/lib/common_steps/helpers/rake_helper.rb +5 -0
- data/lib/common_steps/helpers/record_helper.rb +51 -9
- data/lib/common_steps/helpers.rb +7 -1
- data/lib/common_steps/step_definitions/navigation_steps.rb +3 -0
- data/lib/common_steps/step_definitions/record_steps.rb +23 -7
- data/lib/common_steps/step_definitions/webrat_steps.rb +2 -1
- data/lib/common_steps/support/spec.rb +2 -10
- data/lib/common_steps/tasks/cucumber.rake +1 -1
- data/lib/common_steps.rb +1 -1
- data/spec/common_steps/common_steps_spec.rb +255 -4
- data/spec/common_steps/helpers/conditions_parser_spec.rb +288 -0
- data/spec/common_steps/helpers/record_helper_spec.rb +133 -0
- data/spec/common_steps_helper.rb +29 -0
- data/spec/spec.opts +2 -1
- data/spec/spec_helper.rb +98 -1
- data/tasks/rspec.rake +1 -0
- metadata +36 -8
- data/lib/common_steps/support/env.rb +0 -24
- data/tasks/jeweler.rake +0 -52
@@ -1,7 +1,258 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../common_steps_helper')
|
3
|
+
require "common_steps/helpers/record_helper"
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
module StepMotherHelper
|
6
|
+
def step_should_match(step_string)
|
7
|
+
it { @step_mother.should step_match(step_string) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def artist_should_count(n, step_string)
|
11
|
+
plural_or_singular = n == 1 ? "" : "s"
|
12
|
+
it "should count #{n} Artist#{plural_or_singular} when I call '#{step_string}'" do
|
13
|
+
m = @step_mother.step_match(step_string)
|
14
|
+
m.invoke(nil)
|
15
|
+
Artist.should count(n)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def artist_should_be(hash, step_string)
|
20
|
+
it "should contain #{hash.inspect} when I call '#{step_string}'" do
|
21
|
+
m = @step_mother.step_match(step_string)
|
22
|
+
m.invoke(nil)
|
23
|
+
Artist.should exist_given(hash)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def artist_should_count_and_be(n, hash, step_string)
|
28
|
+
artist_should_count(n, step_string)
|
29
|
+
artist_should_be(hash, step_string)
|
30
|
+
end
|
31
|
+
|
32
|
+
def artists_in_table_should_be(table, step_string)
|
33
|
+
it "should contain the table #{table.hashes.inspect} when I call '#{step_string}" do
|
34
|
+
m = @step_mother.step_match('the following artists')
|
35
|
+
m.invoke(table)
|
36
|
+
table.hashes.each do |hash|
|
37
|
+
Artist.should exist_given(hash)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# In order to use features without bugs
|
44
|
+
# As a developer
|
45
|
+
# I want to test my applications using record steps beginning with Given
|
46
|
+
describe "Cucumber instance with record_steps.rb and World(RecordHelper) loaded" do
|
47
|
+
extend StepMotherHelper
|
48
|
+
|
49
|
+
before do
|
50
|
+
@step_mother = Cucumber::Cli::Main.step_mother
|
51
|
+
@step_mother.load_code_file(File.expand_path(File.dirname(__FILE__) + "/../../lib/common_steps/step_definitions/record_steps.rb"))
|
52
|
+
@dsl = Object.new
|
53
|
+
@dsl.extend(Cucumber::RbSupport::RbDsl)
|
54
|
+
@dsl.World(RecordHelper)
|
55
|
+
@step_mother.load_programming_language('rb').begin_rb_scenario
|
56
|
+
end
|
57
|
+
|
58
|
+
# Specs from record_steps.rb
|
59
|
+
#
|
60
|
+
# there (is|are) (\w+) (\w*)
|
61
|
+
step_should_match 'there are no artists'
|
62
|
+
step_should_match 'there is no artists'
|
63
|
+
step_should_match 'there are no artist'
|
64
|
+
step_should_match 'there is 0 artists'
|
65
|
+
step_should_match 'there is a artist'
|
66
|
+
step_should_match 'there is an artist'
|
67
|
+
step_should_match 'there is 1 artist'
|
68
|
+
step_should_match 'there are 3 artists'
|
69
|
+
|
70
|
+
# there (is|are) (\w+) (\w+) with a (.*)
|
71
|
+
step_should_match 'there are 0 artists with a name of "John"'
|
72
|
+
step_should_match 'there are no artists with a name of "John"'
|
73
|
+
step_should_match 'there is 1 artist with a name of "John"'
|
74
|
+
step_should_match 'there is an artist with a name of "John"'
|
75
|
+
step_should_match 'there is a artist with a name of "John"'
|
76
|
+
step_should_match 'there are 3 artists with a name of "John"'
|
77
|
+
step_should_match 'there are 1 artists with a name of "John", an age of 32 and a country of "Portugal"'
|
78
|
+
|
79
|
+
# there should be (\w+) (\w+)
|
80
|
+
step_should_match 'there should be no artists'
|
81
|
+
step_should_match 'there should be no artists'
|
82
|
+
step_should_match 'there should be no artist'
|
83
|
+
step_should_match 'there should be 0 artists'
|
84
|
+
step_should_match 'there should be a artist'
|
85
|
+
step_should_match 'there should be an artist'
|
86
|
+
step_should_match 'there should be 1 artist'
|
87
|
+
step_should_match 'there should be 3 artists'
|
88
|
+
|
89
|
+
#the following (\w+):
|
90
|
+
step_should_match 'the following artists'
|
91
|
+
step_should_match 'the following artists:'
|
92
|
+
step_should_match 'the following artist'
|
93
|
+
step_should_match 'the following artist:'
|
94
|
+
|
95
|
+
# there should be (\w+) (\w+) with a (.*)
|
96
|
+
step_should_match 'there should be 0 artists with a name of "John"'
|
97
|
+
step_should_match 'there should be no artists with a name of "John"'
|
98
|
+
step_should_match 'there should be 1 artist with a name of "John"'
|
99
|
+
step_should_match 'there should be an artist with a name of "John"'
|
100
|
+
step_should_match 'there should be a artist with a name of "John"'
|
101
|
+
step_should_match 'there should be 3 artists with a name of "John"'
|
102
|
+
step_should_match 'there should be 1 artist with a name of "John", an age of 32 and a country of "Portugal"'
|
103
|
+
|
104
|
+
# there should be the following (\w+):?
|
105
|
+
step_should_match 'there should be the following artists'
|
106
|
+
step_should_match 'there should be the following artists:'
|
107
|
+
step_should_match 'there should be the following artist'
|
108
|
+
step_should_match 'there should be the following artist:'
|
109
|
+
|
110
|
+
# I should see the following (\w+) in order
|
111
|
+
step_should_match 'I should see the following artists in order'
|
112
|
+
step_should_match 'I should see the following artist in order'
|
113
|
+
|
114
|
+
describe "StepMatch[there (is|are) (\w+) (\w+) with a (.*)] invocation, with no artists" do
|
115
|
+
before do
|
116
|
+
Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
|
117
|
+
end
|
118
|
+
|
119
|
+
artist_should_count(0, 'there are 0 artists with a name of "John"')
|
120
|
+
artist_should_count(0, 'there are no artists with a name of "John"')
|
121
|
+
|
122
|
+
artist_should_count_and_be(1, {:name => "John"}, 'there is 1 artist with a name of "John"')
|
123
|
+
artist_should_count_and_be(1, {:name => "John"}, 'there is an artist with a name of "John"')
|
124
|
+
artist_should_count_and_be(1, {:name => "John"}, 'there is a artist with a name of "John"')
|
125
|
+
artist_should_count_and_be(3, {:name => "John"}, 'there are 3 artists with a name of "John"')
|
126
|
+
artist_should_count_and_be(1, {:name => "John", :age => 32}, 'there are 1 artists with a name of "John", and age of 32')
|
127
|
+
|
128
|
+
# To discuss later
|
129
|
+
#artist_should_count_and_be(1, {:name => "John", :age => 32}, 'there are 1 artists with a name of "John", and age of 32')
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "StepMatch[there (is|are) (\w+) (.*)] invocation, with no artists" do
|
133
|
+
before do
|
134
|
+
Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
|
135
|
+
end
|
136
|
+
|
137
|
+
artist_should_count 0, 'there are 0 artists'
|
138
|
+
artist_should_count 0, 'there are no artists'
|
139
|
+
artist_should_count 1, 'there is 1 artist'
|
140
|
+
artist_should_count 1, 'there is an artist'
|
141
|
+
artist_should_count 1, 'there is a artist'
|
142
|
+
artist_should_count 3, 'there are 3 artists'
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "StepMatch[there should be (\w+) (\w+)] invocation with 1 artist, with no artists" do
|
146
|
+
before do
|
147
|
+
Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
|
148
|
+
end
|
149
|
+
|
150
|
+
artist_should_count 0, 'there should be 0 artists'
|
151
|
+
artist_should_count 0, 'there should be no artists'
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "StepMatch[there should be (\w+) (\w+)] invocation with 1 artist, with 1 artist" do
|
155
|
+
before do
|
156
|
+
Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
|
157
|
+
Factory(:artist)
|
158
|
+
end
|
159
|
+
|
160
|
+
artist_should_count 1, 'there should be 1 artist'
|
161
|
+
artist_should_count 1, 'there should be an artist'
|
162
|
+
artist_should_count 1, 'there should be a artist'
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "StepMatch[Given the following artists] invoked with table of attributes" do
|
166
|
+
before do
|
167
|
+
Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
|
168
|
+
end
|
169
|
+
|
170
|
+
@cucumber_table = Cucumber::Ast::Table.new(
|
171
|
+
[['name', 'age'],
|
172
|
+
['John', '12'],
|
173
|
+
['Mary', '34']])
|
174
|
+
artists_in_table_should_be @cucumber_table, 'the following artists'
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "StepMatch[there should be (\w+) (\w+) with a (.*)] with no artists" do
|
178
|
+
before do
|
179
|
+
Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
|
180
|
+
end
|
181
|
+
|
182
|
+
artist_should_count(0, 'there should be 0 artists with a name of "John"')
|
183
|
+
artist_should_count(0, 'there should be no artists with a name of "John"')
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "StepMatch[there should be (\w+) (\w+) with a (.*)] with 1 artist" do
|
187
|
+
before do
|
188
|
+
Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
|
189
|
+
Artist.create!(:name => "John", :age => 32)
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should not raise error when I invoke StepMatch[there should be 1 artist with a name of 'John']" do
|
193
|
+
lambda do
|
194
|
+
m = @step_mother.step_match('there should be 1 artist with a name of "John"')
|
195
|
+
m.invoke(nil)
|
196
|
+
end.should_not raise_error
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should not raise error when I invoke StepMatch['there should be an artist with a name of \"John\"']" do
|
200
|
+
lambda do
|
201
|
+
m = @step_mother.step_match('there should be an artist with a name of "John"')
|
202
|
+
m.invoke(nil)
|
203
|
+
end.should_not raise_error
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should not raise error when I invoke StepMatch[''there should be a artist with a name of \"John\"'']" do
|
207
|
+
lambda do
|
208
|
+
m = @step_mother.step_match('there should be a artist with a name of "John"')
|
209
|
+
m.invoke(nil)
|
210
|
+
end.should_not raise_error
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should not raise error when I invoke StepMatch['there should be 1 artists with a name of \"John\", and age of 32']" do
|
214
|
+
lambda do
|
215
|
+
m = @step_mother.step_match('there should be 1 artists with a name of "John", and age of 32')
|
216
|
+
m.invoke(nil)
|
217
|
+
end.should_not raise_error
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "where there are 2 artists [{:name => 'John', :age => 12}, {:name => 'Mary', :age => 34}]" do
|
222
|
+
before do
|
223
|
+
Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
|
224
|
+
Artist.create!(:name => "John", :age => 12)
|
225
|
+
Artist.create!(:name => "Mary", :age => 34)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should not raise error when I invoke StepMatch[there should be the following (\w+):?] with [{:name => 'John', :age => 12}, {:name => 'Mary', :age => 34}]" do
|
229
|
+
lambda do
|
230
|
+
m = @step_mother.step_match("there should be the following artists")
|
231
|
+
m.invoke(Cucumber::Ast::Table.new(
|
232
|
+
[['name', 'age'],
|
233
|
+
['John', '12'],
|
234
|
+
['Mary', '34']]))
|
235
|
+
end.should_not raise_error
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should raise error when I invoke StepMatch[there should be the following (\w+):?] with [{:name => 'Ann', :age => 12}]" do
|
239
|
+
lambda do
|
240
|
+
m = @step_mother.step_match("there should be the following artists")
|
241
|
+
m.invoke(Cucumber::Ast::Table.new(
|
242
|
+
[['name', 'age'],
|
243
|
+
['Ann', '12']]))
|
244
|
+
end.should raise_error
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should raise error when I invoke StepMatch[there should be the following (\w+):?] with [{:name => 'John', :age => 12}, {:name => 'Mary', :age => 34}, {:name => 'Andrea', :age => 22}]" do
|
248
|
+
lambda do
|
249
|
+
m = @step_mother.step_match("there should be the following artists")
|
250
|
+
m.invoke(Cucumber::Ast::Table.new(
|
251
|
+
[['name', 'age'],
|
252
|
+
['John', '12'],
|
253
|
+
['Mary', '34'],
|
254
|
+
['Andrea', '22']]))
|
255
|
+
end.should raise_error
|
256
|
+
end
|
6
257
|
end
|
7
258
|
end
|
@@ -0,0 +1,288 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
2
|
+
require "common_steps/helpers/conditions_parser"
|
3
|
+
|
4
|
+
module ParserHelper
|
5
|
+
module InputHelper
|
6
|
+
def should_be_instance_of(klass)
|
7
|
+
it { @parse_tree.should be_instance_of(klass) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def should_be_a(klass)
|
11
|
+
it { @parse_tree.should be_a(klass) }
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method :instance_of, :should_be_instance_of
|
15
|
+
alias_method :be_a, :should_be_a
|
16
|
+
|
17
|
+
def conditions_should_be(*conditions)
|
18
|
+
it "conditions should be of type: #{conditions.inspect}" do
|
19
|
+
@parse_tree.splited_conditions.map(&:class).should == conditions
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def conditions_hash_should_be(hash)
|
24
|
+
it "conditions hash should be #{hash.inspect}" do
|
25
|
+
@parse_tree.conditions_hash.should == hash
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
alias_method :conditions_hash, :conditions_hash_should_be
|
30
|
+
end
|
31
|
+
|
32
|
+
def should_parse(input, &block)
|
33
|
+
it { @conditions_parser.should treetop_parse(input) }
|
34
|
+
describe_input input, &block if block_given?
|
35
|
+
end
|
36
|
+
|
37
|
+
def should_not_parse(input)
|
38
|
+
it { @conditions_parser.should_not treetop_parse(input) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def describe_input(input, &block)
|
42
|
+
describe "with input `#{input}'" do
|
43
|
+
extend InputHelper
|
44
|
+
before do
|
45
|
+
@parse_tree = @conditions_parser.parse input
|
46
|
+
end
|
47
|
+
instance_eval(&block)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "ConditionsParser" do
|
53
|
+
extend ParserHelper
|
54
|
+
include TreetopParserMatchers
|
55
|
+
|
56
|
+
before do
|
57
|
+
@conditions_parser = ConditionsParser.new
|
58
|
+
end
|
59
|
+
|
60
|
+
# of separators
|
61
|
+
should_parse "word of 'foo'" do
|
62
|
+
instance_of(OfCondition)
|
63
|
+
conditions_hash 'word' => 'foo'
|
64
|
+
end
|
65
|
+
should_parse "word of 'foo'" do
|
66
|
+
instance_of(OfCondition)
|
67
|
+
conditions_hash 'word' => 'foo'
|
68
|
+
end
|
69
|
+
should_parse "two words of 'foo'" do
|
70
|
+
instance_of(OfCondition)
|
71
|
+
conditions_hash 'two words' => 'foo'
|
72
|
+
end
|
73
|
+
should_parse "of of 'foo'" do
|
74
|
+
instance_of(OfCondition)
|
75
|
+
conditions_hash 'of' => 'foo'
|
76
|
+
end
|
77
|
+
should_parse "word of of 'foo'" do
|
78
|
+
instance_of(OfCondition)
|
79
|
+
conditions_hash 'word of' => 'foo'
|
80
|
+
end
|
81
|
+
should_parse "two of words of 'foo'" do
|
82
|
+
instance_of(OfCondition)
|
83
|
+
conditions_hash 'two of words' => 'foo'
|
84
|
+
end
|
85
|
+
should_parse "of word of 'foo'" do
|
86
|
+
instance_of(OfCondition)
|
87
|
+
conditions_hash 'of word' => 'foo'
|
88
|
+
end
|
89
|
+
should_parse "of word of 'foo'" do
|
90
|
+
instance_of(OfCondition)
|
91
|
+
conditions_hash 'of word' => 'foo'
|
92
|
+
end
|
93
|
+
should_parse "belonging to of 'boo'" do
|
94
|
+
instance_of(OfCondition)
|
95
|
+
conditions_hash 'belonging to' => 'boo'
|
96
|
+
end
|
97
|
+
should_parse "belonging to of 'boo'" do
|
98
|
+
instance_of(OfCondition)
|
99
|
+
conditions_hash 'belonging to' => 'boo'
|
100
|
+
end
|
101
|
+
should_parse "something belonging to of 'boo'" do
|
102
|
+
instance_of(OfCondition)
|
103
|
+
conditions_hash 'something belonging to' => 'boo'
|
104
|
+
end
|
105
|
+
should_parse "something belonging to someone of 'boo'" do
|
106
|
+
instance_of(OfCondition)
|
107
|
+
conditions_hash 'something belonging to someone' => 'boo'
|
108
|
+
end
|
109
|
+
should_parse "belonging to someone of 'boo'" do
|
110
|
+
instance_of(OfCondition)
|
111
|
+
conditions_hash 'belonging to someone' => 'boo'
|
112
|
+
end
|
113
|
+
should_parse "belonging to someone with of 'boo'" do
|
114
|
+
instance_of(OfCondition)
|
115
|
+
conditions_hash 'belonging to somenone with' => 'boo'
|
116
|
+
end
|
117
|
+
should_parse "belonging to someone with name of 'boo'" do
|
118
|
+
instance_of(OfCondition)
|
119
|
+
conditions_hash 'belonging to someone with name' => 'boo'
|
120
|
+
end
|
121
|
+
should_parse "belonging to someone with a of 'boo'" do
|
122
|
+
instance_of(OfCondition)
|
123
|
+
conditions_hash 'belonging to someone with a' => 'boo'
|
124
|
+
end
|
125
|
+
should_parse "belonging to someone with an of 'boo'" do
|
126
|
+
instance_of(OfCondition)
|
127
|
+
conditions_hash 'belonging to someone with an' => 'boo'
|
128
|
+
end
|
129
|
+
should_not_parse "separatorof'foo'"
|
130
|
+
should_not_parse "of 'foo'"
|
131
|
+
|
132
|
+
# => separator
|
133
|
+
should_parse "word => 'foo'" do
|
134
|
+
instance_of(ArrowCondition)
|
135
|
+
conditions_hash 'word' => 'foo'
|
136
|
+
end
|
137
|
+
should_parse "word => 'foo'" do
|
138
|
+
instance_of(ArrowCondition)
|
139
|
+
conditions_hash 'word' => 'foo'
|
140
|
+
end
|
141
|
+
should_parse "word=>'foo'" do
|
142
|
+
instance_of(ArrowCondition)
|
143
|
+
conditions_hash 'word' => 'foo'
|
144
|
+
end
|
145
|
+
should_parse "word of => 'foo'" do
|
146
|
+
instance_of(ArrowCondition)
|
147
|
+
conditions_hash "word of" => 'foo'
|
148
|
+
end
|
149
|
+
# should_parse "belonging to foo => ''"
|
150
|
+
should_parse "belonging to => 'boo'" do
|
151
|
+
instance_of(ArrowCondition)
|
152
|
+
conditions_hash "belonging to" => 'boo'
|
153
|
+
end
|
154
|
+
should_parse "belonging to => 'boo'" do
|
155
|
+
instance_of(ArrowCondition)
|
156
|
+
conditions_hash "belonging to" => 'boo'
|
157
|
+
end
|
158
|
+
should_parse "word of => 'foo'" do
|
159
|
+
instance_of(ArrowCondition)
|
160
|
+
conditions_hash 'word of' => 'foo'
|
161
|
+
end
|
162
|
+
|
163
|
+
# values
|
164
|
+
should_parse "string => 'foo'" do
|
165
|
+
instance_of(ArrowCondition)
|
166
|
+
conditions_hash 'string' => 'foo'
|
167
|
+
end
|
168
|
+
should_parse 'string => "foo"' do
|
169
|
+
instance_of(ArrowCondition)
|
170
|
+
conditions_hash 'string' => 'foo'
|
171
|
+
end
|
172
|
+
# should_parse "string => 'f\\'o\\'o'" future
|
173
|
+
# should_parse 'string => "f\\"o\\"o"' future
|
174
|
+
should_parse "integer => 23" do
|
175
|
+
instance_of(ArrowCondition)
|
176
|
+
conditions_hash 'integer' => 23
|
177
|
+
end
|
178
|
+
should_parse "float => 23.000" do
|
179
|
+
instance_of(ArrowCondition)
|
180
|
+
conditions_hash 'float' => 23.0
|
181
|
+
end
|
182
|
+
should_parse "float => .5" do
|
183
|
+
instance_of(ArrowCondition)
|
184
|
+
conditions_hash 'float' => 0.5
|
185
|
+
end
|
186
|
+
should_parse "boolean => true" do
|
187
|
+
instance_of(ArrowCondition)
|
188
|
+
conditions_hash 'boolean' => true
|
189
|
+
end
|
190
|
+
should_parse "boolean => false" do
|
191
|
+
instance_of(ArrowCondition)
|
192
|
+
conditions_hash 'boolean' => false
|
193
|
+
end
|
194
|
+
should_parse "symbol => :foo" do
|
195
|
+
instance_of(ArrowCondition)
|
196
|
+
conditions_hash 'symbol' => :foo
|
197
|
+
end
|
198
|
+
should_parse "null => nil" do
|
199
|
+
instance_of(ArrowCondition)
|
200
|
+
conditions_hash "null" => nil
|
201
|
+
end
|
202
|
+
should_parse "two words => 'foo'" do
|
203
|
+
instance_of(ArrowCondition)
|
204
|
+
conditions_hash 'two words' => 'foo'
|
205
|
+
end
|
206
|
+
should_parse "two words => 'foo'" do
|
207
|
+
instance_of(ArrowCondition)
|
208
|
+
conditions_hash 'two words' => 'foo'
|
209
|
+
end
|
210
|
+
should_parse "one_word => 'foo'" do
|
211
|
+
instance_of(ArrowCondition)
|
212
|
+
conditions_hash 'one_word' => 'foo'
|
213
|
+
end
|
214
|
+
|
215
|
+
should_not_parse "bar => foo" # future meth (or #meth)
|
216
|
+
should_not_parse "date => Date.today" # future
|
217
|
+
|
218
|
+
|
219
|
+
should_parse "name of 'boo' and age of 23" do
|
220
|
+
be_a(SplitConditions)
|
221
|
+
conditions_should_be OfCondition, OfCondition
|
222
|
+
conditions_hash 'name' => 'boo', 'age' => 23
|
223
|
+
end
|
224
|
+
should_parse "name of 'boo', age => 23, internal => true" do
|
225
|
+
be_a(SplitConditions)
|
226
|
+
conditions_should_be OfCondition, ArrowCondition, ArrowCondition
|
227
|
+
conditions_hash 'name' => 'boo', 'age' => 23, 'internal' => true
|
228
|
+
end
|
229
|
+
should_parse "name => 'boo', age of 23, and internal of true" do
|
230
|
+
be_a(SplitConditions)
|
231
|
+
conditions_should_be ArrowCondition, OfCondition, OfCondition
|
232
|
+
conditions_hash 'name' => 'boo', 'age' => 23, 'internal' => true
|
233
|
+
end
|
234
|
+
should_parse "name => 'boo', age of 23 and internal of true" do
|
235
|
+
be_a(SplitConditions)
|
236
|
+
conditions_should_be ArrowCondition, OfCondition, OfCondition
|
237
|
+
conditions_hash 'name' => 'boo', 'age' => 23, 'internal' => true
|
238
|
+
end
|
239
|
+
should_parse "name => 'boo', age => 23.0 , and internal => true" do
|
240
|
+
be_a(SplitConditions)
|
241
|
+
conditions_should_be ArrowCondition, ArrowCondition, ArrowCondition
|
242
|
+
conditions_hash 'name' => 'boo', 'age' => 23.0, 'internal' => true
|
243
|
+
end
|
244
|
+
|
245
|
+
should_parse "belonging to artist with a name of 'boo'" do
|
246
|
+
instance_of(BelongingToCondition)
|
247
|
+
conditions_hash 'artist' => {'name' => 'boo'}
|
248
|
+
end
|
249
|
+
=begin
|
250
|
+
should_parse "belonging to magnific artist with a name of 'boo'" do
|
251
|
+
instance_of(BelongingToCondition)
|
252
|
+
conditions_hash 'magnific artist' => {'name' => 'boo'}
|
253
|
+
end
|
254
|
+
should_parse "belonging to artist with a name of 'boo', and age of 23" do
|
255
|
+
instance_of(BelongingToCondition)
|
256
|
+
conditions_hash 'artist' => {'name' => 'boo', 'age' => 23}
|
257
|
+
end
|
258
|
+
should_parse "belonging to artist with a name of 'boo'; and age of 50" do
|
259
|
+
be_a(SplitConditions)
|
260
|
+
conditions_should_be BelongingToCondition, OfCondition
|
261
|
+
conditions_hash 'artist' => {'name' => 'boo', 'age' => 50}
|
262
|
+
end
|
263
|
+
should_parse "belonging to artist with with a name of 'boo'; and age of 50" do
|
264
|
+
be_a(SplitConditions)
|
265
|
+
conditions_should_be BelongingToCondition, OfCondition
|
266
|
+
conditions_hash 'artist' => {'name' => 'boo'}, 'age' => 50
|
267
|
+
end
|
268
|
+
should_parse "belonging to with artist with a name of 'boo'; and age of 50" do
|
269
|
+
be_a(SplitConditions)
|
270
|
+
conditions_should_be BelongingToCondition, OfCondition
|
271
|
+
conditions_hash 'with artist' => {'name' => 'boo'}, 'age' => 50
|
272
|
+
end
|
273
|
+
should_parse "age of 50, belonging to artist with a name of 'foo'" do
|
274
|
+
be_a(SplitConditions)
|
275
|
+
conditions_should_be OfCondition, BelongingToCondition, OfCondition
|
276
|
+
conditions_hash 'age' => 50, 'artist' => {'name' => 'foo'}
|
277
|
+
end
|
278
|
+
should_not_parse "belonging to artist"
|
279
|
+
should_not_parse "belonging to artist with a"
|
280
|
+
=end
|
281
|
+
=begin
|
282
|
+
it do
|
283
|
+
p = @conditions_parser.parse("string => 'foo'")
|
284
|
+
debugger
|
285
|
+
nil
|
286
|
+
end
|
287
|
+
=end
|
288
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
2
|
+
require "common_steps/helpers/record_helper"
|
3
|
+
|
4
|
+
class Artist; end
|
5
|
+
class MagnificArtist; end
|
6
|
+
module Admin
|
7
|
+
class Painting; end
|
8
|
+
end
|
9
|
+
describe RecordHelper, "with Artist, MagnificArtist, ::Admin::Painting defined" do
|
10
|
+
before do
|
11
|
+
@env = Object.new
|
12
|
+
@env.extend(RecordHelper)
|
13
|
+
end
|
14
|
+
|
15
|
+
it { @env.should respond_to(:recordize!) }
|
16
|
+
|
17
|
+
it { @env.should respond_to(:record_singular_name) }
|
18
|
+
it "#record_singular_name('aRtIsTs') should == 'artist'" do
|
19
|
+
@env.record_singular_name('aRtIsTs').should == 'artist'
|
20
|
+
end
|
21
|
+
it "#record_singular_name('ArTiSt') should == 'artist'" do
|
22
|
+
@env.record_singular_name('ArTiSt').should == 'artist'
|
23
|
+
end
|
24
|
+
it "#record_singular_name('ReCiPe iNgReDiEnTs') should == 'recipe ingredient'" do
|
25
|
+
@env.record_singular_name('ReCiPe iNgReDiEnTs').should == 'recipe ingredient'
|
26
|
+
end
|
27
|
+
|
28
|
+
it { @env.should respond_to(:record_name_to_class) }
|
29
|
+
it "#record_name_to_class('ArTiSt') should == Artist" do
|
30
|
+
@env.record_name_to_class('ArTiSt').should == Artist
|
31
|
+
end
|
32
|
+
it "#record_name_to_class('aRtIsTs') should == Artist" do
|
33
|
+
@env.record_name_to_class('aRtIsTs').should == Artist
|
34
|
+
end
|
35
|
+
it "#record_name_to_class('magnific artist') should == MagnificArtist" do
|
36
|
+
@env.record_name_to_class('magnific artist').should == MagnificArtist
|
37
|
+
end
|
38
|
+
it "#record_name_to_class('magnific artists') should == MagnificArtist" do
|
39
|
+
@env.record_name_to_class('magnific artists').should == MagnificArtist
|
40
|
+
end
|
41
|
+
|
42
|
+
it { @env.should respond_to(:str_to_num) }
|
43
|
+
it "#str_to_num('a') should == 1" do
|
44
|
+
@env.str_to_num('a').should == 1
|
45
|
+
end
|
46
|
+
it "#str_to_num('an') should == 1" do
|
47
|
+
@env.str_to_num('an').should == 1
|
48
|
+
end
|
49
|
+
it "#str_to_num('no') should == 0" do
|
50
|
+
@env.str_to_num('no').should == 0
|
51
|
+
end
|
52
|
+
it "#str_to_num(something_else) should hit something_else with #to_i" do
|
53
|
+
something_else = mock("something_else")
|
54
|
+
something_else.should_receive(:to_i).once.with(no_args)
|
55
|
+
@env.str_to_num(something_else)
|
56
|
+
end
|
57
|
+
|
58
|
+
it { @env.should respond_to(:conditions_from_str) }
|
59
|
+
it "#conditions_from_str(\"name of 'foo'\") should == {'name' => 'foo'}" do
|
60
|
+
@env.conditions_from_str("name of 'foo'").should == {"name" => "foo"}
|
61
|
+
end
|
62
|
+
it "#conditions_from_str(\"name => 'foo'\") should == {'name' => 'foo'}" do
|
63
|
+
@env.conditions_from_str("name => 'foo'").should == {"name" => "foo"}
|
64
|
+
end
|
65
|
+
it "#conditions_from_str(\"age of 23\") should == {'age' => 23}" do
|
66
|
+
@env.conditions_from_str("age of 23").should == {"age" => 23}
|
67
|
+
end
|
68
|
+
it "#conditions_from_str(\"age => 23\") should == {'age' => 23}" do
|
69
|
+
@env.conditions_from_str("age => 23").should == {"age" => 23}
|
70
|
+
end
|
71
|
+
it "#conditions_from_str(\"lame of true\") should == {'lame' => true}" do
|
72
|
+
@env.conditions_from_str("lame of true").should == {"lame" => true}
|
73
|
+
end
|
74
|
+
it "#conditions_from_str(\"lame => true\")" do
|
75
|
+
@env.conditions_from_str("lame => true").should == {"lame" => true}
|
76
|
+
end
|
77
|
+
it "#conditions_from_str(\"full name => meth\"), with #meth defined and returning 'bar', should == {'full_name'=>'bar'}" do
|
78
|
+
@env.should_receive(:meth).and_return('bar')
|
79
|
+
@env.conditions_from_str("full name => meth").should == {"full_name" => 'bar'}
|
80
|
+
end
|
81
|
+
it "#conditions_from_str(\"full_name of meth\"), with #meth defined and returning 'bar', should == {'full_name'=>'bar'}" do
|
82
|
+
@env.should_receive(:meth).and_return('bar')
|
83
|
+
@env.conditions_from_str("full_name of meth").should == {"full_name" => 'bar'}
|
84
|
+
end
|
85
|
+
it "#conditions_from_str(\"date => Date.today\") should == {'date' => #{Date.today}}" do
|
86
|
+
@env.conditions_from_str("date => Date.today").should == {"date" => Date.today}
|
87
|
+
end
|
88
|
+
it "#conditions_from_str(\"date of Date.today\") should == {'date' => #{Date.today}}" do
|
89
|
+
@env.conditions_from_str("date => Date.today").should == {"date" => Date.today}
|
90
|
+
end
|
91
|
+
|
92
|
+
it "#conditions_from_str(\"name of 'boo' and age of 23\") should == {'name' => 'boo', 'age' => 23}" do
|
93
|
+
@env.conditions_from_str("name of 'boo' and age of 23").should == {"name" => "boo", "age" => 23}
|
94
|
+
end
|
95
|
+
it "#conditions_from_str(\"name of 'boo', age => 23, internal => true\") should == {'name' => 'boo', 'age' => 23, 'internal' => true}" do
|
96
|
+
@env.conditions_from_str("name of 'boo', age => 23, internal => true").should == {"name" => "boo", "age" => 23, "internal" => true}
|
97
|
+
end
|
98
|
+
it "#conditions_from_str(\"name => 'boo', age of 23, and internal of true\") should == {'name' => 'boo', 'age' => 23, 'internal' => true}" do
|
99
|
+
@env.conditions_from_str("name => 'boo', age of 23, and internal of true").should == {"name" => "boo", "age" => 23, "internal" => true}
|
100
|
+
end
|
101
|
+
it "#conditions_from_str(\"name => meth, age of 23, and internal of true\"), with #meth defined and returning 'bar', should == {'name'=>'bar','age'=>23,'internal'=>true}" do
|
102
|
+
@env.should_receive(:meth).and_return('bar')
|
103
|
+
@env.conditions_from_str("name => meth, age of 23, and internal of true").should == {"name"=>"bar", "age"=>23, "internal"=>true}
|
104
|
+
end
|
105
|
+
|
106
|
+
it { @env.should respond_to(:find_record) }
|
107
|
+
describe "find_record(Artist, \"'name of 'Foo', internal => true\")" do
|
108
|
+
it "should hit Artist with #find(:all, :conditions => {'name' => 'Foo', internal => true}) and return mock('artist')" do
|
109
|
+
artist = mock("artist")
|
110
|
+
Artist.should_receive(:find).with(:first, :conditions => {'name' => 'Foo', "internal" => true}).and_return(artist)
|
111
|
+
@env.find_record(Artist, "name of 'Foo', internal => true")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
describe "when Artist.find(:first, :conditions => {'name' => 'Bar'}) return nil find_record(Artist, \"name => 'Bar'\") should raise error" do
|
115
|
+
it do
|
116
|
+
Artist.should_receive(:find).with(:first, :conditions => {'name' => 'Bar'}).and_return(nil)
|
117
|
+
lambda do
|
118
|
+
@env.find_record(Artist, "name => 'Bar'")
|
119
|
+
end.should raise_error("Couldn't found any record for `Artist' with conditions: `{\"name\"=>\"Bar\"}'")
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it { @env.should respond_to(:record_class_to_path) }
|
124
|
+
it "#record_class_to_path(Artist) should == '/artists'" do
|
125
|
+
@env.record_class_to_path(Artist).should == '/artists'
|
126
|
+
end
|
127
|
+
it "#record_class_to_path(MagnificArtist) should == '/magnific_artist'" do
|
128
|
+
@env.record_class_to_path(MagnificArtist).should == '/magnific_artists'
|
129
|
+
end
|
130
|
+
it "#record_class_to_path(::Admin::Painting) should == '/admin/paintings'" do
|
131
|
+
@env.record_class_to_path(::Admin::Painting).should == '/admin/paintings'
|
132
|
+
end
|
133
|
+
end
|