mdoel-cukesteps 0.2.0 → 0.3.0
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 +85 -6
- data/VERSION +1 -1
- data/cukesteps.gemspec +1 -2
- data/lib/common_steps.rb +33 -19
- data/lib/cuke_association_helpers.rb +9 -2
- metadata +1 -2
- data/pkg/cukesteps-0.1.0.gem +0 -0
data/README.rdoc
CHANGED
@@ -4,17 +4,96 @@ cukesteps is a gem containing general purpose step definitions for the Cucumber
|
|
4
4
|
|
5
5
|
Cucumber provides a single webrat_steps.rb file containing generic steps. This gem provides more.
|
6
6
|
|
7
|
-
|
7
|
+
The steps fall into three basic categories:
|
8
|
+
- object creation steps
|
9
|
+
- general debugging/development steps
|
10
|
+
- content matching steps
|
8
11
|
|
9
|
-
|
12
|
+
= Object creation step(s)
|
13
|
+
Right now, there's just one and it is of the form:
|
10
14
|
|
11
|
-
|
15
|
+
Given the following foo(s) exist
|
12
16
|
|
13
|
-
|
17
|
+
This is expected to be used with a step table and allows for complex associations to be built up
|
18
|
+
in concise language. Consider an application with models for restaurant, brand, employee, and
|
19
|
+
location. You might want to create a test world like:
|
20
|
+
|
21
|
+
Given the following employees exist
|
22
|
+
| employee | name |
|
23
|
+
| first | joe |
|
24
|
+
| second | sally |
|
25
|
+
| third | william |
|
26
|
+
Given the following restaurants exist
|
27
|
+
| Location | Brand | Employees |
|
28
|
+
| Miami, fl | McDonalds | first |
|
29
|
+
| Columbus | Chipotle | second,third |
|
30
|
+
|
31
|
+
If you put the following in your features/support/env.rb file:
|
32
|
+
|
33
|
+
cuke_association_builders(:brand => :build_associated_via_find_by_name,
|
34
|
+
:location => :from_factory)
|
35
|
+
|
36
|
+
then each Restaurant object gets created and associated with three other model objects:
|
37
|
+
- Brand - via a find_by_name lookup inside the brands table
|
38
|
+
- Location - via the return of the Location#from_factory class method
|
39
|
+
- Employee - from the objects created in the previous step
|
40
|
+
|
41
|
+
Note that in the above, :build_associated_via_find_by_name is the only "magic" value to associate with
|
42
|
+
a model/table column.
|
43
|
+
|
44
|
+
= General Debugging/Development steps
|
45
|
+
These steps are not typically ones you would leave inside your cucumber features file as they are
|
46
|
+
primarily useful if you are trying to debug some issue rather than doing true acceptance testing.
|
47
|
+
|
48
|
+
== Then I debug
|
49
|
+
Use this in the middle of a scenario to stop running the scenario and dump you into the ruby debugger
|
50
|
+
at this point.
|
51
|
+
|
52
|
+
== Then save_and_open_page
|
53
|
+
This uses webrats save_and_open_page method to capture the output of your scenario at some point and open it
|
54
|
+
in your browser.
|
55
|
+
|
56
|
+
== Then n foos should exist
|
57
|
+
Verifies that the count of Foo records is n
|
14
58
|
|
15
|
-
|
16
|
-
|
59
|
+
== Then dump all foos to standard output
|
60
|
+
Dumps the output of inspect for all ActiveRecord instances of Foo
|
61
|
+
|
62
|
+
= Content Matching Steps
|
63
|
+
These steps help encourage use of semantic IDs and Class Names in your markup. The use of the
|
64
|
+
articles "a" and "the" represent a class and ID respectively. For example, "I should see a photo
|
65
|
+
in the search results" ensures that the the page contains an element of class photo inside an element of ID
|
66
|
+
search-results.
|
67
|
+
|
68
|
+
The steps available here are:
|
69
|
+
- Then I should see the foo
|
70
|
+
- Then I should see a|an foo
|
71
|
+
- Then I should see a foo in the bar
|
72
|
+
- Then I should see the foo in the bar
|
73
|
+
- Then I should see n foos in the bar
|
74
|
+
- Then I should see n to m foos in the bar
|
75
|
+
- Then the baz in the bar should contain a foo
|
76
|
+
|
77
|
+
The negation of each of the above is also available (e.g. Then I should not see a foo in the bar)
|
78
|
+
|
79
|
+
= Installation/Use
|
80
|
+
To install the gem, use:
|
81
|
+
|
82
|
+
gem sources add github.com (only need to do this once)
|
83
|
+
gem install mikedoel-cukesteps
|
84
|
+
|
85
|
+
To use it, add the following to your features/support/env.rb file:
|
86
|
+
|
87
|
+
require 'mdoel-cukesteps'
|
88
|
+
include CukeAssociationhelpers
|
89
|
+
cuke_association_builders(:model1 => :class_method_1,
|
90
|
+
:model2 => :build_associated_via_find_by_name)
|
91
|
+
|
92
|
+
|
93
|
+
= To Do
|
17
94
|
|
95
|
+
- incorporate better testing (right now, testing is in a separate cukesteps-test project)
|
96
|
+
- make this documentation better
|
18
97
|
|
19
98
|
== Copyright
|
20
99
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/cukesteps.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{cukesteps}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.3.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Mike Doel"]
|
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
"lib/common_steps.rb",
|
24
24
|
"lib/cuke_association_helpers.rb",
|
25
25
|
"lib/cukesteps.rb",
|
26
|
-
"pkg/cukesteps-0.1.0.gem",
|
27
26
|
"test/cukesteps_test.rb",
|
28
27
|
"test/test_helper.rb"
|
29
28
|
]
|
data/lib/common_steps.rb
CHANGED
@@ -10,41 +10,55 @@ Then /^I wait for ([0-9]+) seconds$/ do |delay|
|
|
10
10
|
sleep delay.to_i
|
11
11
|
end
|
12
12
|
|
13
|
+
Then /^(\d+) (\S+) should exist$/ do |count, element_class|
|
14
|
+
klass = element_class.singularize.capitalize.constantize
|
15
|
+
klass.count.should eql(count.to_i)
|
16
|
+
end
|
17
|
+
|
18
|
+
Then /^dump all (\S+) to standard output$/ do |klass|
|
19
|
+
klass_name = klass.singularize.capitalize.constantize
|
20
|
+
records = klass_name.send(:find, :all)
|
21
|
+
records.each { |record| puts record.inspect }
|
22
|
+
end
|
23
|
+
|
24
|
+
|
13
25
|
# Steps that are generally useful and help encourage use of semantic
|
14
26
|
# IDs and Class Names in your markup. In the steps below, a match following
|
15
27
|
# "the" will verify the presences of an element with a given ID while a match following
|
16
28
|
# "a" or "an" will verify the presence an element of a given class.
|
17
|
-
Then /^I should
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
Then /^I should see the (\S+) in the (\S+)$/ do |element, containing_element|
|
22
|
-
response.should have_tag("##{containing_element} ##{element}")
|
29
|
+
Then /^I should( not)? see the (\S+)$/ do |negation, element_id|
|
30
|
+
matcher = negation.blank? ? :should : :should_not
|
31
|
+
response.send matcher, have_tag("##{element_id}")
|
23
32
|
end
|
24
33
|
|
25
|
-
Then /^I should
|
26
|
-
|
34
|
+
Then /^I should( not)? see an? (\S+)$/ do |negation, element_class|
|
35
|
+
matcher = negation.blank? ? :should : :should_not
|
36
|
+
response.send matcher, have_tag(".#{element_class}")
|
27
37
|
end
|
28
38
|
|
29
|
-
Then /^I should
|
30
|
-
|
39
|
+
Then /^I should( not)? see an? (\S+) in the (\S+)$/ do |negation, element, containing_element|
|
40
|
+
matcher = negation.blank? ? :should : :should_not
|
41
|
+
response.send matcher, have_tag("##{containing_element} .#{element}")
|
31
42
|
end
|
32
43
|
|
33
|
-
Then /^
|
34
|
-
|
44
|
+
Then /^I should( not)? see the (\S+) in the (\S+)$/ do |negation, element, containing_element|
|
45
|
+
matcher = negation.blank? ? :should : :should_not
|
46
|
+
response.send matcher, have_tag("##{containing_element} ##{element}")
|
35
47
|
end
|
36
48
|
|
37
|
-
Then /^I should see the (\S+)$/ do |
|
38
|
-
|
49
|
+
Then /^I should( not)? see (\d+) (\S+) in the (\S+)$/ do |negation, count, element, containing_element|
|
50
|
+
matcher = negation.blank? ? :should : :should_not
|
51
|
+
response.send matcher, have_tag("##{containing_element} .#{element.singularize}",:count => count.to_i)
|
39
52
|
end
|
40
53
|
|
41
|
-
Then /^I should see (
|
42
|
-
|
54
|
+
Then /^I should( not)? see (\d+) to (\d+) (\S+) in the (\S+)$/ do |negation, min, max, element, containing_element|
|
55
|
+
matcher = negation.blank? ? :should : :should_not
|
56
|
+
response.send matcher, have_tag("##{containing_element} .#{element.singularize}",min.to_i..max.to_i)
|
43
57
|
end
|
44
58
|
|
45
|
-
Then /^(\
|
46
|
-
|
47
|
-
|
59
|
+
Then /^the (\S+) in the (\S+) should( not)? contain an? (\S+)$/ do |middle_element, outer_element, negation, inner_element|
|
60
|
+
matcher = negation.blank? ? :should : :should_not
|
61
|
+
response.send matcher, have_tag("##{outer_element} ##{middle_element} .#{inner_element}")
|
48
62
|
end
|
49
63
|
|
50
64
|
# Steps for creating objects that can be associated with other objects
|
@@ -35,16 +35,23 @@ module CukeAssociationHelpers
|
|
35
35
|
def assemble_attributes(hash,object_name)
|
36
36
|
attributes = {}
|
37
37
|
hash.each do |key,value|
|
38
|
+
cached_key = key.singularize.downcase
|
38
39
|
symbolized_key = key.downcase.gsub(' ','_').to_sym
|
39
|
-
if @created_objects[
|
40
|
+
if @created_objects[cached_key].nil?
|
40
41
|
attributes[symbolized_key] = build_value(symbolized_key,value)
|
41
42
|
else
|
42
|
-
attributes[symbolized_key] =
|
43
|
+
attributes[symbolized_key] = saved_objects(cached_key,value)
|
43
44
|
end
|
44
45
|
end
|
45
46
|
attributes
|
46
47
|
end
|
47
48
|
|
49
|
+
def saved_objects(klass,value)
|
50
|
+
objects = []
|
51
|
+
value.split(",").each {|o| objects << @created_objects[klass][o]}
|
52
|
+
objects
|
53
|
+
end
|
54
|
+
|
48
55
|
def build_value(key,value)
|
49
56
|
if @@associated_cuke_builders[key].nil?
|
50
57
|
value
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdoel-cukesteps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Doel
|
@@ -32,7 +32,6 @@ files:
|
|
32
32
|
- lib/common_steps.rb
|
33
33
|
- lib/cuke_association_helpers.rb
|
34
34
|
- lib/cukesteps.rb
|
35
|
-
- pkg/cukesteps-0.1.0.gem
|
36
35
|
- test/cukesteps_test.rb
|
37
36
|
- test/test_helper.rb
|
38
37
|
has_rdoc: false
|
data/pkg/cukesteps-0.1.0.gem
DELETED
Binary file
|