mattscilipoti-cucumber-rails 0.2.4
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/.gitignore +3 -0
- data/History.txt +84 -0
- data/README.rdoc +38 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/cucumber-rails.gemspec +84 -0
- data/generators/cucumber/USAGE +14 -0
- data/generators/cucumber/cucumber_generator.rb +196 -0
- data/generators/cucumber/templates/config/cucumber.yml.erb +7 -0
- data/generators/cucumber/templates/environments/cucumber.rb.erb +37 -0
- data/generators/cucumber/templates/script/cucumber +10 -0
- data/generators/cucumber/templates/step_definitions/capybara_steps.rb.erb +187 -0
- data/generators/cucumber/templates/step_definitions/web_steps_cs.rb.erb +136 -0
- data/generators/cucumber/templates/step_definitions/web_steps_de.rb.erb +136 -0
- data/generators/cucumber/templates/step_definitions/web_steps_es.rb.erb +136 -0
- data/generators/cucumber/templates/step_definitions/web_steps_no.rb.erb +114 -0
- data/generators/cucumber/templates/step_definitions/web_steps_pt-BR.rb.erb +140 -0
- data/generators/cucumber/templates/step_definitions/webrat_steps.rb.erb +258 -0
- data/generators/cucumber/templates/support/_rails_each_run.rb +29 -0
- data/generators/cucumber/templates/support/_rails_prefork.rb.erb +10 -0
- data/generators/cucumber/templates/support/capybara.rb +9 -0
- data/generators/cucumber/templates/support/edit_warning.txt +5 -0
- data/generators/cucumber/templates/support/paths.rb +27 -0
- data/generators/cucumber/templates/support/rails.rb.erb +4 -0
- data/generators/cucumber/templates/support/rails_spork.rb.erb +13 -0
- data/generators/cucumber/templates/support/webrat.rb +8 -0
- data/generators/cucumber/templates/tasks/cucumber.rake.erb +42 -0
- data/generators/feature/USAGE +12 -0
- data/generators/feature/feature_generator.rb +41 -0
- data/generators/feature/templates/feature.erb +59 -0
- data/generators/feature/templates/steps.erb +14 -0
- data/lib/cucumber/rails/action_controller.rb +65 -0
- data/lib/cucumber/rails/active_record.rb +36 -0
- data/lib/cucumber/rails/capybara_javascript_emulation.rb +61 -0
- data/lib/cucumber/rails/rspec.rb +10 -0
- data/lib/cucumber/rails/test_unit.rb +9 -0
- data/lib/cucumber/rails/world.rb +47 -0
- data/lib/cucumber/web/tableish.rb +75 -0
- data/spec/cucumber/web/tableish_spec.rb +160 -0
- data/spec/spec_helper.rb +6 -0
- data/tasks/rspec.rake +13 -0
- metadata +107 -0
@@ -0,0 +1,9 @@
|
|
1
|
+
begin
|
2
|
+
require 'test/unit/testresult'
|
3
|
+
rescue LoadError => e
|
4
|
+
e.message << "\nYou must gem install test-unit. For more info see https://rspec.lighthouseapp.com/projects/16211/tickets/292"
|
5
|
+
e.message << "\nAlso make sure you have rack 1.0.0 or higher."
|
6
|
+
raise e
|
7
|
+
end
|
8
|
+
# So that Test::Unit doesn't launch at the end - makes it think it has already been run.
|
9
|
+
Test::Unit.run = true if Test::Unit.respond_to?(:run=)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
unless defined?(Test)
|
2
|
+
begin
|
3
|
+
require 'spec/test/unit'
|
4
|
+
rescue LoadError => ignore_if_rspec_not_installed
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
if defined?(ActiveRecord::Base)
|
9
|
+
require 'test_help'
|
10
|
+
else
|
11
|
+
# I can't do rescue LoadError because in this files could be loaded
|
12
|
+
# from rails gem (ie. load actionpack 2.3.5 if rubygems are not disabled)
|
13
|
+
if Rails.version.to_f < 3.0
|
14
|
+
require 'action_controller/test_process'
|
15
|
+
require 'action_controller/integration'
|
16
|
+
else
|
17
|
+
require 'action_dispatch/testing/test_process'
|
18
|
+
require 'action_dispatch/testing/integration'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'cucumber/rails/test_unit'
|
23
|
+
require 'cucumber/rails/action_controller'
|
24
|
+
|
25
|
+
|
26
|
+
if (::Rails.respond_to?(:application) && !(::Rails.application.config.cache_classes)) ||
|
27
|
+
(!(::Rails.respond_to?(:application)) && ::Rails.respond_to?(:configuration) && !(::Rails.configuration.cache_classes))
|
28
|
+
warn "WARNING: You have set Rails' config.cache_classes to false (most likely in config/environments/cucumber.rb). This setting is known to break Cucumber's use_transactional_fixtures method. Set config.cache_classes to true if you want to use transactional fixtures. For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165."
|
29
|
+
end
|
30
|
+
|
31
|
+
module Cucumber #:nodoc:
|
32
|
+
module Rails
|
33
|
+
class World < ActionController::IntegrationTest
|
34
|
+
include ActiveSupport::Testing::SetupAndTeardown if ActiveSupport::Testing.const_defined?("SetupAndTeardown")
|
35
|
+
cattr_accessor :clean_database_after
|
36
|
+
World.clean_database_after = true
|
37
|
+
|
38
|
+
def initialize #:nodoc:
|
39
|
+
@_result = Test::Unit::TestResult.new
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
World do
|
46
|
+
Cucumber::Rails::World.new
|
47
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Cucumber
|
4
|
+
module Tableish
|
5
|
+
# This method returns an Array of Array of String, using CSS3 selectors.
|
6
|
+
# This is particularly handy when using Cucumber's Table#diff! method.
|
7
|
+
#
|
8
|
+
# The +row_selector+ argument must be a String, and picks out all the rows
|
9
|
+
# from the web page's DOM. If the number of cells in each row differs, it
|
10
|
+
# will be constrained by (or padded with) the number of cells in the first row
|
11
|
+
#
|
12
|
+
# The +column_selectors+ argument must be a String or a Proc, picking out
|
13
|
+
# cells from each row. If you pass a Proc, it will be yielded an instance
|
14
|
+
# of Nokogiri::HTML::Element.
|
15
|
+
#
|
16
|
+
# == Example with a table
|
17
|
+
#
|
18
|
+
# <table id="tools">
|
19
|
+
# <tr>
|
20
|
+
# <th>tool</th>
|
21
|
+
# <th>dude</th>
|
22
|
+
# </tr>
|
23
|
+
# <tr>
|
24
|
+
# <td>webrat</td>
|
25
|
+
# <td>bryan</td>
|
26
|
+
# </tr>
|
27
|
+
# <tr>
|
28
|
+
# <td>cucumber</td>
|
29
|
+
# <td>aslak</td>
|
30
|
+
# </tr>
|
31
|
+
# </table>
|
32
|
+
#
|
33
|
+
# t = tableish('table#tools tr', 'td,th')
|
34
|
+
#
|
35
|
+
# == Example with a dl
|
36
|
+
#
|
37
|
+
# <dl id="tools">
|
38
|
+
# <dt>webrat</dt>
|
39
|
+
# <dd>bryan</dd>
|
40
|
+
# <dt>cucumber</dt>
|
41
|
+
# <dd>aslak</dd>
|
42
|
+
# </dl>
|
43
|
+
#
|
44
|
+
# t = tableish('dl#tools dt', lambda{|dt| [dt, dt.next.next]})
|
45
|
+
#
|
46
|
+
def tableish(row_selector, column_selectors)
|
47
|
+
html = defined?(Capybara) ? body : response_body
|
48
|
+
_tableish(html, row_selector, column_selectors)
|
49
|
+
end
|
50
|
+
|
51
|
+
def _tableish(html, row_selector, column_selectors) #:nodoc
|
52
|
+
doc = Nokogiri::HTML(html)
|
53
|
+
column_count = nil
|
54
|
+
doc.search(row_selector).map do |row|
|
55
|
+
cells = case(column_selectors)
|
56
|
+
when String
|
57
|
+
row.search(column_selectors)
|
58
|
+
when Proc
|
59
|
+
column_selectors.call(row)
|
60
|
+
end
|
61
|
+
column_count ||= cells.length
|
62
|
+
(0...column_count).map do |n|
|
63
|
+
cell = cells[n]
|
64
|
+
case(cell)
|
65
|
+
when String then cell.strip
|
66
|
+
when nil then ''
|
67
|
+
else cell.text.strip
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
World(Cucumber::Tableish)
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
2
|
+
|
3
|
+
def World(*a); end
|
4
|
+
require 'cucumber/web/tableish'
|
5
|
+
|
6
|
+
module Cucumber
|
7
|
+
module Web
|
8
|
+
describe Tableish do
|
9
|
+
include Tableish
|
10
|
+
|
11
|
+
unless RUBY_PLATFORM =~ /java/
|
12
|
+
it "should convert a table" do
|
13
|
+
html = <<-HTML
|
14
|
+
<table id="tools">
|
15
|
+
<tr>
|
16
|
+
<th>tool</th>
|
17
|
+
<th>dude</th>
|
18
|
+
</tr>
|
19
|
+
<tr>
|
20
|
+
<td>webrat</td>
|
21
|
+
<td>bryan</td>
|
22
|
+
</tr>
|
23
|
+
<tr>
|
24
|
+
<td>cucumber</td>
|
25
|
+
<td>aslak</td>
|
26
|
+
</tr>
|
27
|
+
</table>
|
28
|
+
HTML
|
29
|
+
|
30
|
+
_tableish(html, 'table#tools tr', 'td,th').should == [
|
31
|
+
%w{tool dude},
|
32
|
+
%w{webrat bryan},
|
33
|
+
%w{cucumber aslak}
|
34
|
+
]
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should size to the first row" do
|
38
|
+
html = <<-HTML
|
39
|
+
<table id="tools">
|
40
|
+
<tr>
|
41
|
+
<th>tool</th>
|
42
|
+
<th>dude</th>
|
43
|
+
</tr>
|
44
|
+
<tr>
|
45
|
+
<td>webrat</td>
|
46
|
+
<td>bryan</td>
|
47
|
+
<td>crapola</td>
|
48
|
+
</tr>
|
49
|
+
<tr>
|
50
|
+
<td>cucumber</td>
|
51
|
+
<td>aslak</td>
|
52
|
+
<td>gunk</td>
|
53
|
+
<td>filth</td>
|
54
|
+
</tr>
|
55
|
+
</table>
|
56
|
+
HTML
|
57
|
+
|
58
|
+
_tableish(html, 'table#tools tr', 'td,th').should == [
|
59
|
+
%w{tool dude},
|
60
|
+
%w{webrat bryan},
|
61
|
+
%w{cucumber aslak}
|
62
|
+
]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should pad with empty Strings if some rows are shorter" do
|
66
|
+
html = <<-HTML
|
67
|
+
<table id="tools">
|
68
|
+
<tr>
|
69
|
+
<th>tool</th>
|
70
|
+
<th>dude</th>
|
71
|
+
</tr>
|
72
|
+
<tr>
|
73
|
+
<td>webrat</td>
|
74
|
+
<td>bryan</td>
|
75
|
+
</tr>
|
76
|
+
<tr>
|
77
|
+
<td>cucumber</td>
|
78
|
+
</tr>
|
79
|
+
</table>
|
80
|
+
HTML
|
81
|
+
|
82
|
+
_tableish(html, 'table#tools tr', 'td,th').should == [
|
83
|
+
%w{tool dude},
|
84
|
+
%w{webrat bryan},
|
85
|
+
['cucumber', '']
|
86
|
+
]
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should convert a dl" do
|
90
|
+
html = <<-HTML
|
91
|
+
<dl id="tools">
|
92
|
+
<dt>webrat</dt>
|
93
|
+
<dd>bryan</dd>
|
94
|
+
<dt>cucumber</dt>
|
95
|
+
<dd>aslak</dd>
|
96
|
+
</dl>
|
97
|
+
HTML
|
98
|
+
|
99
|
+
_tableish(html, 'dl#tools dt', lambda{|dt| [dt, dt.next.next]}).should == [
|
100
|
+
%w{webrat bryan},
|
101
|
+
%w{cucumber aslak}
|
102
|
+
]
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should convert a ul" do
|
106
|
+
html = <<-HTML
|
107
|
+
<ul id="phony">
|
108
|
+
<li>nope</li>
|
109
|
+
</ul>
|
110
|
+
|
111
|
+
<ul id="yes">
|
112
|
+
<li>webrat</li>
|
113
|
+
<li>bryan</li>
|
114
|
+
<li>cucumber</li>
|
115
|
+
<li>aslak</li>
|
116
|
+
</ul>
|
117
|
+
HTML
|
118
|
+
|
119
|
+
_tableish(html, 'ul#yes li', lambda{|li| [li]}).should == [
|
120
|
+
%w{webrat},
|
121
|
+
%w{bryan},
|
122
|
+
%w{cucumber},
|
123
|
+
%w{aslak},
|
124
|
+
]
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should do complex shit" do
|
128
|
+
html = <<-HTML
|
129
|
+
<form method="post" action="/invoices/10/approve" class="button-to">
|
130
|
+
<div>
|
131
|
+
<input id="approve_invoice_10" type="submit" value="Approve" />
|
132
|
+
<input name="authenticity_token" type="hidden" value="WxKGVy3Y5zcvFEiFe66D/odoc3CicfMdAup4vzQfiZ0=" />
|
133
|
+
<span>Hello World<span>
|
134
|
+
</div>
|
135
|
+
</form>
|
136
|
+
<form method="post" action="/invoices/10/delegate" class="button-to">
|
137
|
+
<div>
|
138
|
+
<input id="delegate_invoice_10" type="submit" value="Delegate" />
|
139
|
+
<input name="authenticity_token" type="hidden" value="WxKGVy3Y5zcvFEiFe66D/odoc3CicfMdAup4vzQfiZ0=" />
|
140
|
+
<span>Hi There<span>
|
141
|
+
</div>
|
142
|
+
</form>
|
143
|
+
HTML
|
144
|
+
|
145
|
+
selectors = lambda do |form|
|
146
|
+
[
|
147
|
+
form.css('div input:nth-child(1)').first.attributes['value'],
|
148
|
+
form.css('span').first.text.gsub(/\302\240/, ' ')
|
149
|
+
]
|
150
|
+
end
|
151
|
+
|
152
|
+
_tableish(html, 'form', selectors).should == [
|
153
|
+
['Approve', "Hello World"],
|
154
|
+
['Delegate', 'Hi There']
|
155
|
+
]
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
desc "Run RSpec"
|
5
|
+
Spec::Rake::SpecTask.new do |t|
|
6
|
+
t.spec_opts = %w{--color --diff --format profile}
|
7
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
8
|
+
t.rcov = ENV['RCOV']
|
9
|
+
t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/}
|
10
|
+
end
|
11
|
+
rescue LoadError
|
12
|
+
task :spec
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mattscilipoti-cucumber-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Dennis Bl\xC3\xB6te"
|
8
|
+
- "Aslak Helles\xC3\xB8y"
|
9
|
+
- Rob Holland
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2010-01-26 00:00:00 -05:00
|
15
|
+
default_executable:
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: cucumber
|
19
|
+
type: :runtime
|
20
|
+
version_requirement:
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.6.2
|
26
|
+
version:
|
27
|
+
description: Cucumber Generators and Runtime for Rails
|
28
|
+
email: cukes@googlegroups.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files:
|
34
|
+
- README.rdoc
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- History.txt
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- cucumber-rails.gemspec
|
42
|
+
- generators/cucumber/USAGE
|
43
|
+
- generators/cucumber/cucumber_generator.rb
|
44
|
+
- generators/cucumber/templates/config/cucumber.yml.erb
|
45
|
+
- generators/cucumber/templates/environments/cucumber.rb.erb
|
46
|
+
- generators/cucumber/templates/script/cucumber
|
47
|
+
- generators/cucumber/templates/step_definitions/capybara_steps.rb.erb
|
48
|
+
- generators/cucumber/templates/step_definitions/web_steps_cs.rb.erb
|
49
|
+
- generators/cucumber/templates/step_definitions/web_steps_de.rb.erb
|
50
|
+
- generators/cucumber/templates/step_definitions/web_steps_es.rb.erb
|
51
|
+
- generators/cucumber/templates/step_definitions/web_steps_no.rb.erb
|
52
|
+
- generators/cucumber/templates/step_definitions/web_steps_pt-BR.rb.erb
|
53
|
+
- generators/cucumber/templates/step_definitions/webrat_steps.rb.erb
|
54
|
+
- generators/cucumber/templates/support/_rails_each_run.rb
|
55
|
+
- generators/cucumber/templates/support/_rails_prefork.rb.erb
|
56
|
+
- generators/cucumber/templates/support/capybara.rb
|
57
|
+
- generators/cucumber/templates/support/edit_warning.txt
|
58
|
+
- generators/cucumber/templates/support/paths.rb
|
59
|
+
- generators/cucumber/templates/support/rails.rb.erb
|
60
|
+
- generators/cucumber/templates/support/rails_spork.rb.erb
|
61
|
+
- generators/cucumber/templates/support/webrat.rb
|
62
|
+
- generators/cucumber/templates/tasks/cucumber.rake.erb
|
63
|
+
- generators/feature/USAGE
|
64
|
+
- generators/feature/feature_generator.rb
|
65
|
+
- generators/feature/templates/feature.erb
|
66
|
+
- generators/feature/templates/steps.erb
|
67
|
+
- lib/cucumber/rails/action_controller.rb
|
68
|
+
- lib/cucumber/rails/active_record.rb
|
69
|
+
- lib/cucumber/rails/capybara_javascript_emulation.rb
|
70
|
+
- lib/cucumber/rails/rspec.rb
|
71
|
+
- lib/cucumber/rails/test_unit.rb
|
72
|
+
- lib/cucumber/rails/world.rb
|
73
|
+
- lib/cucumber/web/tableish.rb
|
74
|
+
- spec/cucumber/web/tableish_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
- tasks/rspec.rake
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: http://github.com/aslakhellesoy/cucumber-rails
|
79
|
+
licenses: []
|
80
|
+
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options:
|
83
|
+
- --charset=UTF-8
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
version:
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: "0"
|
97
|
+
version:
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.3.5
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Cucumber Generators and Runtime for Rails
|
105
|
+
test_files:
|
106
|
+
- spec/cucumber/web/tableish_spec.rb
|
107
|
+
- spec/spec_helper.rb
|