suhyo 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,132 +1,174 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe Suhyo::ViewMatchers do
4
- include Suhyo::ViewMatchers
5
-
6
- describe '#have_link' do
7
- it 'matches with no options' do
8
- '<a href="http://example.com">Foo</a>'.should have_link
9
- end
10
-
11
- it 'matches the text' do
12
- '<a href="http://example.com">Foo</a>'.should have_link(:text => 'Foo')
13
- end
14
-
15
- it 'matches the URL' do
16
- '<a href="http://example.com">Foo</a>'.should have_link(:url => 'http://example.com')
17
- end
18
-
19
- it 'matches the ancestors' do
20
- '<div id="main"><a href="http://example.com">Foo</a></div>'.should have_link(:ancestors => 'div#main')
21
- end
22
-
23
- it 'does not match when there is no link' do
24
- '<div><p>Foo</p></div>'.should_not have_link
25
- end
26
-
27
- it 'does not match when the text is wrong' do
28
- '<a href="http://example.com">Foo</a>'.should_not have_link(:text => 'Bar')
29
- end
30
-
31
- it 'does not match when the URL is wrong' do
32
- '<a href="http://example.com">Foo</a>'.should_not have_link(:url => 'http://google.com')
33
- end
34
-
35
- it 'does not match when the ancestors are wrong' do
36
- '<a href="http://example.com">Foo</a>'.should_not have_link(:ancestors => 'div#main')
37
- end
38
- end
39
-
40
- describe '#contain_in_order' do
41
- context 'matching before' do
42
- it 'matches when the content is in the right order' do
43
- '<p>Foo</p><p>Bar</p>'.should contain_in_order('Foo', :before => 'Bar')
44
- end
45
-
46
- it 'does not match when the content is in the reverse order' do
47
- '<p>Bar</p><p>Foo</p>'.should_not contain_in_order('Foo', :before => 'Bar')
48
- end
49
-
50
- it 'does not match when the first content is missing' do
51
- '<p>...</p><p>Bar</p>'.should_not contain_in_order('Foo', :before => 'Bar')
52
- end
53
-
54
- it 'does not match when the second content is missing' do
55
- '<p>Foo</p><p>...</p>'.should_not contain_in_order('Foo', :before => 'Bar')
56
- end
57
- end
58
-
59
- context 'matching after' do
60
- it 'matches when the content is in the right order' do
61
- '<p>Foo</p><p>Bar</p>'.should contain_in_order('Bar', :after => 'Foo')
62
- end
63
-
64
- it 'does not match when the content is in the reverse order' do
65
- '<p>Bar</p><p>Foo</p>'.should_not contain_in_order('Bar', :after => 'Foo')
66
- end
67
-
68
- it 'does not match when the first content is missing' do
69
- '<p>Foo</p><p>...</p>'.should_not contain_in_order('Bar', :after => 'Foo')
70
- end
71
-
72
- it 'does not match when the second content is missing' do
73
- '<p>...</p><p>Bar</p>'.should_not contain_in_order('Bar', :after => 'Foo')
74
- end
75
- end
76
- end
77
-
78
- describe '#have_restful_form' do
79
- def restful_form(method)
80
- case method
81
- when 'get'
82
- browser_method = 'get'
83
- hidden_field = nil
84
- when 'post'
85
- browser_method = 'post'
86
- hidden_field = nil
87
- when 'put'
88
- browser_method = 'post'
89
- hidden_field = '<input type="hidden" name="_method" value="put"/>'
90
- when 'delete'
91
- browser_method = 'post'
92
- hidden_field = '<input type="hidden" name="_method" value="delete"/>'
93
- end
94
- %Q{<form method="#{browser_method}">#{hidden_field}</form>}
95
- end
96
-
97
- %w(get post put delete).each do |expected_method|
98
- it "matches a #{expected_method.upcase} form" do
99
- restful_form(expected_method).should have_restful_form(expected_method)
100
- end
101
-
102
- (%w(get post put delete) - [expected_method]).each do |actual_method|
103
- it "does not match #{expected_method.upcase} when the method is #{actual_method.upcase}" do
104
- restful_form(actual_method).should_not have_restful_form(expected_method)
105
- end
106
- end
107
- end
108
-
109
- it 'matches the ancestors' do
110
- ('<div id="main">' + restful_form('get') + '</div>').should have_restful_form('get', :ancestors => 'div#main')
111
- end
112
-
113
- it 'does not match if the ancestors are wrong' do
114
- restful_form('get').should_not have_restful_form('get', :ancestors => 'div#main')
115
- end
116
-
117
- it 'matches arbitrary attributes' do
118
- '<form action="http://example.com" method="get"></form>'.should have_restful_form('get', :action => 'http://example.com')
119
- '<form action="http://example.com" method="get"></form>'.should_not have_restful_form('get', :action => 'http://google.com')
120
- end
121
-
122
- it 'raises ArgumentError if method is not get, post, put, or delete' do
123
- lambda { restful_form('get').should have_restful_form('foo') }.should raise_error(ArgumentError)
124
- lambda { restful_form('get').should have_restful_form(42) }.should raise_error(ArgumentError)
125
- end
126
-
127
- it 'raises ArgumentError if options is not a hash' do
128
- lambda { restful_form('get').should have_restful_form('get', 42) }.should raise_error(ArgumentError)
129
- lambda { restful_form('get').should have_restful_form('get', 'foo') }.should raise_error(ArgumentError)
130
- end
131
- end
132
- end
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Suhyo::ViewMatchers do
4
+ include Suhyo::ViewMatchers
5
+
6
+ describe '#have_button' do
7
+ it 'matches with no options' do
8
+ '<input type="button"/>'.should have_button
9
+ end
10
+
11
+ it 'matches the text' do
12
+ '<input type="button" value="Submit"/>'.should have_button(:text => 'Submit')
13
+ end
14
+
15
+ it 'does not match when there is no button' do
16
+ '<input type="text"/>'.should_not have_button
17
+ end
18
+
19
+ it 'does not match when the text is wrong' do
20
+ '<input type="button" value="Wrong"/>'.should_not have_button(:text => 'Submit')
21
+ end
22
+ end
23
+
24
+ describe '#have_link' do
25
+ it 'matches with no options' do
26
+ '<a href="http://example.com">Foo</a>'.should have_link
27
+ end
28
+
29
+ it 'matches the text' do
30
+ '<a href="http://example.com">Foo</a>'.should have_link(:text => 'Foo')
31
+ end
32
+
33
+ it 'matches the URL' do
34
+ '<a href="http://example.com">Foo</a>'.should have_link(:url => 'http://example.com')
35
+ end
36
+
37
+ it 'matches the ancestors' do
38
+ '<div id="main"><a href="http://example.com">Foo</a></div>'.should have_link(:ancestors => 'div#main')
39
+ end
40
+
41
+ it 'does not match when there is no link' do
42
+ '<div><p>Foo</p></div>'.should_not have_link
43
+ end
44
+
45
+ it 'does not match when the text is wrong' do
46
+ '<a href="http://example.com">Foo</a>'.should_not have_link(:text => 'Bar')
47
+ end
48
+
49
+ it 'does not match when the URL is wrong' do
50
+ '<a href="http://example.com">Foo</a>'.should_not have_link(:url => 'http://google.com')
51
+ end
52
+
53
+ it 'does not match when the ancestors are wrong' do
54
+ '<a href="http://example.com">Foo</a>'.should_not have_link(:ancestors => 'div#main')
55
+ end
56
+ end
57
+
58
+ describe '#contain_in_order' do
59
+ context 'matching before' do
60
+ it 'matches when the content is in the right order' do
61
+ '<p>Foo</p><p>Bar</p>'.should contain_in_order('Foo', :before => 'Bar')
62
+ end
63
+
64
+ it 'does not match when the content is in the reverse order' do
65
+ '<p>Bar</p><p>Foo</p>'.should_not contain_in_order('Foo', :before => 'Bar')
66
+ end
67
+
68
+ it 'does not match when the first content is missing' do
69
+ '<p>...</p><p>Bar</p>'.should_not contain_in_order('Foo', :before => 'Bar')
70
+ end
71
+
72
+ it 'does not match when the second content is missing' do
73
+ '<p>Foo</p><p>...</p>'.should_not contain_in_order('Foo', :before => 'Bar')
74
+ end
75
+
76
+ it 'tells the expected order in the error message' do
77
+ lambda do
78
+ '<p>Bar</p><p>Foo</p>'.should contain_in_order('Foo', :before => 'Bar')
79
+ end.should raise_error(Spec::Expectations::ExpectationNotMetError, /expected the following element's content to include "Foo" before "Bar":/)
80
+ end
81
+
82
+ it 'tells you if the reference content is missing' do
83
+ lambda do
84
+ '<p>Foo</p><p>...</p>'.should contain_in_order('Foo', :before => 'Bar')
85
+ end.should raise_error(Spec::Expectations::ExpectationNotMetError, /expected the following element's content to include "Foo" before "Bar" but "Bar" was not found:/)
86
+ end
87
+ end
88
+
89
+ context 'matching after' do
90
+ it 'matches when the content is in the right order' do
91
+ '<p>Foo</p><p>Bar</p>'.should contain_in_order('Bar', :after => 'Foo')
92
+ end
93
+
94
+ it 'does not match when the content is in the reverse order' do
95
+ '<p>Bar</p><p>Foo</p>'.should_not contain_in_order('Bar', :after => 'Foo')
96
+ end
97
+
98
+ it 'does not match when the first content is missing' do
99
+ '<p>Foo</p><p>...</p>'.should_not contain_in_order('Bar', :after => 'Foo')
100
+ end
101
+
102
+ it 'does not match when the second content is missing' do
103
+ '<p>...</p><p>Bar</p>'.should_not contain_in_order('Bar', :after => 'Foo')
104
+ end
105
+
106
+ it 'tells the expected order in the error message' do
107
+ lambda do
108
+ '<p>Foo</p><p>Bar</p>'.should contain_in_order('Foo', :after => 'Bar')
109
+ end.should raise_error(Spec::Expectations::ExpectationNotMetError, /expected the following element's content to include "Foo" after "Bar":/)
110
+ end
111
+
112
+ it 'tells you if the reference content is missing' do
113
+ lambda do
114
+ '<p>...</p><p>Foo</p>'.should contain_in_order('Foo', :after => 'Bar')
115
+ end.should raise_error(Spec::Expectations::ExpectationNotMetError, /expected the following element's content to include "Foo" after "Bar" but "Bar" was not found:/)
116
+ end
117
+ end
118
+ end
119
+
120
+ describe '#have_restful_form' do
121
+ def restful_form(method)
122
+ case method
123
+ when 'get'
124
+ browser_method = 'get'
125
+ hidden_field = nil
126
+ when 'post'
127
+ browser_method = 'post'
128
+ hidden_field = nil
129
+ when 'put'
130
+ browser_method = 'post'
131
+ hidden_field = '<input type="hidden" name="_method" value="put"/>'
132
+ when 'delete'
133
+ browser_method = 'post'
134
+ hidden_field = '<input type="hidden" name="_method" value="delete"/>'
135
+ end
136
+ %Q{<form method="#{browser_method}">#{hidden_field}</form>}
137
+ end
138
+
139
+ %w(get post put delete).each do |expected_method|
140
+ it "matches a #{expected_method.upcase} form" do
141
+ restful_form(expected_method).should have_restful_form(expected_method)
142
+ end
143
+
144
+ (%w(get post put delete) - [expected_method]).each do |actual_method|
145
+ it "does not match #{expected_method.upcase} when the method is #{actual_method.upcase}" do
146
+ restful_form(actual_method).should_not have_restful_form(expected_method)
147
+ end
148
+ end
149
+ end
150
+
151
+ it 'matches the ancestors' do
152
+ ('<div id="main">' + restful_form('get') + '</div>').should have_restful_form('get', :ancestors => 'div#main')
153
+ end
154
+
155
+ it 'does not match if the ancestors are wrong' do
156
+ restful_form('get').should_not have_restful_form('get', :ancestors => 'div#main')
157
+ end
158
+
159
+ it 'matches arbitrary attributes' do
160
+ '<form action="http://example.com" method="get"></form>'.should have_restful_form('get', :action => 'http://example.com')
161
+ '<form action="http://example.com" method="get"></form>'.should_not have_restful_form('get', :action => 'http://google.com')
162
+ end
163
+
164
+ it 'raises ArgumentError if method is not get, post, put, or delete' do
165
+ lambda { restful_form('get').should have_restful_form('foo') }.should raise_error(ArgumentError)
166
+ lambda { restful_form('get').should have_restful_form(42) }.should raise_error(ArgumentError)
167
+ end
168
+
169
+ it 'raises ArgumentError if options is not a hash' do
170
+ lambda { restful_form('get').should have_restful_form('get', 42) }.should raise_error(ArgumentError)
171
+ lambda { restful_form('get').should have_restful_form('get', 'foo') }.should raise_error(ArgumentError)
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,127 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'Suhyo Webrat Steps' do
4
+ include ::CukeTest
5
+
6
+ before :all do
7
+ CukeTest.config.features_path = File.expand_path(File.dirname(__FILE__) + '/features')
8
+ end
9
+
10
+ describe 'I should see a link that says "..."' do
11
+ it 'passes if there is a link with the text' do
12
+ scenario('webrat.feature', 'link text expected, found').should pass_cuke
13
+ end
14
+
15
+ it 'fails if there is not link with the text' do
16
+ scenario('webrat.feature', 'link text expected, not found').should fail_cuke
17
+ end
18
+ end
19
+
20
+ describe 'I should not see a link that says ...' do
21
+ it 'passes if there is not a link with the text' do
22
+ scenario('webrat.feature', 'link text not expected, not found').should pass_cuke
23
+ end
24
+
25
+ it 'fails if there is a link with the text' do
26
+ scenario('webrat.feature', 'link text not expected, found').should fail_cuke
27
+ end
28
+ end
29
+
30
+ describe 'I should see a link to ...' do
31
+ it 'passes if there is a link with the URL' do
32
+ scenario('webrat.feature', 'link URL expected, found').should pass_cuke
33
+ end
34
+
35
+ it 'fails if there is not a link with the URL' do
36
+ scenario('webrat.feature', 'link URL expected, not found').should fail_cuke
37
+ end
38
+ end
39
+
40
+ describe 'I should not see a link to ...' do
41
+ it 'passes if there is not a link with the URL' do
42
+ scenario('webrat.feature', 'link URL not expected, not found').should pass_cuke
43
+ end
44
+
45
+ it 'fails if there is a link with the URL' do
46
+ scenario('webrat.feature', 'link URL not expected, found').should fail_cuke
47
+ end
48
+ end
49
+
50
+ describe 'I should see a button that says ...' do
51
+ it 'passes if there is a button with the text' do
52
+ scenario('webrat.feature', 'button text expected, found').should pass_cuke
53
+ end
54
+
55
+ it 'fails if there is not a button with the text' do
56
+ scenario('webrat.feature', 'button text expected, not found').should fail_cuke
57
+ end
58
+ end
59
+
60
+ describe 'I should not see a button that says ...' do
61
+ it 'passes if there is not a button with the text' do
62
+ scenario('webrat.feature', 'button text not expected, not found').should pass_cuke
63
+ end
64
+
65
+ it 'fails if there is a button with the text' do
66
+ scenario('webrat.feature', 'button text not expected, found').should fail_cuke
67
+ end
68
+ end
69
+
70
+ describe 'the page title should be ...' do
71
+ it 'passes is the page title is correct' do
72
+ scenario('webrat.feature', 'page title correct').should pass_cuke
73
+ end
74
+
75
+ it 'fails if the page title is incorrect' do
76
+ scenario('webrat.feature', 'page title wrong').should fail_cuke
77
+ end
78
+ end
79
+
80
+ describe 'I should see ... before ...' do
81
+ it 'passes if the content is found before the reference content' do
82
+ scenario('webrat.feature', 'content expected before, found before').should pass_cuke
83
+ end
84
+
85
+ it 'fails if the content is found after the reference content' do
86
+ scenario('webrat.feature', 'content expected before, found after').should fail_cuke
87
+ end
88
+ end
89
+
90
+ describe 'I should see ... after ...' do
91
+ it 'passes if the content is found after the reference content' do
92
+ scenario('webrat.feature', 'content expected after, found after').should pass_cuke
93
+ end
94
+
95
+ it 'fails if the content is found before the reference content' do
96
+ scenario('webrat.feature', 'content expected after, found before').should fail_cuke
97
+ end
98
+ end
99
+
100
+ describe 'I should be at (.+) with the query string ...' do
101
+ it 'passes if the query string matches' do
102
+ scenario('webrat.feature', 'query string expected, found').should pass_cuke
103
+ end
104
+
105
+ it 'fails if the query string does not match' do
106
+ scenario('webrat.feature', 'query string expected, not found').should fail_cuke
107
+ end
108
+
109
+ it 'fails if the path does not match' do
110
+ scenario('webrat.feature', 'query string expected, path wrong').should fail_cuke
111
+ end
112
+ end
113
+
114
+ describe 'I should be at (.+) with the query string including ...' do
115
+ it 'passes if the query string includes the hash' do
116
+ scenario('webrat.feature', 'partial query string expected, found').should pass_cuke
117
+ end
118
+
119
+ it 'fails if the query string does not include the hash' do
120
+ scenario('webrat.feature', 'partial query string expected, not found').should fail_cuke
121
+ end
122
+
123
+ it 'fails if the path does not match' do
124
+ scenario('webrat.feature', 'partial query string expected, path wrong').should fail_cuke
125
+ end
126
+ end
127
+ end
data/suhyo.gemspec CHANGED
@@ -1,63 +1,76 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{suhyo}
8
- s.version = "0.0.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["jarrett"]
12
- s.date = %q{2010-03-12}
13
- s.description = %q{Matchers built on Webrat to address some common needs in web app testing}
14
- s.email = %q{jarrett@uchicago.edu}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.markdown"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.markdown",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/suhyo.rb",
27
- "lib/suhyo/config.rb",
28
- "lib/suhyo/controller_matchers.rb",
29
- "lib/suhyo/view_matchers.rb",
30
- "spec/controller_matchers_spec.rb",
31
- "spec/spec.opts",
32
- "spec/spec_helper.rb",
33
- "spec/view_matchers_spec.rb",
34
- "suhyo.gemspec"
35
- ]
36
- s.homepage = %q{http://github.com/jarrett/suhyo}
37
- s.rdoc_options = ["--charset=UTF-8"]
38
- s.require_paths = ["lib"]
39
- s.rubygems_version = %q{1.3.5}
40
- s.summary = %q{Matchers for web app specs}
41
- s.test_files = [
42
- "spec/controller_matchers_spec.rb",
43
- "spec/spec_helper.rb",
44
- "spec/view_matchers_spec.rb"
45
- ]
46
-
47
- if s.respond_to? :specification_version then
48
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
- s.specification_version = 3
50
-
51
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
- s.add_runtime_dependency(%q<rspec>, [">= 1.2.9"])
53
- s.add_runtime_dependency(%q<webrat>, [">= 0.7.0"])
54
- else
55
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
56
- s.add_dependency(%q<webrat>, [">= 0.7.0"])
57
- end
58
- else
59
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
60
- s.add_dependency(%q<webrat>, [">= 0.7.0"])
61
- end
62
- end
63
-
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{suhyo}
8
+ s.version = "0.0.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["jarrett"]
12
+ s.date = %q{2010-03-14}
13
+ s.description = %q{Matchers built on Webrat to address some common needs in web app testing}
14
+ s.email = %q{jarrett@uchicago.edu}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/suhyo.rb",
27
+ "lib/suhyo/config.rb",
28
+ "lib/suhyo/controller_matchers.rb",
29
+ "lib/suhyo/hash_matchers.rb",
30
+ "lib/suhyo/view_matchers.rb",
31
+ "lib/suhyo/webrat_steps.rb",
32
+ "spec/controller_matchers_spec.rb",
33
+ "spec/features/README.txt",
34
+ "spec/features/steps.rb",
35
+ "spec/features/webrat.feature",
36
+ "spec/hash_matchers_spec.rb",
37
+ "spec/spec.opts",
38
+ "spec/spec_helper.rb",
39
+ "spec/view_matchers_spec.rb",
40
+ "spec/webrat_steps_spec.rb",
41
+ "suhyo.gemspec"
42
+ ]
43
+ s.homepage = %q{http://github.com/jarrett/suhyo}
44
+ s.rdoc_options = ["--charset=UTF-8"]
45
+ s.require_paths = ["lib"]
46
+ s.rubygems_version = %q{1.3.6}
47
+ s.summary = %q{Matchers for web app specs}
48
+ s.test_files = [
49
+ "spec/controller_matchers_spec.rb",
50
+ "spec/features/steps.rb",
51
+ "spec/hash_matchers_spec.rb",
52
+ "spec/spec_helper.rb",
53
+ "spec/view_matchers_spec.rb",
54
+ "spec/webrat_steps_spec.rb"
55
+ ]
56
+
57
+ if s.respond_to? :specification_version then
58
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
59
+ s.specification_version = 3
60
+
61
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
62
+ s.add_runtime_dependency(%q<rspec>, [">= 1.2.9"])
63
+ s.add_runtime_dependency(%q<webrat>, [">= 0.7.0"])
64
+ s.add_development_dependency(%q<cuke-test>, [">= 0"])
65
+ else
66
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
67
+ s.add_dependency(%q<webrat>, [">= 0.7.0"])
68
+ s.add_dependency(%q<cuke-test>, [">= 0"])
69
+ end
70
+ else
71
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
72
+ s.add_dependency(%q<webrat>, [">= 0.7.0"])
73
+ s.add_dependency(%q<cuke-test>, [">= 0"])
74
+ end
75
+ end
76
+