sandwich 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.13
1
+ 0.0.14
@@ -1,6 +1,13 @@
1
1
  require 'sandwich/ext/string'
2
2
 
3
- Given /^((?:an?|the|\d+) .+)$/ do |what| end
3
+ Given /^((?:an?|the|\d+) .+)$/ do |target|
4
+ case target
5
+ when String
6
+ raise %Q{Could not materialize "#{target}"}
7
+ else
8
+ target
9
+ end
10
+ end
4
11
 
5
12
  Transform /(?:an?|\d+|the) .+/ do |match|
6
13
  materialize!(match)
@@ -23,7 +30,12 @@ Given /^(.+) belong(?:ing|s) to (an?|the) (.+)$/ do |child, determiner, rest|
23
30
  end
24
31
 
25
32
  Given /^(.+) has (.+)$/ do |parent, child|
26
- parent.send(child.class.name.underscore.pluralize) << child
33
+ case child
34
+ when Array
35
+ child.each { |c| parent.send(child.first.class.name.underscore.pluralize) << c }
36
+ else
37
+ parent.send(child.class.name.underscore.pluralize) << c
38
+ end
27
39
  end
28
40
 
29
41
  Given /^the following (.+):$/ do |what, table|
@@ -1,3 +1,17 @@
1
+ module Sandwich
2
+ module WithinHelper
3
+ def inside(locator)
4
+ locator ? within(:xpath, xpath(locator)) { yield } : yield
5
+ end
6
+ end
7
+ end
8
+
9
+ World(Sandwich::WithinHelper)
10
+
11
+ When /^I follow "([^\"]*)"(?: (?:with)?in (.+))$/ do |link, container|
12
+ inside(selector_for(container)) { click_link(link) }
13
+ end
14
+
1
15
  Then /^I should see "([^\"]*)" (?:with)?in (.+)$/ do |text, selector|
2
16
  page.should have_xpath(xpath(selector_for(selector)), :text => text)
3
17
  end
@@ -8,7 +8,7 @@ module Sandwich
8
8
  end
9
9
 
10
10
  if kind == :css
11
- Capybara::XPath.from_css(selector)
11
+ Capybara::XPath.from_css(selector).to_s
12
12
  else
13
13
  selector
14
14
  end
@@ -123,7 +123,14 @@ module Sandwich
123
123
 
124
124
  def default_attribute_args(value, op)
125
125
  if @default_attribute.respond_to?(:call)
126
- @default_attribute.call(value, op)
126
+ case @default_attribute.arity
127
+ when 1
128
+ @default_attribute.call(value)
129
+ when 2
130
+ @default_attribute.call(value, op)
131
+ else
132
+ raise ArgumentError, "the block sent to #{name}.default_attribute needs 1 or 2 arguments"
133
+ end
127
134
  elsif @default_attribute
128
135
  {@default_attribute => value}
129
136
  else
@@ -134,12 +141,14 @@ module Sandwich
134
141
 
135
142
  def materialize!(match)
136
143
  determiner, model, values = definition(match).model_definition
144
+
145
+ return match if model.nil?
137
146
 
138
147
  if creator?(determiner)
139
148
  if determiner.to_i == 1
140
149
  record!(model, values)
141
150
  else
142
- determiner.times.map { record!(model, values) }
151
+ determiner.times.map { record!(model.singularize, values) }
143
152
  end
144
153
  else
145
154
  record(model, values)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 13
9
- version: 0.0.13
8
+ - 14
9
+ version: 0.0.14
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-05-11 00:00:00 +01:00
17
+ date: 2010-05-12 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency