kelp 0.1.2 → 0.1.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/Gemfile.lock CHANGED
@@ -3,6 +3,7 @@ PATH
3
3
  specs:
4
4
  kelp (0.1.2)
5
5
  capybara (>= 0.4.0)
6
+ webrat
6
7
 
7
8
  GEM
8
9
  remote: http://rubygems.org/
@@ -83,6 +84,10 @@ GEM
83
84
  thor (0.14.6)
84
85
  tilt (1.1)
85
86
  tzinfo (0.3.23)
87
+ webrat (0.7.3)
88
+ nokogiri (>= 1.2.0)
89
+ rack (>= 1.0)
90
+ rack-test (>= 0.5.3)
86
91
  xpath (0.1.2)
87
92
  nokogiri (~> 1.3)
88
93
 
@@ -97,3 +102,4 @@ DEPENDENCIES
97
102
  rspec (>= 2.2.0)
98
103
  rspec-rails
99
104
  sinatra
105
+ webrat
data/History.md CHANGED
@@ -1,6 +1,13 @@
1
1
  Kelp History
2
2
  ============
3
3
 
4
+ 0.1.3
5
+ -----
6
+
7
+ - Fixed single-quote escaping issue in table rows and dropdowns
8
+ - Began adding Webrat support (still untested and not fully implemented)
9
+
10
+
4
11
  0.1.2
5
12
  -----
6
13
 
data/README.md CHANGED
@@ -13,6 +13,8 @@ short, easy to remember, and is in keeping with the theme of greenish plants.
13
13
  Kelp is licensed under the
14
14
  [MIT License](http://www.opensource.org/licenses/mit-license.php).
15
15
 
16
+ Documentation is
17
+ [available on rdoc.info](http://rdoc.info/github/wapcaplet/kelp/master/frames).
16
18
  Please use the [issue tracker](http://github.com/wapcaplet/kelp/issues)
17
19
  to report any bugs or feature requests. Visit the `#kelp` channel on
18
20
  `irc.freenode.net` to chat.
@@ -87,12 +89,17 @@ you pass to this should be in whatever format your `Capybara.default_selector`
87
89
  is set to. Other keywords like `:before` or `:after` may be supported in future
88
90
  revisions.
89
91
 
92
+ See the
93
+ [kelp documentation](http://rdoc.info/github/wapcaplet/kelp/master/frames).
94
+ for more information.
95
+
90
96
 
91
97
  Development
92
98
  -----------
93
99
 
94
- If you'd like to hack on Kelp, first fork the {http://github.com/wapcaplet/kelp
95
- repository}, then clone your fork:
100
+ If you'd like to hack on Kelp, first fork the
101
+ [repository](http://github.com/wapcaplet/kelp),
102
+ then clone your fork:
96
103
 
97
104
  $ git clone git://github.com/your_username/kelp.git
98
105
 
@@ -100,7 +107,7 @@ Install [bundler](http://gembundler.com/):
100
107
 
101
108
  $ gem install bundler
102
109
 
103
- Then install Kelp's dependencies (specified in `Gemfile`):
110
+ Then install Kelp's dependencies:
104
111
 
105
112
  $ cd /path/to/kelp
106
113
  $ bundle install
data/kelp.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "kelp"
5
- s.version = "0.1.2"
5
+ s.version = "0.1.3"
6
6
  s.summary = "Cucumber helper methods"
7
7
  s.description = <<-EOS
8
8
  Kelp is a collection of helper methods for Cucumber to ease the process of
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.platform = Gem::Platform::RUBY
15
15
 
16
16
  s.add_dependency 'capybara', '>= 0.4.0'
17
+ s.add_dependency 'webrat'
17
18
 
18
19
  s.add_development_dependency 'sinatra'
19
20
  s.add_development_dependency 'rspec', '>= 2.2.0'
data/lib/kelp.rb CHANGED
@@ -6,3 +6,21 @@ require 'kelp/navigation'
6
6
  require 'kelp/scoping'
7
7
  require 'kelp/visibility'
8
8
 
9
+ module Kelp
10
+ class << self
11
+ attr_writer :driver
12
+
13
+ # @return [Symbol]
14
+ # Name of the default driver used by Kelp
15
+ def default_driver
16
+ :capybara
17
+ end
18
+
19
+ # @return [Symbol]
20
+ # Name of the current driver used by Kelp (:capybara or :webrat)
21
+ def driver
22
+ @driver || default_driver
23
+ end
24
+ end
25
+ end
26
+
data/lib/kelp/dropdown.rb CHANGED
@@ -27,7 +27,8 @@ module Kelp
27
27
  selected = field.find(:xpath, ".//option[@selected='selected']")
28
28
  # If not, find the option matching the first field value
29
29
  rescue Capybara::ElementNotFound
30
- selected = field.find(:xpath, ".//option[@value='#{field.value.first}']")
30
+ first_value = xpath_sanitize(field.value.first)
31
+ selected = field.find(:xpath, ".//option[@value=#{first_value}]")
31
32
  end
32
33
  selected.text.should =~ /#{value}/
33
34
  end
@@ -56,7 +57,7 @@ module Kelp
56
57
  field = nice_find_field(dropdown)
57
58
  # Look for each value
58
59
  values.each do |value|
59
- page.should have_xpath(".//option[text()='#{value}']")
60
+ page.should have_xpath(".//option[text()=#{xpath_sanitize(value)}]")
60
61
  end
61
62
  end
62
63
  end
@@ -83,7 +84,7 @@ module Kelp
83
84
  field = nice_find_field(dropdown)
84
85
  # Look for each value
85
86
  values.each do |value|
86
- page.should have_no_xpath(".//option[text()='#{value}']")
87
+ page.should have_no_xpath(".//option[text()=#{xpath_sanitize(value)}]")
87
88
  end
88
89
  end
89
90
  end
@@ -89,10 +89,20 @@ module Kelp
89
89
  # Content you expect to be on the page
90
90
  #
91
91
  def page_should_contain_text(text)
92
- if page.respond_to? :should
93
- page.should have_content(text)
92
+ if Kelp.driver == :capybara
93
+ if page.respond_to? :should
94
+ page.should have_content(text)
95
+ else
96
+ assert page.has_content?(text)
97
+ end
98
+ elsif Kelp.driver == :webrat
99
+ if defined?(Spec::Rails::Matchers)
100
+ response.should contain(text)
101
+ else
102
+ assert_contain text
103
+ end
94
104
  else
95
- assert page.has_content?(text)
105
+ raise RuntimeError, "Unsupported driver: #{Kelp.driver}"
96
106
  end
97
107
  end
98
108
 
@@ -103,10 +113,20 @@ module Kelp
103
113
  # Content you expect to match
104
114
  #
105
115
  def page_should_contain_regexp(regexp)
106
- if page.respond_to? :should
107
- page.should have_xpath('.//*', :text => regexp)
116
+ if Kelp.driver == :capybara
117
+ if page.respond_to? :should
118
+ page.should have_xpath('.//*', :text => regexp)
119
+ else
120
+ assert page.has_xpath?('.//*', :text => regexp)
121
+ end
122
+ elsif Kelp.driver == :webrat
123
+ if defined?(Spec::Rails::Matchers)
124
+ response.should contain(regexp)
125
+ else
126
+ assert_match(regexp, response_body)
127
+ end
108
128
  else
109
- assert page.has_xpath?('.//*', :text => regexp)
129
+ raise RuntimeError, "Unsupported driver: #{Kelp.driver}"
110
130
  end
111
131
  end
112
132
 
@@ -117,10 +137,21 @@ module Kelp
117
137
  # Content you expect to be missing from the page
118
138
  #
119
139
  def page_should_not_contain_text(text)
120
- if page.respond_to? :should
121
- page.should have_no_content(text)
140
+ if Kelp.driver == :capybara
141
+ if page.respond_to? :should
142
+ page.should have_no_content(text)
143
+ else
144
+ assert page.has_no_content?(text)
145
+ end
146
+ elsif Kelp.driver == :webrat
147
+ if defined?(Spec::Rails::Matchers)
148
+ response.should_not contain(text)
149
+ else
150
+ hc = Webrat::Matchers::HasContent.new(text)
151
+ assert !hc.matches?(content), hc.negative_failure_message
152
+ end
122
153
  else
123
- assert page.has_no_content?(text)
154
+ raise RuntimeError, "Unsupported driver: #{Kelp.driver}"
124
155
  end
125
156
  end
126
157
 
@@ -131,10 +162,20 @@ module Kelp
131
162
  # Content you expect to fail matching
132
163
  #
133
164
  def page_should_not_contain_regexp(regexp)
134
- if page.respond_to? :should
135
- page.should have_no_xpath('.//*', :text => regexp)
165
+ if Kelp.driver == :capybara
166
+ if page.respond_to? :should
167
+ page.should have_no_xpath('.//*', :text => regexp)
168
+ else
169
+ assert page.has_no_xpath?('.//*', :text => regexp)
170
+ end
171
+ elsif Kelp.driver == :webrat
172
+ if defined?(Spec::Rails::Matchers)
173
+ response.should_not contain(regexp)
174
+ else
175
+ assert_not_contain(regexp)
176
+ end
136
177
  else
137
- assert page.has_no_xpath?('.//*', :text => regexp)
178
+ raise RuntimeError, "Unsupported driver: #{Kelp.driver}"
138
179
  end
139
180
  end
140
181
 
@@ -152,7 +193,11 @@ module Kelp
152
193
  # Array of Strings that should appear in the same row
153
194
  #
154
195
  def should_see_in_same_row(texts)
155
- page.should have_xpath(xpath_row_containing(texts))
196
+ if Kelp.driver == :capybara
197
+ page.should have_xpath(xpath_row_containing(texts))
198
+ elsif Kelp.driver == :webrat
199
+ raise RuntimeError, "Not implemented yet"
200
+ end
156
201
  end
157
202
 
158
203
 
@@ -168,9 +213,12 @@ module Kelp
168
213
  # Array of Strings that should not appear in the same row
169
214
  #
170
215
  def should_not_see_in_same_row(texts)
171
- page.should have_no_xpath(xpath_row_containing(texts))
216
+ if Kelp.driver == :capybara
217
+ page.should have_no_xpath(xpath_row_containing(texts))
218
+ elsif Kelp.driver == :webrat
219
+ raise RuntimeError, "Not implemented yet"
220
+ end
172
221
  end
173
222
 
174
-
175
223
  end
176
224
  end
data/lib/kelp/xpath.rb CHANGED
@@ -6,9 +6,27 @@ module Kelp
6
6
  def xpath_row_containing(texts)
7
7
  texts = [texts] if texts.class == String
8
8
  conditions = texts.collect do |text|
9
- "contains(., '#{text}')"
9
+ "contains(., #{xpath_sanitize(text)})"
10
10
  end.join(' and ')
11
11
  return "//table//tr[#{conditions}]"
12
12
  end
13
+
14
+ # Return the given text string in an XPath-safe form, with
15
+ # any single-quotes escaped by using the XPath `concat`
16
+ # function to combine them with the rest of the text.
17
+ #
18
+ # @example
19
+ # xpath_sanitize("Bob's")
20
+ # # => concat('Bob', "'", 's')
21
+ #
22
+ def xpath_sanitize(text)
23
+ # If there's nothing to escape, just wrap text in single-quotes
24
+ if !text.include?("'")
25
+ return "'#{text}'"
26
+ else
27
+ result = text.gsub(/'/, %{', "'", '})
28
+ return "concat('#{result}')"
29
+ end
30
+ end
13
31
  end
14
32
  end
@@ -59,6 +59,12 @@ describe Kelp::Dropdown, "dropdown_should_include" do
59
59
  dropdown_should_include "Height", "Tall"
60
60
  end
61
61
 
62
+ it "a single option with quotes exists in the dropdown" do
63
+ dropdown_should_include "Quotes", %{Single 'quotes'}
64
+ dropdown_should_include "Quotes", %{"Double" quotes}
65
+ dropdown_should_include "Quotes", %{'Single' and "Double" quotes}
66
+ end
67
+
62
68
  it "multiple options exist in the dropdown" do
63
69
  dropdown_should_include "Height", [
64
70
  "Short",
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,17 @@
1
1
  require 'rspec'
2
+
3
+ # Supported drivers
2
4
  require 'capybara'
3
5
  require 'capybara/dsl'
6
+ #require 'webrat'
7
+
4
8
  require 'kelp'
5
9
  require File.expand_path(File.dirname(__FILE__) + '/test_app/test_app')
6
10
 
7
11
  RSpec.configure do |config|
8
12
  config.include Capybara
13
+ #config.include Webrat::Methods
14
+
9
15
  config.include Kelp::Attribute
10
16
  config.include Kelp::Checkbox
11
17
  config.include Kelp::Dropdown
@@ -13,14 +19,21 @@ RSpec.configure do |config|
13
19
  config.include Kelp::Navigation
14
20
  config.include Kelp::Scoping
15
21
  config.include Kelp::Visibility
16
- config.after do
17
- Capybara.reset_sessions!
18
- Capybara.use_default_driver
19
- end
22
+
20
23
  config.before do
24
+ #Kelp.driver = :webrat
21
25
  Capybara.default_driver = :rack_test
22
26
  Capybara.default_selector = :css
23
27
  Capybara.app = TestApp
24
28
  end
29
+
30
+ config.after do
31
+ Capybara.reset_sessions!
32
+ Capybara.use_default_driver
33
+ end
25
34
  end
26
35
 
36
+ #Webrat.configure do |config|
37
+ #config.mode = :rack
38
+ #end
39
+
@@ -29,6 +29,14 @@
29
29
  <option value="3">Heavy</option>
30
30
  </select>
31
31
  </p>
32
+ <p>
33
+ <label for="quotes">Quotes</label>
34
+ <select id="quotes">
35
+ <option value="1">Single 'quotes'</option>
36
+ <option value="2">"Double" quotes</option>
37
+ <option value="3">'Single' and "Double" quotes</option>
38
+ </select>
39
+ </p>
32
40
  <p>
33
41
  <label for="favorite_colors">Favorite Colors</label>
34
42
  <select id="favorite_colors" multiple="multiple">
@@ -33,6 +33,10 @@
33
33
  <tr> <td>Eric</td> <td>555-4444</td> <td><a href="/edit1">Edit</a></td> </tr>
34
34
  <tr> <td>John</td> <td>666-5555</td> <td><a href="/edit2">Edit</a></td> </tr>
35
35
  <tr> <td>Terry</td> <td>777-6666</td> <td><a href="/edit3">Edit</a></td> </tr>
36
+
37
+ <tr> <td>Eric "Quoted"</td> <td>555-4444</td> <td><a href="/edit1">Edit</a></td> </tr>
38
+ <tr> <td>"John's" quo'ta'tions</td> <td>666-5555</td> <td><a href="/edit2">Edit</a></td> </tr>
39
+ <tr> <td>Terry's "Big" thing</td> <td>777-6666</td> <td><a href="/edit3">Edit</a></td> </tr>
36
40
  </tbody>
37
41
  </table>
38
42
  </div>
@@ -183,13 +183,17 @@ describe Kelp::Visibility, "should_see_in_same_row" do
183
183
  it "two strings are in the same row" do
184
184
  should_see_in_same_row ["Eric", "Edit"]
185
185
  should_see_in_same_row ["John", "Edit"]
186
- should_see_in_same_row ["Terry", "Edit"]
186
+ end
187
+
188
+ it "two strings are in the same row, and one has single and/or double-quotes" do
189
+ should_see_in_same_row [%{Eric "Quoted"}, "Edit"]
190
+ should_see_in_same_row [%{"John's" quo'ta'tions}, "Edit"]
191
+ should_see_in_same_row [%{Terry's "Big" thing}, "Edit"]
187
192
  end
188
193
 
189
194
  it "three strings are in the same row" do
190
195
  should_see_in_same_row ["Eric", "555-4444", "Edit"]
191
196
  should_see_in_same_row ["John", "666-5555", "Edit"]
192
- should_see_in_same_row ["Terry", "777-6666", "Edit"]
193
197
  end
194
198
  end
195
199
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eric Pierce
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-11 00:00:00 -07:00
18
+ date: 2011-04-06 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -35,7 +35,7 @@ dependencies:
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: sinatra
38
+ name: webrat
39
39
  prerelease: false
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
@@ -46,12 +46,26 @@ dependencies:
46
46
  segments:
47
47
  - 0
48
48
  version: "0"
49
- type: :development
49
+ type: :runtime
50
50
  version_requirements: *id002
51
51
  - !ruby/object:Gem::Dependency
52
- name: rspec
52
+ name: sinatra
53
53
  prerelease: false
54
54
  requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: rspec
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
55
69
  none: false
56
70
  requirements:
57
71
  - - ">="
@@ -63,11 +77,11 @@ dependencies:
63
77
  - 0
64
78
  version: 2.2.0
65
79
  type: :development
66
- version_requirements: *id003
80
+ version_requirements: *id004
67
81
  - !ruby/object:Gem::Dependency
68
82
  name: rspec-rails
69
83
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
84
+ requirement: &id005 !ruby/object:Gem::Requirement
71
85
  none: false
72
86
  requirements:
73
87
  - - ">="
@@ -77,11 +91,11 @@ dependencies:
77
91
  - 0
78
92
  version: "0"
79
93
  type: :development
80
- version_requirements: *id004
94
+ version_requirements: *id005
81
95
  - !ruby/object:Gem::Dependency
82
96
  name: rcov
83
97
  prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
98
+ requirement: &id006 !ruby/object:Gem::Requirement
85
99
  none: false
86
100
  requirements:
87
101
  - - ">="
@@ -91,7 +105,7 @@ dependencies:
91
105
  - 0
92
106
  version: "0"
93
107
  type: :development
94
- version_requirements: *id005
108
+ version_requirements: *id006
95
109
  description: " Kelp is a collection of helper methods for Cucumber to ease the process of\n writing step definitions.\n"
96
110
  email: wapcaplet88@gmail.com
97
111
  executables: []