Byclosure-common_steps 0.0.2 → 0.0.3

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/common_steps.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{common_steps}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Vasco Andrade e Silva", "Duarte Henriques"]
12
- s.date = %q{2009-09-15}
12
+ s.date = %q{2009-09-23}
13
13
  s.description = %q{common_steps. Some common cucumber step definitions, rake tasks, and rspec matchers}
14
14
  s.email = ["vasco@byclosure.com", "duarte@byclosure.com"]
15
15
  s.extra_rdoc_files = [
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "lib/common_steps/helpers.rb",
31
31
  "lib/common_steps/helpers/conditions.treetop",
32
32
  "lib/common_steps/helpers/conditions_parser.rb",
33
+ "lib/common_steps/helpers/navigation_helper.rb",
33
34
  "lib/common_steps/helpers/rake_helper.rb",
34
35
  "lib/common_steps/helpers/record_helper.rb",
35
36
  "lib/common_steps/matchers/count.rb",
@@ -42,9 +43,11 @@ Gem::Specification.new do |s|
42
43
  "lib/common_steps/support/spec.rb",
43
44
  "lib/common_steps/tasks/cucumber.rake",
44
45
  "lib/common_steps/tasks/rspec.rake",
45
- "spec/common_steps/common_steps_spec.rb",
46
46
  "spec/common_steps/helpers/conditions_parser_spec.rb",
47
47
  "spec/common_steps/helpers/record_helper_spec.rb",
48
+ "spec/common_steps/helpers/step_mother_helper.rb",
49
+ "spec/common_steps/navigation_steps_spec.rb",
50
+ "spec/common_steps/record_steps_spec.rb",
48
51
  "spec/common_steps_helper.rb",
49
52
  "spec/spec.opts",
50
53
  "spec/spec_helper.rb",
@@ -53,23 +56,24 @@ Gem::Specification.new do |s|
53
56
  "tasks/roodi.rake",
54
57
  "tasks/rspec.rake"
55
58
  ]
56
- s.has_rdoc = true
57
59
  s.homepage = %q{http://github.com/Byclosure/common_steps}
58
60
  s.rdoc_options = ["--charset=UTF-8"]
59
61
  s.require_paths = ["lib"]
60
- s.rubygems_version = %q{1.3.1}
62
+ s.rubygems_version = %q{1.3.5}
61
63
  s.summary = %q{common_steps. Some common cucumber step definitions, rake tasks, and rspec matchers}
62
64
  s.test_files = [
63
- "spec/spec_helper.rb",
64
- "spec/common_steps_helper.rb",
65
+ "spec/common_steps/helpers/conditions_parser_spec.rb",
65
66
  "spec/common_steps/helpers/record_helper_spec.rb",
66
- "spec/common_steps/helpers/conditions_parser_spec.rb",
67
- "spec/common_steps/common_steps_spec.rb"
67
+ "spec/common_steps/helpers/step_mother_helper.rb",
68
+ "spec/common_steps/navigation_steps_spec.rb",
69
+ "spec/common_steps/record_steps_spec.rb",
70
+ "spec/common_steps_helper.rb",
71
+ "spec/spec_helper.rb"
68
72
  ]
69
73
 
70
74
  if s.respond_to? :specification_version then
71
75
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
72
- s.specification_version = 2
76
+ s.specification_version = 3
73
77
 
74
78
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
75
79
  s.add_development_dependency(%q<rspec>, [">= 0"])
@@ -1,8 +1,8 @@
1
- require "activesupport"
1
+ require 'activesupport'
2
2
 
3
3
  common_step_mods = []
4
4
 
5
- Dir[File.dirname(__FILE__) + "/helpers/*.rb"].each do |filename|
5
+ Dir[File.dirname(__FILE__) + "/helpers/*_helper.rb"].each do |filename|
6
6
  require filename
7
7
  module_name = filename.chomp(".rb").classify.demodulize
8
8
  mod = module_name.constantize rescue warn("unable to load: module `#{module_name}' in file #{filename}")
@@ -10,4 +10,3 @@ Dir[File.dirname(__FILE__) + "/helpers/*.rb"].each do |filename|
10
10
  end
11
11
 
12
12
  Cucumber::RbSupport::RbDsl.build_rb_world_factory(common_step_mods, nil)
13
-
@@ -0,0 +1,4 @@
1
+ module NavigationHelper
2
+ # def visit_homepage
3
+ # end
4
+ end
@@ -1,6 +1,6 @@
1
1
  module RecordHelper
2
2
  def record_singular_name(record_name)
3
- record_name.gsub('_', ' ').downcase.singularize
3
+ record_name.gsub(' ', '_').downcase.singularize
4
4
  end
5
5
 
6
6
  def record_name_to_class(record_name)
@@ -89,7 +89,6 @@ module RecordHelper
89
89
  # base[attr_from_name(class_record, attr_name)] = value_from_str(value_str)
90
90
  # base
91
91
  # end
92
-
93
92
  conds.inject({}) {|base, (attr, value_str)| base[attr] = instance_eval(value_str); base}
94
93
  end
95
94
 
@@ -1,3 +1,3 @@
1
1
  Dir[File.dirname(__FILE__) + "/step_definitions/*.rb"].each do |filename|
2
2
  require filename
3
- end
3
+ end
@@ -4,40 +4,42 @@ end
4
4
 
5
5
  When /^I go to "([^\"]*)"$/ do |page_name|
6
6
  visit page_name
7
+ @can_follow_url = page_name
8
+ @can_take_screeshot = true
7
9
  end
8
10
 
9
11
  When /^I go to the homepage$/ do
10
- When 'I go to "/"'
12
+ visit_homepage
11
13
  end
12
14
 
13
- Given /^I am on the new (\w+) page$/ do |record_name|
15
+ Given /^I am on the new (.+) page$/ do |record_name|
14
16
  When "I go to the new #{record_name} page"
15
17
  end
16
18
 
17
- When /^I go to the new (\w+) page$/ do |record_name|
19
+ When /^I go to the new (.+) page$/ do |record_name|
18
20
  record_class = record_name_to_class(record_name)
19
- When "I go to \"/#{record_class_to_path(record_class)}/new\""
21
+ When "I go to \"#{record_class_to_path(record_class)}/new\""
20
22
  end
21
23
 
22
- When /^I go to the list page of (\w+)$/ do |record_name|
23
- path = record_name.pluralize # TODO refact
24
+ When /^I go to the list page of (.+)$/ do |record_name|
25
+ path = record_name.pluralize # TODO refact record_class_to_path(record_class)
24
26
  When "I go to \"/#{path}\""
25
27
  end
26
28
 
27
- Given /^I am on the edit page of the (\w+) with (a|an) (.*)$/ do |record_name, _, record_conditions|
29
+ Given /^I am on the edit page of the (.+) with (a|an) (.*)$/ do |record_name, _, record_conditions|
28
30
  When "I go to the edit page of the #{record_name} with a #{record_conditions}"
29
31
  end
30
32
 
31
- When /^I go to the edit page of the (\w+) with (a|an) (.*)$/ do |record_name, _, record_conditions|
33
+ When /^I go to the edit page of the (.+) with (a|an) (.*)$/ do |record_name, _, record_conditions|
32
34
  record_class = record_name_to_class(record_name)
33
35
  record = find_record(record_class, record_conditions)
34
- When "I go to \"/#{record_class_to_path(record_class)}/#{record.id}/edit\""
36
+ When "I go to \"#{record_class_to_path(record_class)}/#{record.id}/edit\""
35
37
  end
36
38
 
37
- When /^I go to the show page of the (\w+) with (a|an) (.*)$/ do |record_name, _, record_conditions|
39
+ When /^I go to the show page of the (.+) with (a|an) (.*)$/ do |record_name, _, record_conditions|
38
40
  record_class = record_name_to_class(record_name)
39
41
  record = find_record(record_class, record_conditions)
40
- When "I go to \"/#{record_class_to_path(record_class)}/#{record.id}\""
42
+ When "I go to \"#{record_class_to_path(record_class)}/#{record.id}\""
41
43
  end
42
44
 
43
45
  #When /^I go to the delete page of (\w+) with (.*)$/ do |record_name|
@@ -48,20 +50,36 @@ Then /^I should be on "([^\"]*)"$/ do |page_name|
48
50
  URI.parse(current_url).path.should == page_name
49
51
  end
50
52
 
51
- Then /^I should be on the show page of the (\w+) with (a|an) (.*)$/ do |record_name, _,record_conditions|
53
+ Then /^I should be on the show page of the (.+) with (a|an) (.*)$/ do |record_name, _,record_conditions|
52
54
  record_class = record_name_to_class(record_name)
53
55
  record = find_record(record_class, record_conditions)
54
- path = "/#{record_class_to_path(record_class)}/#{record.id}"
56
+ path = "#{record_class_to_path(record_class)}/#{record.id}"
55
57
  URI.parse(current_url).path.should match(/#{path}/)
56
58
  end
57
59
 
58
- Then /^I should be on the edit page of the (\w+) with (a|an) (.*)$/ do |record_name, _,record_conditions|
60
+ Then /^I should be on the edit page of the (.+) with (a|an) (.*)$/ do |record_name, _,record_conditions|
59
61
  record_class = record_name_to_class(record_name)
60
62
  record = find_record(record_class, record_conditions)
61
- path = "/#{record_class_to_path(record_class)}/#{record.id}"
63
+ path = "#{record_class_to_path(record_class)}/#{record.id}"
64
+ URI.parse(current_url).path.should match(/#{path}/)
65
+ end
66
+
67
+ Then /^I should be on the "(.+)" create page$/ do |record_name|
68
+ record_class = record_name_to_class(record_name)
69
+ path = "#{record_class_to_path(record_class)}/new"
62
70
  URI.parse(current_url).path.should match(/#{path}/)
63
71
  end
64
72
 
65
73
  Then /the field with label "([^\"]*)" should contain "([^\"]*)"/ do |field_name, content|
66
74
  field_labeled(field_name).value.should == content
67
75
  end
76
+
77
+ # webrat steps
78
+
79
+ #When /^I press "([^\"]*)"$/ do |button|
80
+ # click_button(button)
81
+ #end
82
+
83
+ #Then /^I should see "([^\"]*)"$/ do |text|
84
+ # response.should contain(text)
85
+ #end
@@ -1,44 +1,43 @@
1
- Given /^there (is|are) (\w+) (\w+) with a (.*)$/ do |_, count_str, record_name, record_conditions|
1
+ Given /^there (is|are) (\w+) (.*) with (a|an) (.*)$/ do |_, count_str, record_name, _, record_conditions|
2
2
  singular_record_name = record_singular_name(record_name)
3
3
  conditions = conditions_from_str(record_conditions)
4
- record_name_to_class(record_name).delete_all
4
+ # record_name_to_class(record_name).delete_all
5
5
  num = str_to_num(count_str)
6
- num.times { Factory(singular_record_name, conditions) }
6
+ num.times { Factory(singular_record_name.gsub(/\s/, "_"), conditions) }
7
7
  end
8
8
 
9
- Given /^there (is|are) (\w+) (\w*)$/ do |_, count_str, record_name|
9
+ Given /^there (is|are) (\w+) (\w+)$/ do |_, count_str, record_name|
10
10
  singular_record_name = record_singular_name(record_name)
11
11
  num = str_to_num(count_str)
12
- num.times { Factory(singular_record_name) }
13
- end
14
-
15
- Then /^there should be (\w+) (\w+)$/ do |count_str, record_name|
16
- num = str_to_num(count_str)
17
- record_name_to_class(record_name).should count(num)
12
+ num.times { Factory(singular_record_name.gsub(/\s/, "_")) }
18
13
  end
19
14
 
20
15
  Given /^the following (\w+):?$/ do |record_name, table|
21
16
  recordize!(record_name, table)
22
17
  singular_record_name = record_singular_name(record_name)
23
18
  table.hashes.each do |hash|
24
- Factory(singular_record_name, hash)
19
+ Factory(singular_record_name.gsub(/\s/, "_"), hash)
25
20
  end
26
21
  end
27
22
 
28
- Then /^there should be (\w+) (\w+) with a (.*)$/ do |count_str, record_name, record_conditions|
29
- class_name = record_name_to_class(record_name)
30
- conditions = conditions_from_str(record_conditions)
23
+ Then /^there should be (\d+) (.+)$/ do |count_str, record_name|
31
24
  num = str_to_num(count_str)
32
- class_name.count(:conditions => conditions).should == num
25
+ record_name_to_class(record_name).should count(num)
33
26
  end
34
27
 
35
- Then /^there should be the following (\w+):?$/ do |record_name, table|
28
+ Then /^there should be the following (.+):?$/ do |record_name, table|
36
29
  recordize!(record_name, table)
37
30
  class_name = record_name_to_class(record_name)
38
31
  table.hashes.each do |hash|
39
32
  class_name.exists?(hash).should == true # TODO vasco: make a matcher for this
40
33
  end
41
34
  end
35
+ Then /^there should be (\w+) (\w+) with a (.*)$/ do |count_str, record_name, record_conditions|
36
+ class_name = record_name_to_class(record_name)
37
+ conditions = conditions_from_str(record_conditions)
38
+ num = str_to_num(count_str)
39
+ class_name.count(:conditions => conditions).should == num
40
+ end
42
41
 
43
42
  Then /^I should see the following (\w+) in order$/ do |record_name, table|
44
43
  class_name = record_name_to_class(record_name)
@@ -48,132 +47,4 @@ Then /^I should see the following (\w+) in order$/ do |record_name, table|
48
47
  actual_table << [record.name]
49
48
  end
50
49
  table.diff!(actual_table)
51
- end
52
-
53
-
54
- =begin
55
- class_name = model_name.gsub(' ', '_').singularize
56
- model_class = nil
57
- begin
58
- model_class = class_name.classify.constantize
59
- rescue
60
- # do nothing
61
- end
62
- model_class.delete_all if model_class
63
- table.hashes.each do |hash|
64
- attr_hash = hash.inject({}) do |attr_hash, (attr_name, attr_value)|
65
- if attr_name == 'user' && !attr_value.is_a?(User) # hack
66
- attr_hash[attr_name] = find_or_create_valid_user(:login => attr_value)
67
- elsif attr_name == "published_at" && hash['published_as'] == "draft" # hack
68
- attr_hash[attr_name] = nil
69
- elsif (model_class && (association = model_class.reflect_on_all_associations(:has_many).detect { |a| attr_name =~ /^(#{a.name})(_.*)/ }))
70
- find_suffix = $2
71
- attr_hash[association.name] = if attr_value.nil?
72
- []
73
- else
74
- association_class = association.class_name.constantize
75
- attr_value.split(", ").map do |v|
76
- association_class.send("find_by#{find_suffix}", v)
77
- end
78
- end
79
- else
80
- attr_hash[attr_name] = attr_value
81
- end
82
- attr_hash
83
- end
84
-
85
- approve = attr_hash.delete("approve")
86
- model = Factory(class_name.to_sym, attr_hash)
87
- if approve == "true"
88
- model.approve!
89
- end
90
- model
91
- end
92
- =end
93
-
94
- =begin
95
- Given /^the following (.+) records?$/ do |model_name, table|
96
- class_name = model_name.gsub(' ', '_').singularize
97
- model_class = class_name.classify.constantize
98
- model_class.delete_all
99
- has_many_opts = model_class.reflect_on_all_associations(:has_many)
100
- table.hashes.each do |hash|
101
- attr_hash = hash.inject({}) do |attr_hash, (attr_name, attr_value)|
102
- if attr_name == 'user' && !attr_value.is_a?(User) # hack
103
- attr_hash[attr_name] = find_or_create_valid_user(:login => attr_value)
104
- elsif attr_name == "published_at" && hash['published_as'] == "draft" # hack
105
- attr_hash[attr_name] = nil
106
- elsif (association = has_many_opts.detect { |a| attr_name =~ /^(#{a.name})(_.*)/ })
107
- find_suffix = $2
108
- attr_hash[association.name] = if attr_value.nil?
109
- []
110
- else
111
- association_class = association.class_name.constantize
112
- attr_value.split(", ").map do |v|
113
- association_class.send("find_by#{find_suffix}", v)
114
- end
115
- end
116
- else
117
- attr_hash[attr_name] = attr_value
118
- end
119
- attr_hash
120
- end
121
-
122
- approve = attr_hash.delete("approve")
123
- model = Factory(class_name.to_sym, attr_hash)
124
- if approve == "true"
125
- model.approve!
126
- end
127
- model
128
- end
129
- end
130
-
131
-
132
- Given /^there is a ([^\" ]+)$/ do |resource|
133
- instance_variable_set(:"@#{resource.gsub(' ', '_')}", respond_to?(:"create_valid_#{resource.gsub(' ', '_')}") ? send(:"create_valid_#{resource.gsub(' ', '_')}") : Factory(:"#{resource.gsub(' ', '_')}"))
134
- end
135
- Given /^there is a (.+) with (.+) "([^\"]*)"$/ do |resource, field, value|
136
- resource_name = resource.gsub(' ', '_')
137
- resource_name.classify.constantize.find(:all, :conditions => {field => value}).map(&:destroy) rescue nil # in case there is a uniqueness validation
138
- method = :"create_valid_#{resource_name}"
139
- instance_variable_set(:"@#{resource_name}", respond_to?(method) ? send(method, field.to_sym => value) : Factory(resource_name, field.to_sym => value))
140
- end
141
- Given /^there is an (.+) with (.+) "([^\"]*)"$/ do |resource, field, value|
142
- resource_name = resource.gsub(' ', '_')
143
- resource_name.classify.constantize.find(:all, :conditions => {field => value}).map(&:destroy) rescue nil # in case there is a uniqueness validation
144
- method = :"create_valid_#{resource_name}"
145
- instance_variable_set(:"@#{resource_name}", respond_to?(method) ? send(method, field.to_sym => value) : Factory(resource_name, field.to_sym => value))
146
- end
147
- #Given /^I have only one (.+)$/ do |resource|
148
- # @myself.send(resource.pluralize).delete_all
149
- # instance_variable_set(:"@#{resource.gsub(' ', '_')}", send(:"create_valid_#{resource.gsub(' ', '_')}"))
150
- #end
151
- Given /^I have only one (.+) with (.+) "([^\"]*)"$/ do |resource, field, value|
152
- @myself.send(resource.pluralize).delete_all
153
- resource.classify.constantize.find(:all, :conditions => {field => value}).map(&:destroy) rescue nil # in case there is a uniqueness validation
154
- instance_variable_set(:"@#{resource.gsub(' ', '_')}", send(:"create_valid_#{resource.gsub(' ', '_')}", field.to_sym => value, :user => @myself))
155
- end
156
- Given /^I have a (.+) with (.+) "([^\"]*)"$/ do |resource, field, value|
157
- resource.classify.constantize.find(:all, :conditions => {field => value}).map(&:destroy) rescue nil # in case there is a uniqueness validation
158
- instance_variable_set(:"@#{resource.gsub(' ', '_')}", send(:"create_valid_#{resource.gsub(' ', '_')}", field.to_sym => value, :user => @myself))
159
- end
160
-
161
- Then /^there should be ([0-9]+) (.+)$/ do |count, resource|
162
- resource.singularize.classify.constantize.count.should == count.to_i
163
- end
164
-
165
- Then /^I should have ([0-9]+) (.+)$/ do |count, resource|
166
- @myself.send(resource.pluralize).count.should == count.to_i
167
- end
168
-
169
- Given /^there are no ([^ ]+)$/ do |resource|
170
- resource.singularize.classify.constantize.delete_all
171
- end
172
-
173
- Then /^that (.+) should be deleted$/ do |resource|
174
- lambda { instance_variable_get(:"@#{resource}").reload }.should raise_error ActiveRecord::RecordNotFound
175
- end
176
- Then /^that (.+) should no longer exist$/ do |resource|
177
- lambda { instance_variable_get(:"@#{resource}").reload }.should raise_error ActiveRecord::RecordNotFound
178
- end
179
- =end
50
+ end
@@ -14,11 +14,12 @@ When /^I follow "([^\"]*)"$/ do |link|
14
14
  end
15
15
 
16
16
  When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
17
- fill_in(field, :with => value)
17
+ fill_in(field, :with => value)
18
+ @can_take_screeshot = true
18
19
  end
19
20
 
20
21
  When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
21
- select(value, :from => field)
22
+ select(value, :from => field)
22
23
  end
23
24
 
24
25
  # Use this step in conjunction with Rail's datetime_select helper. For example:
@@ -0,0 +1,37 @@
1
+ module StepMotherHelper
2
+ def step_should_match(step_string)
3
+ it { @step_mother.should step_match(step_string) }
4
+ end
5
+
6
+ def artist_should_count(n, step_string)
7
+ plural_or_singular = n == 1 ? "" : "s"
8
+ it "should count #{n} Artist#{plural_or_singular} when I call '#{step_string}'" do
9
+ m = @step_mother.step_match(step_string)
10
+ m.invoke(nil)
11
+ Artist.should count(n)
12
+ end
13
+ end
14
+
15
+ def artist_should_be(hash, step_string)
16
+ it "should contain #{hash.inspect} when I call '#{step_string}'" do
17
+ m = @step_mother.step_match(step_string)
18
+ m.invoke(nil)
19
+ Artist.should exist_given(hash)
20
+ end
21
+ end
22
+
23
+ def artist_should_count_and_be(n, hash, step_string)
24
+ artist_should_count(n, step_string)
25
+ artist_should_be(hash, step_string)
26
+ end
27
+
28
+ def artists_in_table_should_be(table, step_string)
29
+ it "should contain the table #{table.hashes.inspect} when I call '#{step_string}" do
30
+ m = @step_mother.step_match('the following artists')
31
+ m.invoke(table)
32
+ table.hashes.each do |hash|
33
+ Artist.should exist_given(hash)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,39 @@
1
+ # Specs from navigation_steps.rb
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+ require File.expand_path(File.dirname(__FILE__) + '/../common_steps_helper')
4
+ require 'common_steps/helpers/record_helper'
5
+ require 'common_steps/helpers/navigation_helper'
6
+ require 'common_steps/helpers/step_mother_helper'
7
+
8
+
9
+ describe 'Cucumber instance with navigation_steps.rb and World(RecordHelper, NavigationHelper) loaded' do
10
+ extend StepMotherHelper
11
+
12
+ before do
13
+ #include 'ruby-debug'
14
+ #debugger
15
+ @step_mother = Cucumber::Cli::Main.step_mother
16
+ @step_mother.load_code_file(File.expand_path(File.dirname(__FILE__) + "/../../lib/common_steps/step_definitions/navigation_steps.rb"))
17
+
18
+ @dsl = Object.new
19
+ @dsl.extend(Cucumber::RbSupport::RbDsl)
20
+ @dsl.World(RecordHelper, NavigationHelper)
21
+ @step_mother.load_programming_language('rb').begin_rb_scenario
22
+ @current_world = Cucumber::RbSupport::RbDsl.instance_variable_get(:@rb_language).current_world
23
+ end
24
+
25
+ step_should_match 'I go to the homepage'
26
+ step_should_match 'I go to "/asdkjasd/asdasd"'
27
+ step_should_match 'I go to "asdkjasd/asdasd"'
28
+
29
+ describe 'when I invoke homepage with homepage redirecting to "/"' do
30
+ it 'should call homepage method' do
31
+ @current_world.should_receive(:visit_homepage).with(no_args)
32
+ m = @step_mother.step_match('I go to the homepage')
33
+ m.invoke(nil)
34
+ end
35
+ end
36
+
37
+ step_should_match 'I go to "/something.something/something"'
38
+
39
+ end
@@ -1,44 +1,9 @@
1
+ # Specs from record_steps.rb
2
+
1
3
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
4
  require File.expand_path(File.dirname(__FILE__) + '/../common_steps_helper')
3
5
  require "common_steps/helpers/record_helper"
4
-
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
6
+ require 'common_steps/helpers/step_mother_helper'
42
7
 
43
8
  # In order to use features without bugs
44
9
  # As a developer
@@ -55,9 +20,9 @@ describe "Cucumber instance with record_steps.rb and World(RecordHelper) loaded"
55
20
  @step_mother.load_programming_language('rb').begin_rb_scenario
56
21
  end
57
22
 
58
- # Specs from record_steps.rb
59
- #
23
+ ####################
60
24
  # there (is|are) (\w+) (\w*)
25
+ ####################
61
26
  step_should_match 'there are no artists'
62
27
  step_should_match 'there is no artists'
63
28
  step_should_match 'there are no artist'
@@ -67,7 +32,23 @@ describe "Cucumber instance with record_steps.rb and World(RecordHelper) loaded"
67
32
  step_should_match 'there is 1 artist'
68
33
  step_should_match 'there are 3 artists'
69
34
 
35
+ # there (is|are) (\w+) (\w*)
36
+ describe "StepMatch[there (is|are) (\w+) (.*)] invocation, with no artists" do
37
+ before do
38
+ Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
39
+ end
40
+
41
+ artist_should_count 0, 'there are 0 artists'
42
+ artist_should_count 0, 'there are no artists'
43
+ artist_should_count 1, 'there is 1 artist'
44
+ artist_should_count 1, 'there is an artist'
45
+ artist_should_count 1, 'there is a artist'
46
+ artist_should_count 3, 'there are 3 artists'
47
+ end
48
+
49
+ ####################
70
50
  # there (is|are) (\w+) (\w+) with a (.*)
51
+ ####################
71
52
  step_should_match 'there are 0 artists with a name of "John"'
72
53
  step_should_match 'there are no artists with a name of "John"'
73
54
  step_should_match 'there is 1 artist with a name of "John"'
@@ -75,42 +56,8 @@ describe "Cucumber instance with record_steps.rb and World(RecordHelper) loaded"
75
56
  step_should_match 'there is a artist with a name of "John"'
76
57
  step_should_match 'there are 3 artists with a name of "John"'
77
58
  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
59
 
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
-
60
+ # there (is|are) (\w+) (\w+) with a (.*)
114
61
  describe "StepMatch[there (is|are) (\w+) (\w+) with a (.*)] invocation, with no artists" do
115
62
  before do
116
63
  Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
@@ -129,51 +76,66 @@ describe "Cucumber instance with record_steps.rb and World(RecordHelper) loaded"
129
76
  #artist_should_count_and_be(1, {:name => "John", :age => 32}, 'there are 1 artists with a name of "John", and age of 32')
130
77
  end
131
78
 
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
-
79
+ ####################
80
+ # there should be (\w+) (\w+)
81
+ ####################
82
+ step_should_match 'there should be no artists'
83
+ step_should_match 'there should be no artists'
84
+ step_should_match 'there should be no artist'
85
+ step_should_match 'there should be 0 artists'
86
+ step_should_match 'there should be a artist'
87
+ step_should_match 'there should be an artist'
88
+ step_should_match 'there should be 1 artist'
89
+ step_should_match 'there should be 3 artists'
90
+
91
+ # there should be (\w+) (\w+)
145
92
  describe "StepMatch[there should be (\w+) (\w+)] invocation with 1 artist, with no artists" do
146
93
  before do
147
94
  Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
148
95
  end
149
-
150
96
  artist_should_count 0, 'there should be 0 artists'
151
97
  artist_should_count 0, 'there should be no artists'
152
98
  end
153
99
 
100
+ # there should be (\w+) (\w+)
154
101
  describe "StepMatch[there should be (\w+) (\w+)] invocation with 1 artist, with 1 artist" do
155
102
  before do
156
103
  Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
157
104
  Factory(:artist)
158
105
  end
159
-
160
106
  artist_should_count 1, 'there should be 1 artist'
161
107
  artist_should_count 1, 'there should be an artist'
162
108
  artist_should_count 1, 'there should be a artist'
163
109
  end
164
110
 
111
+ ####################
112
+ # the following (\w+)
113
+ ####################
114
+ step_should_match 'the following artists'
115
+ step_should_match 'the following artists:'
116
+ step_should_match 'the following artist'
117
+ step_should_match 'the following artist:'
118
+
119
+ # the following (\w+)
165
120
  describe "StepMatch[Given the following artists] invoked with table of attributes" do
166
121
  before do
167
122
  Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
168
123
  end
169
-
170
- @cucumber_table = Cucumber::Ast::Table.new(
171
- [['name', 'age'],
172
- ['John', '12'],
173
- ['Mary', '34']])
124
+ @cucumber_table = Cucumber::Ast::Table.new([['name', 'age'], ['John', '12'], ['Mary', '34']])
174
125
  artists_in_table_should_be @cucumber_table, 'the following artists'
175
126
  end
176
127
 
128
+ ####################
129
+ # there should be (\w+) (\w+) with a (.*)
130
+ ####################
131
+ step_should_match 'there should be 0 artists with a name of "John"'
132
+ step_should_match 'there should be no artists with a name of "John"'
133
+ step_should_match 'there should be 1 artist with a name of "John"'
134
+ step_should_match 'there should be an artist with a name of "John"'
135
+ step_should_match 'there should be a artist with a name of "John"'
136
+ step_should_match 'there should be 3 artists with a name of "John"'
137
+ step_should_match 'there should be 1 artist with a name of "John", an age of 32 and a country of "Portugal"'
138
+
177
139
  describe "StepMatch[there should be (\w+) (\w+) with a (.*)] with no artists" do
178
140
  before do
179
141
  Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
@@ -182,7 +144,7 @@ describe "Cucumber instance with record_steps.rb and World(RecordHelper) loaded"
182
144
  artist_should_count(0, 'there should be 0 artists with a name of "John"')
183
145
  artist_should_count(0, 'there should be no artists with a name of "John"')
184
146
  end
185
-
147
+
186
148
  describe "StepMatch[there should be (\w+) (\w+) with a (.*)] with 1 artist" do
187
149
  before do
188
150
  Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
@@ -217,8 +179,16 @@ describe "Cucumber instance with record_steps.rb and World(RecordHelper) loaded"
217
179
  end.should_not raise_error
218
180
  end
219
181
  end
220
-
221
- describe "where there are 2 artists [{:name => 'John', :age => 12}, {:name => 'Mary', :age => 34}]" do
182
+
183
+ ####################
184
+ # there should be the following (\w+):?
185
+ ####################
186
+ step_should_match 'there should be the following artists'
187
+ step_should_match 'there should be the following artists:'
188
+ step_should_match 'there should be the following artist'
189
+ step_should_match 'there should be the following artist:'
190
+
191
+ describe "there are 2 artists [{:name => 'John', :age => 12}, {:name => 'Mary', :age => 34}]" do
222
192
  before do
223
193
  Artist.destroy_all # there are no artist - FIXME I shouldn't have to care about this
224
194
  Artist.create!(:name => "John", :age => 12)
@@ -252,7 +222,14 @@ describe "Cucumber instance with record_steps.rb and World(RecordHelper) loaded"
252
222
  ['John', '12'],
253
223
  ['Mary', '34'],
254
224
  ['Andrea', '22']]))
255
- end.should raise_error
225
+ end.should raise_error
256
226
  end
257
227
  end
228
+
229
+ ####################
230
+ # I should see the following (\w+) in order
231
+ ####################
232
+ step_should_match 'I should see the following artists in order'
233
+ step_should_match 'I should see the following artist in order'
234
+
258
235
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Byclosure-common_steps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasco Andrade e Silva
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-09-15 00:00:00 -07:00
13
+ date: 2009-09-23 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -78,6 +78,7 @@ files:
78
78
  - lib/common_steps/helpers.rb
79
79
  - lib/common_steps/helpers/conditions.treetop
80
80
  - lib/common_steps/helpers/conditions_parser.rb
81
+ - lib/common_steps/helpers/navigation_helper.rb
81
82
  - lib/common_steps/helpers/rake_helper.rb
82
83
  - lib/common_steps/helpers/record_helper.rb
83
84
  - lib/common_steps/matchers/count.rb
@@ -90,9 +91,11 @@ files:
90
91
  - lib/common_steps/support/spec.rb
91
92
  - lib/common_steps/tasks/cucumber.rake
92
93
  - lib/common_steps/tasks/rspec.rake
93
- - spec/common_steps/common_steps_spec.rb
94
94
  - spec/common_steps/helpers/conditions_parser_spec.rb
95
95
  - spec/common_steps/helpers/record_helper_spec.rb
96
+ - spec/common_steps/helpers/step_mother_helper.rb
97
+ - spec/common_steps/navigation_steps_spec.rb
98
+ - spec/common_steps/record_steps_spec.rb
96
99
  - spec/common_steps_helper.rb
97
100
  - spec/spec.opts
98
101
  - spec/spec_helper.rb
@@ -100,7 +103,7 @@ files:
100
103
  - tasks/rdoc.rake
101
104
  - tasks/roodi.rake
102
105
  - tasks/rspec.rake
103
- has_rdoc: true
106
+ has_rdoc: false
104
107
  homepage: http://github.com/Byclosure/common_steps
105
108
  licenses:
106
109
  post_install_message:
@@ -125,11 +128,13 @@ requirements: []
125
128
  rubyforge_project:
126
129
  rubygems_version: 1.3.5
127
130
  signing_key:
128
- specification_version: 2
131
+ specification_version: 3
129
132
  summary: common_steps. Some common cucumber step definitions, rake tasks, and rspec matchers
130
133
  test_files:
131
- - spec/spec_helper.rb
132
- - spec/common_steps_helper.rb
133
- - spec/common_steps/helpers/record_helper_spec.rb
134
134
  - spec/common_steps/helpers/conditions_parser_spec.rb
135
- - spec/common_steps/common_steps_spec.rb
135
+ - spec/common_steps/helpers/record_helper_spec.rb
136
+ - spec/common_steps/helpers/step_mother_helper.rb
137
+ - spec/common_steps/navigation_steps_spec.rb
138
+ - spec/common_steps/record_steps_spec.rb
139
+ - spec/common_steps_helper.rb
140
+ - spec/spec_helper.rb