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
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -1,6 +1,28 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require "rake/gempackagetask"
|
3
3
|
require "rake/clean"
|
4
|
-
|
4
|
+
|
5
5
|
Dir['tasks/**/*.rake'].each { |rake| load rake }
|
6
6
|
task :default => :spec
|
7
|
+
|
8
|
+
task :install => :gemspec
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'jeweler'
|
12
|
+
Jeweler::Tasks.new do |gem|
|
13
|
+
gem.name = "common_steps"
|
14
|
+
gem.summary = %Q{common_steps. Some common cucumber step definitions, rake tasks, and rspec matchers}
|
15
|
+
gem.description = gem.summary
|
16
|
+
gem.email = ["vasco@byclosure.com", "duarte@byclosure.com"]
|
17
|
+
gem.homepage = "http://github.com/Byclosure/common_steps"
|
18
|
+
gem.authors = ["Vasco Andrade e Silva", "Duarte Henriques"]
|
19
|
+
gem.add_development_dependency "rspec"
|
20
|
+
gem.add_development_dependency "cucumber"
|
21
|
+
gem.add_dependency 'activesupport'
|
22
|
+
gem.add_dependency 'cucumber'
|
23
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
24
|
+
end
|
25
|
+
rescue LoadError
|
26
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
27
|
+
end
|
28
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
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.
|
8
|
+
s.version = "0.0.2"
|
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-
|
12
|
+
s.date = %q{2009-09-15}
|
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 = [
|
@@ -28,6 +28,9 @@ Gem::Specification.new do |s|
|
|
28
28
|
"features/support/env.rb",
|
29
29
|
"lib/common_steps.rb",
|
30
30
|
"lib/common_steps/helpers.rb",
|
31
|
+
"lib/common_steps/helpers/conditions.treetop",
|
32
|
+
"lib/common_steps/helpers/conditions_parser.rb",
|
33
|
+
"lib/common_steps/helpers/rake_helper.rb",
|
31
34
|
"lib/common_steps/helpers/record_helper.rb",
|
32
35
|
"lib/common_steps/matchers/count.rb",
|
33
36
|
"lib/common_steps/step_definitions.rb",
|
@@ -36,42 +39,53 @@ Gem::Specification.new do |s|
|
|
36
39
|
"lib/common_steps/step_definitions/webrat_steps.rb",
|
37
40
|
"lib/common_steps/support/database.rb",
|
38
41
|
"lib/common_steps/support/email.rb",
|
39
|
-
"lib/common_steps/support/env.rb",
|
40
42
|
"lib/common_steps/support/spec.rb",
|
41
43
|
"lib/common_steps/tasks/cucumber.rake",
|
42
44
|
"lib/common_steps/tasks/rspec.rake",
|
43
45
|
"spec/common_steps/common_steps_spec.rb",
|
46
|
+
"spec/common_steps/helpers/conditions_parser_spec.rb",
|
47
|
+
"spec/common_steps/helpers/record_helper_spec.rb",
|
48
|
+
"spec/common_steps_helper.rb",
|
44
49
|
"spec/spec.opts",
|
45
50
|
"spec/spec_helper.rb",
|
46
51
|
"tasks/cucumber.rake",
|
47
|
-
"tasks/jeweler.rake",
|
48
52
|
"tasks/rdoc.rake",
|
49
53
|
"tasks/roodi.rake",
|
50
54
|
"tasks/rspec.rake"
|
51
55
|
]
|
56
|
+
s.has_rdoc = true
|
52
57
|
s.homepage = %q{http://github.com/Byclosure/common_steps}
|
53
58
|
s.rdoc_options = ["--charset=UTF-8"]
|
54
59
|
s.require_paths = ["lib"]
|
55
|
-
s.rubygems_version = %q{1.3.
|
60
|
+
s.rubygems_version = %q{1.3.1}
|
56
61
|
s.summary = %q{common_steps. Some common cucumber step definitions, rake tasks, and rspec matchers}
|
57
62
|
s.test_files = [
|
58
|
-
"spec/
|
59
|
-
"spec/
|
63
|
+
"spec/spec_helper.rb",
|
64
|
+
"spec/common_steps_helper.rb",
|
65
|
+
"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"
|
60
68
|
]
|
61
69
|
|
62
70
|
if s.respond_to? :specification_version then
|
63
71
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
64
|
-
s.specification_version =
|
72
|
+
s.specification_version = 2
|
65
73
|
|
66
74
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
67
75
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
68
76
|
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
77
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
78
|
+
s.add_runtime_dependency(%q<cucumber>, [">= 0"])
|
69
79
|
else
|
70
80
|
s.add_dependency(%q<rspec>, [">= 0"])
|
71
81
|
s.add_dependency(%q<cucumber>, [">= 0"])
|
82
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
83
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
72
84
|
end
|
73
85
|
else
|
74
86
|
s.add_dependency(%q<rspec>, [">= 0"])
|
75
87
|
s.add_dependency(%q<cucumber>, [">= 0"])
|
88
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
89
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
76
90
|
end
|
77
91
|
end
|
data/features/support/env.rb
CHANGED
@@ -0,0 +1,113 @@
|
|
1
|
+
grammar Conditions
|
2
|
+
rule conditions
|
3
|
+
condition [\s]* "," [\s]* "and" [\s]+ conditions <CommaAndConditions>
|
4
|
+
/
|
5
|
+
condition [\s]+ "and" [\s]+ conditions <AndConditions> # Para não suportar
|
6
|
+
/
|
7
|
+
condition [\s]* "," [\s]* conditions <CommaConditions>
|
8
|
+
/
|
9
|
+
condition
|
10
|
+
end
|
11
|
+
|
12
|
+
rule condition
|
13
|
+
belonging_to ([\s]* "and" [\s]*)? conditions <BelongingToCondition>
|
14
|
+
/
|
15
|
+
attribute_name [\s]* "=>" [\s]* attribute_value <ArrowCondition>
|
16
|
+
/
|
17
|
+
of_attribute_name [\s]+ attribute_value <OfCondition>
|
18
|
+
end
|
19
|
+
|
20
|
+
rule of_attribute_name
|
21
|
+
name [\s]+ of_attribute_name
|
22
|
+
/
|
23
|
+
(!of name) [\s]+ of
|
24
|
+
/
|
25
|
+
of [\s]+ of
|
26
|
+
end
|
27
|
+
|
28
|
+
rule names_with
|
29
|
+
name [\s]+ names_with
|
30
|
+
/
|
31
|
+
(!with name) [\s]+ with
|
32
|
+
/
|
33
|
+
with with
|
34
|
+
end
|
35
|
+
|
36
|
+
rule with
|
37
|
+
"with"
|
38
|
+
end
|
39
|
+
|
40
|
+
rule of
|
41
|
+
"of"
|
42
|
+
end
|
43
|
+
|
44
|
+
rule attribute_name
|
45
|
+
names
|
46
|
+
end
|
47
|
+
|
48
|
+
rule name
|
49
|
+
[\w]+
|
50
|
+
end
|
51
|
+
|
52
|
+
rule names
|
53
|
+
name [\s]+ names
|
54
|
+
/
|
55
|
+
name
|
56
|
+
end
|
57
|
+
|
58
|
+
rule attribute_value
|
59
|
+
string
|
60
|
+
/
|
61
|
+
symbol
|
62
|
+
/
|
63
|
+
boolean
|
64
|
+
/
|
65
|
+
nil
|
66
|
+
/
|
67
|
+
number
|
68
|
+
end
|
69
|
+
|
70
|
+
rule belonging_to
|
71
|
+
"belonging" [\s]+ "to" [\s]+ names_with [\s]+ ("an" / "a") [\s]+ conditions belonging_to_terminator*
|
72
|
+
end
|
73
|
+
|
74
|
+
rule belonging_to_terminator
|
75
|
+
";"
|
76
|
+
end
|
77
|
+
|
78
|
+
rule string
|
79
|
+
"\"" [^\"]* "\""
|
80
|
+
/
|
81
|
+
"'" [^\']* "'"
|
82
|
+
end
|
83
|
+
|
84
|
+
rule symbol
|
85
|
+
":" [^\s]*
|
86
|
+
end
|
87
|
+
|
88
|
+
rule boolean
|
89
|
+
"true"
|
90
|
+
/
|
91
|
+
"false"
|
92
|
+
end
|
93
|
+
|
94
|
+
rule nil
|
95
|
+
"nil"
|
96
|
+
end
|
97
|
+
|
98
|
+
rule number
|
99
|
+
float
|
100
|
+
/
|
101
|
+
integer
|
102
|
+
end
|
103
|
+
|
104
|
+
rule integer
|
105
|
+
[\d]+
|
106
|
+
end
|
107
|
+
|
108
|
+
rule float
|
109
|
+
"." integer
|
110
|
+
/
|
111
|
+
integer "." integer
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "treetop"
|
2
|
+
|
3
|
+
class SplitConditions < Treetop::Runtime::SyntaxNode
|
4
|
+
def splited_conditions
|
5
|
+
elements.inject([]) do |conditions, element|
|
6
|
+
case element
|
7
|
+
when SplitConditions
|
8
|
+
conditions.push(*element.splited_conditions)
|
9
|
+
when Condition
|
10
|
+
conditions << element
|
11
|
+
end
|
12
|
+
conditions
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
class CommaAndConditions < SplitConditions; end
|
17
|
+
class CommaConditions < SplitConditions; end
|
18
|
+
class AndConditions < SplitConditions; end
|
19
|
+
|
20
|
+
class Condition < Treetop::Runtime::SyntaxNode; end
|
21
|
+
class BelongingToCondition < Condition; end
|
22
|
+
class OfCondition < Condition; end
|
23
|
+
class ArrowCondition < Condition; end
|
24
|
+
|
25
|
+
Treetop.load File.expand_path(File.dirname(__FILE__) + "/conditions.treetop")
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module RecordHelper
|
2
|
-
def record_singular_name(
|
3
|
-
record_name
|
4
|
-
record_name.gsub(' ', '_').singularize
|
2
|
+
def record_singular_name(record_name)
|
3
|
+
record_name.gsub('_', ' ').downcase.singularize
|
5
4
|
end
|
6
|
-
|
5
|
+
|
7
6
|
def record_name_to_class(record_name)
|
8
|
-
klass_name = record_singular_name(record_name).classify
|
7
|
+
klass_name = record_singular_name(record_name).gsub(/\s/, "_").classify
|
9
8
|
klass = klass_name.constantize
|
10
9
|
klass.nil? ? raise("Couldn't found any class for record with name `#{record_name}', tried with `#{klass_name}'") : klass
|
11
10
|
end
|
@@ -44,20 +43,63 @@ module RecordHelper
|
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
|
-
#
|
48
|
-
|
46
|
+
# I should go to the show page of paiting with a name of "Bello", and belonging to an artist with a name "foo"
|
47
|
+
=begin
|
48
|
+
def attr_from_name(class_record, attr_name)
|
49
|
+
case attr_name
|
50
|
+
when /^belonging to (a|an) (\w+) with (a|an) (.*)$/
|
51
|
+
_, association_str, _, conditions_str = $~.captures
|
52
|
+
association_name = association_str.gsub(/\s/, "_").downcase.to_sym
|
53
|
+
association = reflect_on_association(association_name)
|
54
|
+
|
55
|
+
raise("Association `#{association_name}' not found on #{record_class}") if association.nil?
|
56
|
+
raise("Association `#{association_name}' isn't belongs_to(is a #{association.macro})") unless association.belongs_to?
|
57
|
+
|
58
|
+
association
|
59
|
+
association_record = find_record(association.klass, conditions_str)
|
60
|
+
|
61
|
+
else
|
62
|
+
attr_name
|
63
|
+
end
|
64
|
+
|
65
|
+
if record_class.columns_hash[attr_name] # record_class.has_column?(attr_name)
|
66
|
+
elsif
|
67
|
+
end
|
68
|
+
if column_attr.nil? # artist_name case
|
69
|
+
association = record_class.reflect_on_all_associations.detect {|a| header =~ /^#{a.name}/ }
|
70
|
+
raise("Association: `#{header}' not found on #{record_class}") if association.nil?
|
71
|
+
|
72
|
+
find_attrs = header.match(/^#{association.name}(.*)$/)[1]
|
73
|
+
association_class = association.klass
|
74
|
+
table.map_column!(header) { |value| association_class.send("find_by#{find_attrs}", value) }
|
75
|
+
else
|
76
|
+
end
|
77
|
+
end
|
78
|
+
=end
|
79
|
+
|
80
|
+
def value_from_str(value_str)
|
81
|
+
instance_eval(value_str)
|
82
|
+
end
|
83
|
+
|
84
|
+
def conditions_from_str(conditions_str)
|
49
85
|
record_conds = conditions_str.gsub(", and", ",").gsub(" and", ",").split(", ")
|
50
86
|
conds = record_conds.map {|rc| rc.gsub(" => ", " of ").split(" of ") }
|
87
|
+
|
88
|
+
# conds.inject({}) do |base, (attr_name, value_str)|
|
89
|
+
# base[attr_from_name(class_record, attr_name)] = value_from_str(value_str)
|
90
|
+
# base
|
91
|
+
# end
|
92
|
+
|
51
93
|
conds.inject({}) {|base, (attr, value_str)| base[attr] = instance_eval(value_str); base}
|
52
94
|
end
|
53
95
|
|
54
96
|
def find_record(record_class, record_conditions)
|
55
|
-
conditions = conditions_from_str(
|
97
|
+
conditions = conditions_from_str(record_conditions)
|
56
98
|
record = record_class.find(:first, :conditions => conditions)
|
57
99
|
record.nil? ? raise("Couldn't found any record for `#{record_class}' with conditions: `#{conditions.inspect}'") : record
|
58
100
|
end
|
59
101
|
|
60
102
|
def record_class_to_path(record_class)
|
61
|
-
record_class.name.underscore.pluralize
|
103
|
+
"/#{record_class.name.underscore.pluralize}"
|
62
104
|
end
|
63
105
|
end
|
data/lib/common_steps/helpers.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
require "activesupport"
|
2
|
+
|
3
|
+
common_step_mods = []
|
4
|
+
|
1
5
|
Dir[File.dirname(__FILE__) + "/helpers/*.rb"].each do |filename|
|
2
6
|
require filename
|
3
7
|
module_name = filename.chomp(".rb").classify.demodulize
|
4
8
|
mod = module_name.constantize rescue warn("unable to load: module `#{module_name}' in file #{filename}")
|
5
|
-
|
9
|
+
common_step_mods << mod
|
6
10
|
end
|
7
11
|
|
12
|
+
Cucumber::RbSupport::RbDsl.build_rb_world_factory(common_step_mods, nil)
|
13
|
+
|
@@ -62,3 +62,6 @@ Then /^I should be on the edit page of the (\w+) with (a|an) (.*)$/ do |record_n
|
|
62
62
|
URI.parse(current_url).path.should match(/#{path}/)
|
63
63
|
end
|
64
64
|
|
65
|
+
Then /the field with label "([^\"]*)" should contain "([^\"]*)"/ do |field_name, content|
|
66
|
+
field_labeled(field_name).value.should == content
|
67
|
+
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
Given /^there (is|are) (\w+) (\w+) with a (.*)$/ do |_, count_str, record_name, record_conditions|
|
2
|
-
|
3
|
-
conditions = conditions_from_str(
|
2
|
+
singular_record_name = record_singular_name(record_name)
|
3
|
+
conditions = conditions_from_str(record_conditions)
|
4
|
+
record_name_to_class(record_name).delete_all
|
4
5
|
num = str_to_num(count_str)
|
5
|
-
num.times { Factory(
|
6
|
+
num.times { Factory(singular_record_name, conditions) }
|
6
7
|
end
|
7
8
|
|
8
9
|
Given /^there (is|are) (\w+) (\w*)$/ do |_, count_str, record_name|
|
9
|
-
|
10
|
+
singular_record_name = record_singular_name(record_name)
|
10
11
|
num = str_to_num(count_str)
|
11
|
-
num.times { Factory(
|
12
|
+
num.times { Factory(singular_record_name) }
|
12
13
|
end
|
13
14
|
|
14
15
|
Then /^there should be (\w+) (\w+)$/ do |count_str, record_name|
|
@@ -18,9 +19,24 @@ end
|
|
18
19
|
|
19
20
|
Given /^the following (\w+):?$/ do |record_name, table|
|
20
21
|
recordize!(record_name, table)
|
21
|
-
|
22
|
+
singular_record_name = record_singular_name(record_name)
|
22
23
|
table.hashes.each do |hash|
|
23
|
-
Factory(
|
24
|
+
Factory(singular_record_name, hash)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
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)
|
31
|
+
num = str_to_num(count_str)
|
32
|
+
class_name.count(:conditions => conditions).should == num
|
33
|
+
end
|
34
|
+
|
35
|
+
Then /^there should be the following (\w+):?$/ do |record_name, table|
|
36
|
+
recordize!(record_name, table)
|
37
|
+
class_name = record_name_to_class(record_name)
|
38
|
+
table.hashes.each do |hash|
|
39
|
+
class_name.exists?(hash).should == true # TODO vasco: make a matcher for this
|
24
40
|
end
|
25
41
|
end
|
26
42
|
|
@@ -1,11 +1,3 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require 'spec/mocks'
|
4
|
-
|
5
|
-
Dir[File.expand_path(File.dirname(__FILE__) + "../matchers/*.rb")].each do |matcher_fn|
|
6
|
-
require matcher_fn
|
1
|
+
Dir[File.expand_path(File.dirname(__FILE__) + "/../matchers/*.rb")].each do |filename|
|
2
|
+
require filename
|
7
3
|
end
|
8
|
-
|
9
|
-
# Spec::Runner.configure do |config|
|
10
|
-
# end
|
11
|
-
|
@@ -2,7 +2,7 @@ desc "Run all features"
|
|
2
2
|
task :features => 'db:test:prepare' if ::Rake::Task.task_defines?("db:test:prepare")
|
3
3
|
task :features => "features:all"
|
4
4
|
|
5
|
-
require 'cucumber/rake/task'
|
5
|
+
require 'cucumber/rake/task'
|
6
6
|
|
7
7
|
namespace :features do
|
8
8
|
Cucumber::Rake::Task.new(:all) do |t|
|
data/lib/common_steps.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/common_steps/helpers")
|
2
|
-
|
2
|
+
Cucumber::Cli::Main.step_mother.load_code_files(Dir[File.expand_path(File.dirname(__FILE__) + "/common_steps/step_definitions/**/*.*")])
|