toothbrush 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +31 -0
- data/VERSION +1 -1
- data/lib/toothbrush/helpers.rb +6 -31
- data/spec/dummy_app/page.html +21 -0
- data/spec/toothbrush_spec.rb +9 -0
- data/toothbrush.gemspec +2 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -2,6 +2,37 @@
|
|
2
2
|
|
3
3
|
Useful stuff for testing with Capybara.
|
4
4
|
|
5
|
+
== Install
|
6
|
+
|
7
|
+
Add to your gemfile:
|
8
|
+
|
9
|
+
gem 'toothbrush', group: :test
|
10
|
+
|
11
|
+
Add the file spec/support/toothbrush.rb with this content:
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include Toothbrush::Helpers
|
15
|
+
end
|
16
|
+
|
17
|
+
== Usage
|
18
|
+
|
19
|
+
For now, the only feature is ``ensure_table``.
|
20
|
+
|
21
|
+
In an integration/acceptance/whatever test using Capybara, you can ensure the
|
22
|
+
contents of a table:
|
23
|
+
|
24
|
+
ensure_table '#football-clubs-from-rio-de-janeiro-and-their-honors',
|
25
|
+
%w( Club World Libertadores Brasileiro Brasil Carioca ),
|
26
|
+
[%w( Flamengo 1 1 6 2 32 ),
|
27
|
+
%w( Vasco 0 1 4 1 22 ),
|
28
|
+
%w( Fluminense 0 0 3 1 30 ),
|
29
|
+
%w( Botafogo 0 0 1 0 19 )]
|
30
|
+
|
31
|
+
The arguments are the CSS selector for the table, an array with the table headers and
|
32
|
+
a two-dimensional array including the table content. As the example above shows,
|
33
|
+
code layout can be arranged in order to seem like a table.
|
34
|
+
|
35
|
+
|
5
36
|
== Contributing to toothbrush
|
6
37
|
|
7
38
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/toothbrush/helpers.rb
CHANGED
@@ -7,39 +7,15 @@ module Toothbrush
|
|
7
7
|
header = header_or_content
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
n = 1
|
13
|
-
while true do
|
14
|
-
begin
|
15
|
-
within("#{table_selector} thead tr th:nth-child(#{n})") do
|
16
|
-
columns[title] = n if page.has_content?(title)
|
17
|
-
n += 1
|
18
|
-
end
|
19
|
-
rescue Capybara::ElementNotFound
|
20
|
-
begin
|
21
|
-
within("#{table_selector} tr th:nth-child(#{n})") do
|
22
|
-
columns[title] = n if page.has_content?(title)
|
23
|
-
n += 1
|
24
|
-
end
|
25
|
-
rescue Capybara::ElementNotFound
|
26
|
-
break
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
columns.keys.should =~ header
|
33
|
-
|
34
|
-
content.each_with_index do |celulas, index|
|
35
|
-
celulas.each_with_index do |value, td_index|
|
10
|
+
content.each_with_index do |row, row_index|
|
11
|
+
row.each_with_index do |cell, cell_index|
|
36
12
|
begin
|
37
|
-
within("#{table_selector} tbody tr:nth-child(#{
|
38
|
-
page.should have_content(
|
13
|
+
within("#{table_selector} tbody tr:nth-child(#{row_index+1}) td:nth-child(#{cell_index+1})") do
|
14
|
+
page.should have_content(cell)
|
39
15
|
end
|
40
16
|
rescue Capybara::ElementNotFound
|
41
|
-
within("#{table_selector} tr:nth-child(#{
|
42
|
-
page.should have_content(
|
17
|
+
within("#{table_selector} tr:nth-child(#{row_index+2}) td:nth-child(#{cell_index+1})") do
|
18
|
+
page.should have_content(cell)
|
43
19
|
end
|
44
20
|
end
|
45
21
|
end
|
@@ -49,7 +25,6 @@ module Toothbrush
|
|
49
25
|
private
|
50
26
|
|
51
27
|
def _ensure_table(selector, content)
|
52
|
-
column_count = content[0].count
|
53
28
|
content.each_with_index do |row, row_index|
|
54
29
|
row.each_with_index do |cell_data, cell_index|
|
55
30
|
within("#{selector} tr:nth-child(#{row_index + 1}) td:nth-child(#{cell_index + 1})") do
|
data/spec/dummy_app/page.html
CHANGED
@@ -76,3 +76,24 @@
|
|
76
76
|
<td>6</td>
|
77
77
|
</tr>
|
78
78
|
</table>
|
79
|
+
|
80
|
+
<table id='different-th-td-number'>
|
81
|
+
<thead>
|
82
|
+
<tr>
|
83
|
+
<th>Name</th>
|
84
|
+
<th>City</th>
|
85
|
+
</tr>
|
86
|
+
</thead>
|
87
|
+
<tbody>
|
88
|
+
<tr>
|
89
|
+
<td>Americano</td>
|
90
|
+
<td>Campos</td>
|
91
|
+
<td>Destroy</td>
|
92
|
+
</tr>
|
93
|
+
<tr>
|
94
|
+
<td>Goytacaz</td>
|
95
|
+
<td>Campos</td>
|
96
|
+
<td>You can't destroy this</td>
|
97
|
+
</tr>
|
98
|
+
</tbody>
|
99
|
+
</table>
|
data/spec/toothbrush_spec.rb
CHANGED
@@ -42,5 +42,14 @@ describe "Toothbrush" do
|
|
42
42
|
%w(3 4),
|
43
43
|
%w(5 6)]
|
44
44
|
end
|
45
|
+
|
46
|
+
it 'supports tables with different <th> and <td> number' do
|
47
|
+
ensure_table '#different-th-td-number',
|
48
|
+
['Name', 'City'],
|
49
|
+
[
|
50
|
+
['Americano', 'Campos', 'Destroy'],
|
51
|
+
['Goytacaz', 'Campos', "You can't destroy this"]
|
52
|
+
]
|
53
|
+
end
|
45
54
|
end
|
46
55
|
end
|
data/toothbrush.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "toothbrush"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Rodrigo Manh\u{e3}es"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2013-02-23"
|
13
13
|
s.description = "Useful stuff for testing with Capybara"
|
14
14
|
s.email = "rmanhaes@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toothbrush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|