sandwich 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/sandwich/cucumber/debug_steps.rb +5 -5
- data/lib/sandwich/cucumber/model_steps.rb +28 -10
- data/lib/sandwich/cucumber/table_steps.rb +6 -6
- data/lib/sandwich/cucumber/web_steps.rb +5 -0
- data/lib/sandwich/cucumber/world.rb +8 -0
- data/lib/sandwich/ext/active_record.rb +1 -0
- data/lib/sandwich/ext/object.rb +9 -0
- data/lib/sandwich/helpers/base.rb +13 -0
- data/sandwich.gemspec +5 -3
- metadata +6 -4
- data/lib/sandwich/regexps.rb +0 -27
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'pp'
|
2
2
|
|
3
|
-
Then
|
3
|
+
Then /^show me the source$/ do
|
4
4
|
puts page.body
|
5
5
|
end
|
6
6
|
|
7
|
-
Then
|
7
|
+
Then /^show me all (.+)$/ do |targets|
|
8
8
|
targets.split(/,/).map do |target|
|
9
|
-
target.strip.singularize.classify.constantize.all.map { |item| pp item }
|
9
|
+
target.strip.underscore.singularize.classify.constantize.all.map { |item| pp item }
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
Then
|
13
|
+
Then /^show me the source for #{q}$/ do |selector|
|
14
14
|
puts locate(selector).html
|
15
15
|
end
|
16
16
|
|
17
|
-
Then
|
17
|
+
Then /^show me the page text$/ do
|
18
18
|
IO.popen("html2text", "w+") do |io|
|
19
19
|
io.puts response.body
|
20
20
|
io.close_write
|
@@ -2,33 +2,51 @@ require 'sandwich/ext/string'
|
|
2
2
|
require 'sandwich/cucumber/world'
|
3
3
|
require 'sandwich/regexps'
|
4
4
|
|
5
|
-
Given
|
5
|
+
Given /^(an?|the|\d+) (.+) exists?$/ do |total, what|
|
6
6
|
class_for(what).tap do |model|
|
7
7
|
total.times { model.make }
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
class_for(what)
|
11
|
+
Transform /(an?|\d+) (.+) #{q}$/ do |total, what, value|
|
12
|
+
model = class_for(what)
|
13
|
+
r = total.times.map { model.make(model.default_attribute => value) }
|
14
|
+
|
15
|
+
r.length == 1 ? r.first : r
|
13
16
|
end
|
14
17
|
|
15
|
-
|
16
|
-
class_for(what).
|
17
|
-
|
18
|
-
|
18
|
+
Transform /the (.+) (?:with|in) (.+) #{q}$/ do |what, attr, value|
|
19
|
+
class_for(what).find(:first, :conditions => {attr => value})
|
20
|
+
end
|
21
|
+
|
22
|
+
Transform /the (.+) #{q}$/ do |what, value|
|
23
|
+
klass = class_for(what)
|
24
|
+
klass.find(:first, :conditions => {klass.default_attribute => value})
|
25
|
+
end
|
26
|
+
|
27
|
+
Given /^(.+) belonging to (.+)$/ do |child, parent|
|
28
|
+
child.send("#{parent.class.name.underscore}=", parent)
|
29
|
+
end
|
30
|
+
|
31
|
+
Given /^(.+) has (.+)$/ do |parent, child|
|
32
|
+
parent.send(child.class.name.underscore.pluralize) << child
|
33
|
+
end
|
34
|
+
|
35
|
+
Given /^no (.+) exists?$/ do |what|
|
36
|
+
class_for(what).delete_all
|
19
37
|
end
|
20
38
|
|
21
|
-
Given
|
39
|
+
Given /^no (.+) (?:with|in) (.+) #{q} exists?$/ do |what, attr, value|
|
22
40
|
class_for(what).delete_all
|
23
41
|
end
|
24
42
|
|
25
|
-
Given
|
43
|
+
Given /^(an?|the|\d+) (.+) with the following attributes:$/ do |total, what, table|
|
26
44
|
class_for(what).tap do |model|
|
27
45
|
total.times { model.make(Hash[*table.raw.map { |k, v| [k.underscore, v] }.flatten]) }
|
28
46
|
end
|
29
47
|
end
|
30
48
|
|
31
|
-
Given
|
49
|
+
Given /^the following (.+):$/ do |what, table|
|
32
50
|
class_for(what.singularize).tap do |model|
|
33
51
|
table.hashes.each do |h|
|
34
52
|
model.make(Hash[*h.each_pair.map { |(k, v)| [k.underscore, v] }.flatten])
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'sandwich/regexps'
|
2
2
|
|
3
|
-
When
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
When /^I fill in the #{q} row, #{q} column in (.+?) with #{q}$/ do |row, column, path, value|
|
4
|
+
selector = xpath(selector_for(path))
|
5
|
+
_, column_index = page.all(:xpath, "#{selector}//th").each_with_index.find { |e, i| e.text == column }
|
6
|
+
_, row_index = page.all(:xpath, "#{selector}//tr").each_with_index.find { |e, i| e.text.include?(row) }
|
7
|
+
page.locate(:xpath, "((#{selector}//tr)[#{row_index + 1}]/td)[#{column_index + 1}]/input").set(value)
|
8
8
|
end
|
9
9
|
|
10
|
-
Then
|
10
|
+
Then /^I should see #{q} in the (\w+) data row of (.+)$/ do |value, ordinal, path|
|
11
11
|
within(selector_for(path)) do
|
12
12
|
page.should have_xpath("//tr[#{ordinal.to_i}]/td", :text => value)
|
13
13
|
end
|
data/sandwich.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sandwich}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Leal"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-18}
|
13
13
|
s.description = %q{Yup, cucumber helpers}
|
14
14
|
s.email = %q{david@thedigitalants.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,12 +27,14 @@ Gem::Specification.new do |s|
|
|
27
27
|
"lib/sandwich/cucumber/debug_steps.rb",
|
28
28
|
"lib/sandwich/cucumber/model_steps.rb",
|
29
29
|
"lib/sandwich/cucumber/table_steps.rb",
|
30
|
+
"lib/sandwich/cucumber/web_steps.rb",
|
30
31
|
"lib/sandwich/cucumber/world.rb",
|
31
32
|
"lib/sandwich/ext/active_record.rb",
|
32
33
|
"lib/sandwich/ext/capybara.rb",
|
34
|
+
"lib/sandwich/ext/object.rb",
|
33
35
|
"lib/sandwich/ext/string.rb",
|
34
36
|
"lib/sandwich/helpers/amounts.rb",
|
35
|
-
"lib/sandwich/
|
37
|
+
"lib/sandwich/helpers/base.rb",
|
36
38
|
"sandwich.gemspec",
|
37
39
|
"spec/sandwich_spec.rb",
|
38
40
|
"spec/spec.opts",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- David Leal
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-18 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -99,12 +99,14 @@ files:
|
|
99
99
|
- lib/sandwich/cucumber/debug_steps.rb
|
100
100
|
- lib/sandwich/cucumber/model_steps.rb
|
101
101
|
- lib/sandwich/cucumber/table_steps.rb
|
102
|
+
- lib/sandwich/cucumber/web_steps.rb
|
102
103
|
- lib/sandwich/cucumber/world.rb
|
103
104
|
- lib/sandwich/ext/active_record.rb
|
104
105
|
- lib/sandwich/ext/capybara.rb
|
106
|
+
- lib/sandwich/ext/object.rb
|
105
107
|
- lib/sandwich/ext/string.rb
|
106
108
|
- lib/sandwich/helpers/amounts.rb
|
107
|
-
- lib/sandwich/
|
109
|
+
- lib/sandwich/helpers/base.rb
|
108
110
|
- sandwich.gemspec
|
109
111
|
- spec/sandwich_spec.rb
|
110
112
|
- spec/spec.opts
|
data/lib/sandwich/regexps.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Sandwich
|
2
|
-
def self.regexps
|
3
|
-
# TODO extract (a|the|etc) to its own thing, so that it can be overridden
|
4
|
-
|
5
|
-
@regexps ||= {}.tap do |rx|
|
6
|
-
rx[:model] = /^(an?|the|\d+) (.+) exists?$/
|
7
|
-
rx[:no_model] = /^no (.+) exists?$/
|
8
|
-
rx[:model_with_attribute] = /^(an?|the|\d+) (.+) (?:with|in) (.+) #{quoted_value} exists?$/
|
9
|
-
rx[:no_model_with_attribute] = /^no (.+) (?:with|in) (.+) #{quoted_value} exists?$/
|
10
|
-
rx[:model_with_attributes] = /^(an?|the|\d+) (.+) exists with the following attributes:$/
|
11
|
-
rx[:models_with_attributes] = /^the following (.+) exist:$/
|
12
|
-
rx[:show_source] = /^show me the source$/
|
13
|
-
rx[:show_all] = /^show me all (.+)$/
|
14
|
-
rx[:show_source_snippet] = /^show me the source for #{quoted_value}$/
|
15
|
-
rx[:show_page_text] = /^show me the page text$/
|
16
|
-
rx[:look_at] = /^I look at (.+)$/
|
17
|
-
rx[:fill_within_table] = /^I fill in the #{quoted_value} cell for the (\w+) row of (.+?) with #{quoted_value}$/
|
18
|
-
rx[:find_within_row] = /^I should see #{quoted_value} in the (\w+) data row of (.+)$/
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def self.quoted_value
|
25
|
-
'"([^\"]*)"'
|
26
|
-
end
|
27
|
-
end
|