forked from cucumber/cucumber-rails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b79b22
commit 2a12bb4
Showing
7 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
== In Git | ||
|
||
=== New features | ||
* New #tableish method to extract table-like data from a HTML page. Pure Nokogiri/CSS3/XPath. (Aslak Hellesøy) | ||
|
||
=== Bugfixes | ||
* Make #element_at / #table_at work on Webrat 0.6.0. This is now deprecated it in favour of #tableish. (Aslak Hellesøy) | ||
* Webrat step "Then I should be on" should use request_uri instead of path for missing query string parameters (ZhangJinzhu) | ||
* Added MIME type parameter to attach file step definition (Felix Flores) | ||
* Added check when including ActiveSupport::Testing::SetupAndTeardown for older Rails versions (Jeremy Durham) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'nokogiri' | ||
|
||
module Cucumber | ||
module Tableish | ||
def tableish(row_selector, column_selectors) | ||
_tableish(response_body, row_selector, column_selectors) | ||
end | ||
|
||
def _tableish(html, row_selector, column_selectors) | ||
doc = Nokogiri::HTML(html) | ||
column_count = nil | ||
doc.search(row_selector).map do |row| | ||
cells = case(column_selectors) | ||
when String | ||
row.search(column_selectors) | ||
when Proc | ||
column_selectors.call(row) | ||
end | ||
column_count ||= cells.length | ||
cells[0...column_count].map do |cell| | ||
cell.text.strip | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") | ||
require 'cucumber/web/tableish' | ||
|
||
module Cucumber | ||
module Web | ||
describe Tableish do | ||
include Tableish | ||
|
||
unless RUBY_PLATFORM =~ /java/ | ||
it "should convert a table" do | ||
html = <<-HTML | ||
<table> | ||
<tr> | ||
<th>tool</th> | ||
<th>dude</th> | ||
</tr> | ||
<tr> | ||
<td>webrat</td> | ||
<td>bryan</td> | ||
</tr> | ||
<tr> | ||
<td>cucumber</td> | ||
<td>aslak</td> | ||
</tr> | ||
</table> | ||
HTML | ||
|
||
_tableish(html, 'table tr', 'td,th').should == [ | ||
%w{tool dude}, | ||
%w{webrat bryan}, | ||
%w{cucumber aslak} | ||
] | ||
end | ||
|
||
it "should size to the first row" do | ||
html = <<-HTML | ||
<table> | ||
<tr> | ||
<th>tool</th> | ||
<th>dude</th> | ||
</tr> | ||
<tr> | ||
<td>webrat</td> | ||
<td>bryan</td> | ||
<td>crapola</td> | ||
</tr> | ||
<tr> | ||
<td>cucumber</td> | ||
<td>aslak</td> | ||
<td>gunk</td> | ||
<td>filth</td> | ||
</tr> | ||
</table> | ||
HTML | ||
|
||
_tableish(html, 'table tr', 'td,th').should == [ | ||
%w{tool dude}, | ||
%w{webrat bryan}, | ||
%w{cucumber aslak} | ||
] | ||
end | ||
|
||
it "should convert a dl" do | ||
html = <<-HTML | ||
<dl> | ||
<dt>webrat</dt> | ||
<dd>bryan</dd> | ||
<dt>cucumber</dt> | ||
<dd>aslak</dd> | ||
</dl> | ||
HTML | ||
|
||
_tableish(html, 'dl dt', lambda{|dt| [dt, dt.next.next]}).should == [ | ||
%w{webrat bryan}, | ||
%w{cucumber aslak} | ||
] | ||
end | ||
|
||
it "should convert a ul" do | ||
html = <<-HTML | ||
<ul id="phony"> | ||
<li>nope</li> | ||
</ul> | ||
<ul id="yes"> | ||
<li>webrat</li> | ||
<li>bryan</li> | ||
<li>cucumber</li> | ||
<li>aslak</li> | ||
</ul> | ||
HTML | ||
|
||
_tableish(html, 'ul#yes li', lambda{|li| [li]}).should == [ | ||
%w{webrat}, | ||
%w{bryan}, | ||
%w{cucumber}, | ||
%w{aslak}, | ||
] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'rubygems' | ||
gem 'rspec' | ||
require 'spec' | ||
require 'spec/autorun' | ||
|
||
$:.unshift(File.dirname(__FILE__) + '/../lib') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
begin | ||
require 'spec/rake/spectask' | ||
|
||
desc "Run RSpec" | ||
Spec::Rake::SpecTask.new do |t| | ||
t.spec_opts = %w{--color --diff --format profile} | ||
t.spec_files = FileList['spec/**/*_spec.rb'] | ||
t.rcov = ENV['RCOV'] | ||
t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/} | ||
end | ||
rescue LoadError | ||
task :spec | ||
end |