html_matchers 0.0.1

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.
@@ -0,0 +1,77 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'table_body_matcher' do
4
+ describe 'with <tbody> element' do
5
+ it 'should find body rows' do
6
+ response = mock_model(Object, :body => '<table id="my_id"><tbody><tr><td>c1</td><td>c2</td></tr></tbody></table>')
7
+ response.should have_table_body('my_id', [['c1', 'c2']])
8
+ end
9
+ end
10
+
11
+ describe 'without <tbody> element' do
12
+ it 'should not require <tbody>' do
13
+ response = mock_model(Object, :body => '<table id="my_id"><tr><td>c1</td><td>c2</td></tr></table>')
14
+ response.should have_table_body('my_id', [['c1', 'c2']])
15
+ end
16
+
17
+ describe 'with extraneous multiline whitespace' do
18
+ it 'should remove extraneous whitespace' do
19
+ response = mock_model(Object, :body => "<table id='my_id'><tr><td>\n c1a\n \t<br/> \tc1b</td><td>c2</td></tr></table>")
20
+ response.should have_table_body('my_id', [["c1a\nc1b", 'c2']])
21
+ end
22
+ end
23
+
24
+ it 'should ignore header row' do
25
+ response = mock_model(Object, :body => '<table id="my_id"><tr><th>h1</th><th>h2</th></tr><tr><td>c1</td><td>c2</td></tr></table>')
26
+ response.should have_table_body('my_id', [['c1', 'c2']])
27
+ end
28
+ end
29
+
30
+ it 'can be called without a table_id' do
31
+ response = mock_model(Object, :body => '<table><tr><td>c1</td><td>c2</td></tr></table>')
32
+ response.should have_table_body([['c1', 'c2']])
33
+ end
34
+
35
+ it 'matches multiple body rows' do
36
+ response = mock_model(Object, :body => '<table><tr><td>c1</td><td>c2</td></tr><tr><td>c3</td><td>c4</td></tr></table>')
37
+ response.should have_table_body([['c1', 'c2'], ['c3', 'c4']])
38
+ end
39
+
40
+ describe 'passed wrong id' do
41
+ it 'should not match' do
42
+ response = mock_model(Object, :body => '<table id="my_id"><tr><td>c1</td><td>c2</td></tr></table>')
43
+ response.should_not have_table_body('wrong_id', [['c1', 'c2']])
44
+ end
45
+ end
46
+
47
+ describe 'passed non-matching expected' do
48
+ it 'should not match' do
49
+ response = mock_model(Object, :body => '<table id="my_id"><tr><td>c1</td><td>c2</td></tr></table>')
50
+ response.should_not have_table_body('my_id', [['c3', 'c2']])
51
+ end
52
+ end
53
+
54
+ describe 'with normal failure' do
55
+ it 'should raise ExpectationNotMetError with correct message' do
56
+ response = mock_model Object, :body => 'Some non-matching HTML'
57
+ lambda do
58
+ response.should have_table_body('my_id', [['c1', 'c2']])
59
+ end.should raise_error(Spec::Expectations::ExpectationNotMetError, "\nWrong table body contents.\nexpected: [[\"c1\", \"c2\"]]\n found: []\n\n")
60
+ end
61
+ end
62
+
63
+ describe 'with negative failure' do
64
+ it 'should raise ExpectationNotMetError' do
65
+ response = mock_model Object, :body => '<table id="my_id"><tr><td>c1</td><td>c2</td></tr></table>'
66
+ lambda{response.should_not have_table_body('my_id', [['c1', 'c2']])}.should raise_error(Spec::Expectations::ExpectationNotMetError,
67
+ "\nTable body should not have matched: [[\"c1\", \"c2\"]]\n")
68
+ end
69
+ end
70
+
71
+ describe 'passed nil expected' do
72
+ it 'should raise error' do
73
+ response = mock_model(Object, :body => '<table id="my_id"><tr><td>c1</td><td>c2</td></tr></table>')
74
+ lambda{ response.should have_table_body('my_id', nil)}.should raise_error(RuntimeError, 'Invalid "expected" argument')
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,111 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'table_header_matcher' do
4
+ describe 'with <thead> element' do
5
+ it 'should have headers' do
6
+ verify_table_header_match 'my_id', '<table id="my_id"><thead><tr><th>h1</th><th>h2</th></tr></thead></table>', [['h1', 'h2']]
7
+ end
8
+ end
9
+
10
+ describe 'without <thead> element' do
11
+ it 'should not require <thead>' do
12
+ verify_table_header_match 'my_id', '<table id="my_id"><tr><th>h1</th><th>h2</th></tr></table>', [['h1', 'h2']]
13
+ end
14
+
15
+ it 'should ignore regular row' do
16
+ verify_table_header_match 'my_id',
17
+ '<table id="my_id"><tr><th>h1</th><th>h2</th></tr><tr><td>"regular"</td><td>"row"</td></tr></table>',
18
+ [['h1', 'h2']]
19
+ end
20
+
21
+ it 'should handle multiple header rows' do
22
+ verify_table_header_match 'my_id',
23
+ '<table id="my_id"><tr><th>h1</th><th>h2</th></tr><tr><th>h3</th><th>h4</th></tr><tr><td>"regular"</td><td>"row"</td></tr></table>',
24
+ [['h1', 'h2'], ['h3', 'h4']]
25
+ end
26
+
27
+ it 'should match "<br/>" to "\n"' do
28
+ verify_table_header_match 'my_id',
29
+ '<table id="my_id"><tr><th>h1 - row 1<br/>h1 - row 2</th></tr></table>',
30
+ [["h1 - row 1\nh1 - row 2"]]
31
+ end
32
+
33
+ it 'should match "<br />" to "\n"' do
34
+ verify_table_header_match 'my_id',
35
+ "<table id='my_id'><tr><th>h1 - row 1<br />h1 - row 2</th></tr></table>",
36
+ [["h1 - row 1\nh1 - row 2"]]
37
+ end
38
+
39
+ it 'should throw away any amount of white space around a br element' do
40
+ verify_table_header_match 'my_id',
41
+ "<table id='my_id'><tr><th>h1 - row 1 <br/>\t\th1 - row 2</th></tr></table>",
42
+ [["h1 - row 1\nh1 - row 2"]]
43
+ end
44
+
45
+ it 'should throw away any amount of white space spanning new lines' do
46
+ verify_table_header_match 'my_id',
47
+ "<table id='my_id'><tr><th>h1 - row 1 \n <br/>\n \t\th1 - row 2</th></tr></table>",
48
+ [["h1 - row 1\nh1 - row 2"]]
49
+ end
50
+ end
51
+
52
+ describe 'passed wrong id' do
53
+ it 'should not have header' do
54
+ verify_no_header_match 'wrong_id', '<table id="my_id"><tr><th>h1</th><th>h2</th></tr></table>', [['h1', 'h2']]
55
+ end
56
+ end
57
+
58
+ describe 'with normal failure' do
59
+ it 'should raise ExpectationNotMetError with correct message' do
60
+ response = mock_model Object, :body => 'Some non-matching HTML'
61
+ lambda do
62
+ response.should have_table_header('id', [['h1', 'h2']])
63
+ end.should raise_error(Spec::Expectations::ExpectationNotMetError, "\nWrong table header contents.\nexpected: [[\"h1\", \"h2\"]]\n found: []\n\n")
64
+ end
65
+ end
66
+
67
+ describe 'with negative failure' do
68
+ it 'should raise ExpectationNotMetError' do
69
+ response = mock_model Object, :body => '<table id="my_id"><tr><th>h1</th><th>h2</th></tr></table>'
70
+ lambda{response.should_not have_table_header('my_id', [['h1', 'h2']])}.should raise_error(Spec::Expectations::ExpectationNotMetError,
71
+ "\nTable header should not have matched: [[\"h1\", \"h2\"]]\n")
72
+ end
73
+ end
74
+
75
+ describe 'passed nil expected' do
76
+ it 'should raise error' do
77
+ response = mock_model(Object, :body => '<table id="my_id"><tr><th>h1</th><th>h2</th></tr></table>')
78
+ lambda{ response.should have_table_header('my_id', nil)}.should raise_error(RuntimeError, 'Invalid "expected" argument')
79
+ end
80
+ end
81
+
82
+ describe 'called from nil response object' do
83
+ it 'should raise error' do
84
+ lambda{ nil.should have_table_header('my_id', [['h1', 'h2']]) }.should raise_error(NoMethodError,
85
+ "You have a nil object when you didn't expect it!\nThe error occurred while evaluating nil.body")
86
+ end
87
+ end
88
+
89
+ describe 'when headers don\'t match' do
90
+ it 'should not match' do
91
+ verify_no_header_match 'my_id', '<table id="my_id"><tr><th>h1</th><th>h2</th></tr></table>', [['h1', 'h3']]
92
+ end
93
+ end
94
+
95
+ it "doesn't require table_id" do
96
+ response = mock_model Object, :body => '<table id="my_id"><tr><th>h1</th><th>h2</th></tr></table>'
97
+ response.should have_table_header([['h1', 'h2']])
98
+ end
99
+
100
+ private
101
+
102
+ def verify_table_header_match id, html, expected
103
+ response = mock_model Object, :body => html
104
+ response.should have_table_header(id, expected)
105
+ end
106
+
107
+ def verify_no_header_match id, html, expected
108
+ response = mock_model Object, :body => html
109
+ response.should_not have_table_header(id, expected)
110
+ end
111
+ end
@@ -0,0 +1,117 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'table_matcher' do
4
+ describe 'with <thead> and <tbody> elements' do
5
+ it 'should find header and body rows' do
6
+ response = mock_model(Object, :body => '<table id="my_id"><thead><tr><th>h1</th><th>h2</th></tr></thead><tbody><tr><td>c1</td><td>c2</td></tr></tbody></table>')
7
+ response.should have_table('#my_id', [['h1', 'h2'], ['c1', 'c2']])
8
+ end
9
+ end
10
+
11
+ describe 'without <thead> and <tbody> elements' do
12
+ it 'should work' do
13
+ response = mock_model(Object, :body => '<table id="my_id"><tr><th>h1</th><th>h2</th></tr><tr><td>c1</td><td>c2</td></tr></table>')
14
+ response.should have_table('#my_id', [['h1', 'h2'], ['c1', 'c2']])
15
+ end
16
+
17
+ describe 'with extraneous multiline whitespace' do
18
+ it 'should remove extraneous whitespace' do
19
+ response = mock_model(Object, :body => "<table id=\"my_id\"><tr><th>h1</th><th>h2</th></tr><tr><td>\n c1a\n \t<br/> \tc1b</td><td>c2</td></tr></table>")
20
+ response.should have_table('#my_id', [['h1', 'h2'], ["c1a\nc1b", 'c2']])
21
+ end
22
+ end
23
+
24
+ describe 'with inline script tags in a header cell' do
25
+ it "should suppress script content" do
26
+ response = mock_model(Object, :body => '<table id="my_id"><tr><th>h1</th><th>h2a<script type="text/javascript">
27
+ //<![CDATA[
28
+ x = 1;
29
+ //]]>
30
+ </script>
31
+ h2b</th></tr><tr><td>c1</td><td>c2</td></tr></table>')
32
+ response.should have_table('#my_id', [['h1', "h2a\nh2b"], ["c1", "c2"]])
33
+ end
34
+ end
35
+
36
+ describe 'with inline script tags in a cell' do
37
+ it "should suppress script content" do
38
+ response = mock_model(Object, :body => '<table id="my_id"><tr><th>h1</th><th>h2</th></tr><tr><td>c1a<script type="text/javascript">
39
+ //<![CDATA[
40
+ x = 1;
41
+ //]]>
42
+ </script>
43
+ c1b</td></tr></table>')
44
+ response.should have_table('#my_id', [['h1', 'h2'], ["c1a\nc1b"]])
45
+ end
46
+ end
47
+ end
48
+
49
+ it 'can be called without a table_id' do
50
+ response = mock_model(Object, :body => '<table><tr><td>c1</td><td>c2</td></tr></table>')
51
+ response.should have_table([['c1', 'c2']])
52
+ end
53
+
54
+ it 'matches multiple body rows' do
55
+ response = mock_model(Object, :body => '<table><tr><td>c1</td><td>c2</td></tr><tr><td>c3</td><td>c4</td></tr></table>')
56
+ response.should have_table([['c1', 'c2'], ['c3', 'c4']])
57
+ end
58
+
59
+ describe 'passed wrong id' do
60
+ it 'should not match' do
61
+ response = mock_model(Object, :body => '<table id="my_id"><tr><td>c1</td><td>c2</td></tr></table>')
62
+ response.should_not have_table('#wrong_id', [['c1', 'c2']])
63
+ end
64
+ end
65
+
66
+ describe 'passed non-matching expected' do
67
+ it 'should not match' do
68
+ response = mock_model(Object, :body => '<table id="my_id"><tr><td>c1</td><td>c2</td></tr></table>')
69
+ response.should_not have_table('#my_id', [['c3', 'c2']])
70
+ end
71
+ end
72
+
73
+ describe 'with normal failure' do
74
+ it 'should raise ExpectationNotMetError with correct message' do
75
+ response = mock_model Object, :body => 'Some non-matching HTML'
76
+ lambda do
77
+ response.should have_table('#my_id', [['c1', 'c2']])
78
+ end.should raise_error(Spec::Expectations::ExpectationNotMetError, "\nWrong table contents.\nexpected: [[\"c1\", \"c2\"]]\n found: []\n\n")
79
+ end
80
+ end
81
+
82
+ describe 'with negative failure' do
83
+ it 'should raise ExpectationNotMetError' do
84
+ response = mock_model Object, :body => '<table id="my_id"><tr><td>c1</td><td>c2</td></tr></table>'
85
+ lambda{
86
+ response.should_not have_table('#my_id', [['c1', 'c2']])
87
+ }.should raise_error(Spec::Expectations::ExpectationNotMetError,
88
+ "\nTable should not have matched: [[\"c1\", \"c2\"]]\n")
89
+ end
90
+ end
91
+
92
+ describe 'passed nil expected' do
93
+ it 'should raise error' do
94
+ response = mock_model(Object, :body => '<table id="my_id"><tr><td>c1</td><td>c2</td></tr></table>')
95
+ lambda{ response.should have_table('#my_id', nil)}.should raise_error(RuntimeError, 'Invalid "expected" argument')
96
+ end
97
+ end
98
+
99
+ describe "using non-id selectors" do
100
+ describe "class" do
101
+ it "matches with class" do
102
+ response = mock_model(Object, :body => '<table class="my_class"><tr><th>h1</th><th>h2</th></tr><tr><td>c1</td><td>c2</td></tr></table>')
103
+ response.should have_table('.my_class', [['h1', 'h2'], ['c1', 'c2']])
104
+ end
105
+ it "does not match when class do not match" do
106
+ response = mock_model(Object, :body => '<table class="my_class_2"><tr><th>h1</th><th>h2</th></tr><tr><td>c1</td><td>c2</td></tr></table>')
107
+ response.should_not have_table('.my_class', [['h1', 'h2'], ['c1', 'c2']])
108
+ end
109
+ it 'should raise ExpectationNotMetError with correct message' do
110
+ response = mock_model Object, :body => 'Some non-matching HTML'
111
+ lambda do
112
+ response.should have_table('.my_id', [['c1', 'c2']])
113
+ end.should raise_error(Spec::Expectations::ExpectationNotMetError, "\nWrong table contents.\nexpected: [[\"c1\", \"c2\"]]\n found: []\n\n")
114
+ end
115
+ end
116
+ end
117
+ end
data/tasks/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .svn
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :html_matchers do
3
+ # # Task goes here
4
+ # end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html_matchers
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - bendycode, helabed, listrophy
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-24 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: HTML entity matchers for RSpec
22
+ email: stephen@bendyworks.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README
29
+ files:
30
+ - .gitignore
31
+ - MIT-LICENSE
32
+ - README
33
+ - Rakefile
34
+ - VERSION
35
+ - init.rb
36
+ - install.rb
37
+ - lib/.gitignore
38
+ - lib/html_matchers.rb
39
+ - lib/matchers/.gitignore
40
+ - lib/matchers/button_matcher.rb
41
+ - lib/matchers/check_box_group_matcher.rb
42
+ - lib/matchers/drop_down_matcher.rb
43
+ - lib/matchers/image_matcher.rb
44
+ - lib/matchers/options_matcher.rb
45
+ - lib/matchers/radio_group_matcher.rb
46
+ - lib/matchers/span_text_matcher.rb
47
+ - lib/matchers/table_body_matcher.rb
48
+ - lib/matchers/table_header_matcher.rb
49
+ - lib/matchers/table_matcher.rb
50
+ - lib/matchers/td_link_matcher.rb
51
+ - spec/button_matcher_spec.rb
52
+ - spec/check_box_group_matcher_spec.rb
53
+ - spec/drop_down_matcher_spec.rb
54
+ - spec/image_matcher_spec.rb
55
+ - spec/radio_group_matcher_spec.rb
56
+ - spec/span_text_matcher_spec.rb
57
+ - spec/spec.opts
58
+ - spec/spec_helper.rb
59
+ - spec/table_body_matcher_spec.rb
60
+ - spec/table_header_matcher_spec.rb
61
+ - spec/table_matcher_spec.rb
62
+ - tasks/.gitignore
63
+ - tasks/html_matchers_tasks.rake
64
+ - uninstall.rb
65
+ has_rdoc: true
66
+ homepage: http://github.com/bendyworks/html_matchers
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.6
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: HTML entity matchers for RSpec
95
+ test_files:
96
+ - spec/button_matcher_spec.rb
97
+ - spec/check_box_group_matcher_spec.rb
98
+ - spec/drop_down_matcher_spec.rb
99
+ - spec/image_matcher_spec.rb
100
+ - spec/radio_group_matcher_spec.rb
101
+ - spec/span_text_matcher_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/table_body_matcher_spec.rb
104
+ - spec/table_header_matcher_spec.rb
105
+ - spec/table_matcher_spec.rb