sandwich 0.0.6 → 0.0.7
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.
|
1
|
+
0.0.7
|
@@ -18,6 +18,10 @@ Then /^show me the source for ([^\"]+)$/ do |selector|
|
|
18
18
|
puts locate(selector_for(selector)).html
|
19
19
|
end
|
20
20
|
|
21
|
+
Then /^wait (\d+)$/ do |time|
|
22
|
+
sleep time.to_i
|
23
|
+
end
|
24
|
+
|
21
25
|
Then /^show me the page text$/ do
|
22
26
|
IO.popen("html2text", "w+") do |io|
|
23
27
|
io.puts response.body
|
@@ -16,10 +16,10 @@ Transform /(an?|\d+) (.+) #{qc}$/ do |total, what, value|
|
|
16
16
|
model = class_for(what)
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
%
|
19
|
+
raise \
|
20
|
+
%Q{No attribute passed and no default attribute defined. You can do that with:
|
21
21
|
|
22
|
-
|
22
|
+
#{model}.default_attribute :your_default_attribute
|
23
23
|
|
24
24
|
} if attr.nil?
|
25
25
|
|
@@ -37,12 +37,9 @@ Transform /the (.+) #{qc}$/ do |what, value|
|
|
37
37
|
klass.find(:first, :conditions => {klass.default_attribute => value})
|
38
38
|
end
|
39
39
|
|
40
|
-
Given /^(.+)
|
40
|
+
Given /^(.+) belong(?:ing|s) to (.+)$/ do |child, parent|
|
41
41
|
child.send("#{parent.class.name.underscore}=", parent)
|
42
|
-
|
43
|
-
|
44
|
-
Given /^(a .+ with .+)$/ do |obj|
|
45
|
-
# la la la la
|
42
|
+
child.save!
|
46
43
|
end
|
47
44
|
|
48
45
|
Given /^(.+) has (.+)$/ do |parent, child|
|
@@ -66,7 +63,7 @@ end
|
|
66
63
|
Given /^the following (.+):$/ do |what, table|
|
67
64
|
class_for(what.singularize).tap do |model|
|
68
65
|
table.hashes.each do |h|
|
69
|
-
model.make(Hash[*h.each_pair.map { |(k, v)| [k.underscore, v] }.flatten])
|
66
|
+
model.make(Hash[*h.each_pair.map { |(k, v)| [k.underscore, value_for(model, k, v)] }.flatten])
|
70
67
|
end
|
71
68
|
end
|
72
69
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
When /^I fill in the #{qc} row, #{qc} column in (.+?) with #{qc}$/ do |row, column, path, value|
|
2
2
|
selector = xpath(selector_for(path))
|
3
|
-
_, column_index = page.
|
3
|
+
_, column_index = page.find(:xpath, "#{selector}//tr", :text => /#{column}/).
|
4
|
+
all(:xpath, "*").each_with_index.find { |e, i| e.text == column }
|
4
5
|
_, row_index = page.all(:xpath, "#{selector}//tr").each_with_index.find { |e, i| e.text.include?(row) }
|
6
|
+
|
5
7
|
page.locate(:xpath, "((#{selector}//tr)[#{row_index + 1}]/td)[#{column_index + 1}]/input").set(value)
|
6
8
|
end
|
7
9
|
|
8
10
|
Then /^I should see #{qc} in the (\w+) data row of (.+)$/ do |value, ordinal, path|
|
9
|
-
|
10
|
-
page.should have_xpath("//tr[#{ordinal.to_i}]/td", :text => value)
|
11
|
-
end
|
11
|
+
page.should have_xpath("(#{xpath(selector_for(path))}//tr[td])[#{ordinal.to_i}]", :text => value)
|
12
12
|
end
|
@@ -1,3 +1,31 @@
|
|
1
|
-
Then /^I should see "([^\"]*)"
|
1
|
+
Then /^I should see "([^\"]*)" (?:with)?in (.+)$/ do |text, selector|
|
2
2
|
page.should have_xpath(xpath(selector_for(selector)), :text => text)
|
3
3
|
end
|
4
|
+
|
5
|
+
Then /^I should see the header "([^\"]*)"$/ do |text|
|
6
|
+
page.should have_xpath("//h1 | //h2 | //h3 | //h4 | //h5 | //h6")
|
7
|
+
end
|
8
|
+
|
9
|
+
Then /^I should see the (notice|error) "([^\"]*)"$/ do |type, message|
|
10
|
+
locate(:xpath, xpath(selector_for(type)), :text => message)
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^I should see (.+)$/ do |selector|
|
14
|
+
locate(:xpath, xpath(selector_for(selector)))
|
15
|
+
end
|
16
|
+
|
17
|
+
When /^I fill in (.+) with the following:$/ do |selector, table|
|
18
|
+
within(:xpath, xpath(selector_for(selector))) do
|
19
|
+
table.raw.each do |(k, v)|
|
20
|
+
node = find(:xpath, Capybara::XPath.field(k))
|
21
|
+
|
22
|
+
raise Capybara::ElementNotFound, "Unable to locate '#{selector_for(selector)}'" unless node
|
23
|
+
|
24
|
+
if (node.tag_name == 'select')
|
25
|
+
node.select(v)
|
26
|
+
else
|
27
|
+
node.set(v)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -4,8 +4,23 @@ module Sandwich
|
|
4
4
|
name.underscore.classify.constantize
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
if
|
7
|
+
def value_for(model, attr, value)
|
8
|
+
if assoc = model.reflect_on_association(attr.to_sym)
|
9
|
+
assoc_class = assoc.class_name.constantize
|
10
|
+
assoc_class.make(assoc_class.default_attribute => value)
|
11
|
+
else
|
12
|
+
value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def xpath(unknown_selector)
|
17
|
+
kind, selector = if Array === unknown_selector
|
18
|
+
[unknown_selector[0].to_sym, unknown_selector[1]]
|
19
|
+
else
|
20
|
+
[Capybara.default_selector.to_sym, unknown_selector]
|
21
|
+
end
|
22
|
+
|
23
|
+
if kind == :css
|
9
24
|
Capybara::XPath.from_css(selector)
|
10
25
|
else
|
11
26
|
selector
|
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
|
+
- 7
|
9
|
+
version: 0.0.7
|
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-26 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|