capybara_minitest_spec 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/.rvmrc +1 -1
  2. data/HISTORY.md +0 -0
  3. data/README.md +31 -32
  4. data/Rakefile +2 -2
  5. data/capybara_minitest_spec.gemspec +6 -4
  6. data/lib/capybara_minitest_spec.rb +53 -6
  7. data/lib/capybara_minitest_spec/test_name.rb +67 -0
  8. data/lib/capybara_minitest_spec/version.rb +1 -1
  9. data/spec/capybara_minitest_spec.spec.rb +13 -0
  10. data/spec/capybara_rspec_matchers.spec.rb +580 -0
  11. data/spec/helper.rb +39 -0
  12. data/{test_app → spec/test_app}/test_app.rb +0 -0
  13. data/{test_app → spec/test_app}/views/buttons.erb +0 -0
  14. data/{test_app → spec/test_app}/views/fieldsets.erb +0 -0
  15. data/{test_app → spec/test_app}/views/form.erb +0 -0
  16. data/{test_app → spec/test_app}/views/frame_one.erb +0 -0
  17. data/{test_app → spec/test_app}/views/frame_two.erb +0 -0
  18. data/{test_app → spec/test_app}/views/header_links.erb +0 -0
  19. data/{test_app → spec/test_app}/views/host_links.erb +0 -0
  20. data/{test_app → spec/test_app}/views/popup_one.erb +0 -0
  21. data/{test_app → spec/test_app}/views/popup_two.erb +0 -0
  22. data/{test_app → spec/test_app}/views/postback.erb +0 -0
  23. data/{test_app → spec/test_app}/views/tables.erb +0 -0
  24. data/{test_app → spec/test_app}/views/with_html.erb +0 -0
  25. data/{test_app → spec/test_app}/views/with_html_entities.erb +0 -0
  26. data/{test_app → spec/test_app}/views/with_js.erb +0 -0
  27. data/{test_app → spec/test_app}/views/with_scope.erb +0 -0
  28. data/{test_app → spec/test_app}/views/with_simple_html.erb +0 -0
  29. data/{test_app → spec/test_app}/views/within_frames.erb +0 -0
  30. data/{test_app → spec/test_app}/views/within_popups.erb +0 -0
  31. data/spec/test_name.spec.rb +47 -0
  32. metadata +142 -121
  33. data/lib/capybara_minitest_spec/matcher.rb +0 -126
  34. data/test/capybara_node_matchers_spec.rb +0 -471
  35. data/test/custom_matcher_spec.rb +0 -29
  36. data/test/matcher_spec.rb +0 -45
  37. data/test/spec_helper.rb +0 -14
  38. data/test_app/driver.rb +0 -297
  39. data/test_app/fixtures/capybara.jpg +0 -3
  40. data/test_app/fixtures/test_file.txt +0 -1
  41. data/test_app/public/test.js +0 -43
  42. data/test_app/session.rb +0 -154
  43. data/test_app/session/all_spec.rb +0 -78
  44. data/test_app/session/attach_file_spec.rb +0 -73
  45. data/test_app/session/check_spec.rb +0 -65
  46. data/test_app/session/choose_spec.rb +0 -26
  47. data/test_app/session/click_button_spec.rb +0 -304
  48. data/test_app/session/click_link_or_button_spec.rb +0 -36
  49. data/test_app/session/click_link_spec.rb +0 -119
  50. data/test_app/session/current_host_spec.rb +0 -68
  51. data/test_app/session/current_url_spec.rb +0 -15
  52. data/test_app/session/fill_in_spec.rb +0 -125
  53. data/test_app/session/find_button_spec.rb +0 -18
  54. data/test_app/session/find_by_id_spec.rb +0 -18
  55. data/test_app/session/find_field_spec.rb +0 -26
  56. data/test_app/session/find_link_spec.rb +0 -19
  57. data/test_app/session/find_spec.rb +0 -149
  58. data/test_app/session/first_spec.rb +0 -105
  59. data/test_app/session/has_button_spec.rb +0 -32
  60. data/test_app/session/has_content_spec.rb +0 -106
  61. data/test_app/session/has_css_spec.rb +0 -243
  62. data/test_app/session/has_field_spec.rb +0 -192
  63. data/test_app/session/has_link_spec.rb +0 -37
  64. data/test_app/session/has_select_spec.rb +0 -129
  65. data/test_app/session/has_selector_spec.rb +0 -129
  66. data/test_app/session/has_table_spec.rb +0 -96
  67. data/test_app/session/has_xpath_spec.rb +0 -123
  68. data/test_app/session/headers.rb +0 -19
  69. data/test_app/session/javascript.rb +0 -289
  70. data/test_app/session/response_code.rb +0 -19
  71. data/test_app/session/select_spec.rb +0 -113
  72. data/test_app/session/text_spec.rb +0 -19
  73. data/test_app/session/uncheck_spec.rb +0 -21
  74. data/test_app/session/unselect_spec.rb +0 -61
  75. data/test_app/session/within_spec.rb +0 -178
@@ -0,0 +1,39 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'minitest/autorun'
4
+ require 'awesome_print'
5
+
6
+ require 'capybara/dsl'
7
+ require 'capybara_minitest_spec'
8
+
9
+ # Make all specs a subclass of MiniTest::Spec.
10
+ MiniTest::Spec.register_spec_type //, MiniTest::Spec
11
+
12
+ # Bridge some gaps between RSpec and MiniTest.
13
+ class MiniTest::Spec
14
+
15
+ class << self
16
+ alias_method :context, :describe
17
+ end
18
+
19
+ alias_method :expect, :proc
20
+
21
+ end
22
+
23
+ module MiniTest::Assertions
24
+
25
+ # Yield, rescue, compare exception's message.
26
+ def assert_raises_with_message(exception_message)
27
+ yield
28
+ rescue Exception => exception
29
+ exception_raised = true
30
+ assert_match exception_message, exception.message
31
+ ensure
32
+ assert exception_raised, 'expected exception to be raised'
33
+ end
34
+
35
+ end
36
+
37
+ module MiniTest::Expectations
38
+ infect_an_assertion :assert_raises_with_message, :must_raise_with_message
39
+ end
File without changes
@@ -0,0 +1,47 @@
1
+ require_relative 'helper'
2
+
3
+ describe CapybaraMiniTestSpec::TestName do
4
+
5
+ describe CapybaraMiniTestSpec::PositiveTestName do
6
+
7
+ let(:positive) { CapybaraMiniTestSpec::PositiveTestName.new(:have_css) }
8
+
9
+ specify '#assertion_name returns assert_page_has_css' do
10
+ positive.assertion_name.must_equal 'assert_page_has_css'
11
+ end
12
+
13
+ specify '#expectation_name returns must_have_css' do
14
+ positive.expectation_name.must_equal 'must_have_css'
15
+ end
16
+
17
+ specify '#match_method returns :matches?' do
18
+ positive.match_method.must_equal :matches?
19
+ end
20
+
21
+ end
22
+
23
+ describe CapybaraMiniTestSpec::NegativeTestName do
24
+
25
+ let(:negative) { CapybaraMiniTestSpec::NegativeTestName.new(:have_css) }
26
+
27
+ specify '#assertion_name returns refute_page_has_css' do
28
+ negative.assertion_name.must_equal 'refute_page_has_css'
29
+ end
30
+
31
+ specify '#expectation_name returns wont_have_css' do
32
+ negative.expectation_name.must_equal 'wont_have_css'
33
+ end
34
+
35
+ specify '#match_method returns :does_not_match?' do
36
+ negative.match_method.must_equal :does_not_match?
37
+ end
38
+
39
+ end
40
+
41
+ specify '#matcher returns actual Capybara RSpec matcher' do
42
+ matcher_name = CapybaraMiniTestSpec::TestName.new(:have_css)
43
+ rspec_matcher = matcher_name.matcher('.asdf')
44
+ rspec_matcher.must_be_instance_of Capybara::RSpecMatchers::HaveSelector
45
+ end
46
+
47
+ end
metadata CHANGED
@@ -1,164 +1,185 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: capybara_minitest_spec
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
4
5
  prerelease:
5
- version: 0.2.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Jared Ning
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-05-17 00:00:00 -05:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2012-11-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: capybara
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2'
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: minitest
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
31
25
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "2.0"
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '2'
36
38
  type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: sinatra
40
39
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '2'
46
+ - !ruby/object:Gem::Dependency
47
+ name: awesome_print
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
42
57
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: sinatra
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
46
85
  version: 0.9.4
47
86
  type: :development
48
- version_requirements: *id003
49
- description: MiniTest::Spec expectations for Capybara node matchers.
50
- email:
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.9.4
94
+ description: Use Capybara matchers with MiniTest. Specifically, it defines MiniTest::Spec
95
+ expectations like page.must_have_content('content').
96
+ email:
51
97
  - jared@redningja.com
52
98
  executables: []
53
-
54
99
  extensions: []
55
-
56
100
  extra_rdoc_files: []
57
-
58
- files:
101
+ files:
59
102
  - .gemtest
60
103
  - .gitignore
61
104
  - .gitmodules
62
105
  - .rvmrc
63
106
  - .travis.yml
64
107
  - Gemfile
108
+ - HISTORY.md
65
109
  - README.md
66
110
  - Rakefile
67
111
  - capybara_minitest_spec.gemspec
68
112
  - lib/capybara_minitest_spec.rb
69
- - lib/capybara_minitest_spec/matcher.rb
113
+ - lib/capybara_minitest_spec/test_name.rb
70
114
  - lib/capybara_minitest_spec/version.rb
71
- - test/capybara_node_matchers_spec.rb
72
- - test/custom_matcher_spec.rb
73
- - test/matcher_spec.rb
74
- - test/spec_helper.rb
75
- - test_app/driver.rb
76
- - test_app/fixtures/capybara.jpg
77
- - test_app/fixtures/test_file.txt
78
- - test_app/public/test.js
79
- - test_app/session.rb
80
- - test_app/session/all_spec.rb
81
- - test_app/session/attach_file_spec.rb
82
- - test_app/session/check_spec.rb
83
- - test_app/session/choose_spec.rb
84
- - test_app/session/click_button_spec.rb
85
- - test_app/session/click_link_or_button_spec.rb
86
- - test_app/session/click_link_spec.rb
87
- - test_app/session/current_host_spec.rb
88
- - test_app/session/current_url_spec.rb
89
- - test_app/session/fill_in_spec.rb
90
- - test_app/session/find_button_spec.rb
91
- - test_app/session/find_by_id_spec.rb
92
- - test_app/session/find_field_spec.rb
93
- - test_app/session/find_link_spec.rb
94
- - test_app/session/find_spec.rb
95
- - test_app/session/first_spec.rb
96
- - test_app/session/has_button_spec.rb
97
- - test_app/session/has_content_spec.rb
98
- - test_app/session/has_css_spec.rb
99
- - test_app/session/has_field_spec.rb
100
- - test_app/session/has_link_spec.rb
101
- - test_app/session/has_select_spec.rb
102
- - test_app/session/has_selector_spec.rb
103
- - test_app/session/has_table_spec.rb
104
- - test_app/session/has_xpath_spec.rb
105
- - test_app/session/headers.rb
106
- - test_app/session/javascript.rb
107
- - test_app/session/response_code.rb
108
- - test_app/session/select_spec.rb
109
- - test_app/session/text_spec.rb
110
- - test_app/session/uncheck_spec.rb
111
- - test_app/session/unselect_spec.rb
112
- - test_app/session/within_spec.rb
113
- - test_app/test_app.rb
114
- - test_app/views/buttons.erb
115
- - test_app/views/fieldsets.erb
116
- - test_app/views/form.erb
117
- - test_app/views/frame_one.erb
118
- - test_app/views/frame_two.erb
119
- - test_app/views/header_links.erb
120
- - test_app/views/host_links.erb
121
- - test_app/views/popup_one.erb
122
- - test_app/views/popup_two.erb
123
- - test_app/views/postback.erb
124
- - test_app/views/tables.erb
125
- - test_app/views/with_html.erb
126
- - test_app/views/with_html_entities.erb
127
- - test_app/views/with_js.erb
128
- - test_app/views/with_scope.erb
129
- - test_app/views/with_simple_html.erb
130
- - test_app/views/within_frames.erb
131
- - test_app/views/within_popups.erb
132
- has_rdoc: true
115
+ - spec/capybara_minitest_spec.spec.rb
116
+ - spec/capybara_rspec_matchers.spec.rb
117
+ - spec/helper.rb
118
+ - spec/test_app/test_app.rb
119
+ - spec/test_app/views/buttons.erb
120
+ - spec/test_app/views/fieldsets.erb
121
+ - spec/test_app/views/form.erb
122
+ - spec/test_app/views/frame_one.erb
123
+ - spec/test_app/views/frame_two.erb
124
+ - spec/test_app/views/header_links.erb
125
+ - spec/test_app/views/host_links.erb
126
+ - spec/test_app/views/popup_one.erb
127
+ - spec/test_app/views/popup_two.erb
128
+ - spec/test_app/views/postback.erb
129
+ - spec/test_app/views/tables.erb
130
+ - spec/test_app/views/with_html.erb
131
+ - spec/test_app/views/with_html_entities.erb
132
+ - spec/test_app/views/with_js.erb
133
+ - spec/test_app/views/with_scope.erb
134
+ - spec/test_app/views/with_simple_html.erb
135
+ - spec/test_app/views/within_frames.erb
136
+ - spec/test_app/views/within_popups.erb
137
+ - spec/test_name.spec.rb
133
138
  homepage: https://github.com/ordinaryzelig/capybara_minitest_spec
134
139
  licenses: []
135
-
136
140
  post_install_message:
137
141
  rdoc_options: []
138
-
139
- require_paths:
142
+ require_paths:
140
143
  - lib
141
- required_ruby_version: !ruby/object:Gem::Requirement
144
+ required_ruby_version: !ruby/object:Gem::Requirement
142
145
  none: false
143
- requirements:
144
- - - ">="
145
- - !ruby/object:Gem::Version
146
- version: "0"
147
- required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
151
  none: false
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: "0"
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
153
156
  requirements: []
154
-
155
157
  rubyforge_project: capybara_minitest_spec
156
- rubygems_version: 1.6.1
158
+ rubygems_version: 1.8.24
157
159
  signing_key:
158
160
  specification_version: 3
159
- summary: MiniTest::Spec expectations for Capybara node matchers.
160
- test_files:
161
- - test/capybara_node_matchers_spec.rb
162
- - test/custom_matcher_spec.rb
163
- - test/matcher_spec.rb
164
- - test/spec_helper.rb
161
+ summary: Capybara + MiniTest::Spec
162
+ test_files:
163
+ - spec/capybara_minitest_spec.spec.rb
164
+ - spec/capybara_rspec_matchers.spec.rb
165
+ - spec/helper.rb
166
+ - spec/test_app/test_app.rb
167
+ - spec/test_app/views/buttons.erb
168
+ - spec/test_app/views/fieldsets.erb
169
+ - spec/test_app/views/form.erb
170
+ - spec/test_app/views/frame_one.erb
171
+ - spec/test_app/views/frame_two.erb
172
+ - spec/test_app/views/header_links.erb
173
+ - spec/test_app/views/host_links.erb
174
+ - spec/test_app/views/popup_one.erb
175
+ - spec/test_app/views/popup_two.erb
176
+ - spec/test_app/views/postback.erb
177
+ - spec/test_app/views/tables.erb
178
+ - spec/test_app/views/with_html.erb
179
+ - spec/test_app/views/with_html_entities.erb
180
+ - spec/test_app/views/with_js.erb
181
+ - spec/test_app/views/with_scope.erb
182
+ - spec/test_app/views/with_simple_html.erb
183
+ - spec/test_app/views/within_frames.erb
184
+ - spec/test_app/views/within_popups.erb
185
+ - spec/test_name.spec.rb
@@ -1,126 +0,0 @@
1
- module CapybaraMiniTestSpec
2
- class Matcher
3
-
4
- attr_reader :name
5
-
6
- def initialize(node_matcher_name)
7
- @name = Name.new(node_matcher_name, true)
8
- define_expectations
9
- end
10
-
11
- def define_expectations
12
- # Define positive expectations.
13
- define_expectation
14
- # Define negative expectations.
15
- @name.negate!
16
- define_expectation
17
- end
18
-
19
- def undefine_assertions
20
- undefine_assertion
21
- @name.negate!
22
- undefine_assertion
23
- end
24
-
25
- # Send page the matcher name with args.
26
- # E.g. page.has_css?(*args)
27
- def test(page, *args)
28
- wrap(page).send(name.original, *args)
29
- end
30
-
31
- # Compose failure message.
32
- # E.g. Matcher failed: has_css?("expected", {:count => 1})
33
- def self.failure_message(assertion_method, matcher_name, *args)
34
- if assertion_method == 'assert'
35
- message = "Matcher failed: "
36
- else
37
- message = 'Matcher should have failed: '
38
- end
39
- message += "#{matcher_name}(#{args.map(&:inspect).join(', ')})"
40
- end
41
-
42
- private
43
-
44
- def define_expectation
45
- define_assertion
46
- infect_assertion
47
- end
48
-
49
- # Define an assertion with the matcher name in MiniTest::Assertions.
50
- # For example, if the matcher name is has_css?,
51
- # the assertion would be called assert_page_has_css.
52
- def define_assertion
53
- # scope self to be available in the method definition.
54
- matcher = self
55
- assertion_method = name.positive? ? 'assert' : 'refute'
56
- MiniTest::Assertions.send :define_method, name.assertion do |page, *args|
57
- message = matcher.class.failure_message(assertion_method, matcher.name.original, *args)
58
- send(assertion_method, matcher.test(page, *args), message)
59
- end
60
- end
61
-
62
- def undefine_assertion
63
- MiniTest::Assertions.send :undef_method, @name.assertion
64
- end
65
-
66
- def infect_assertion
67
- MiniTest::Expectations.infect_an_assertion @name.assertion, @name.expectation, true
68
- end
69
-
70
- # Turn a string into a Capybara node if it's not already.
71
- # Copied from Capybara::RSpecMatchers::HaveMatcher.
72
- def wrap(actual)
73
- if actual.respond_to?("has_selector?")
74
- actual
75
- else
76
- Capybara.string(actual.to_s)
77
- end
78
- end
79
-
80
- # Represents the a matcher name.
81
- # Returns different forms of the name depending on whether it is in a positive or negative state.
82
- class Name
83
-
84
- attr_reader :original
85
-
86
- def initialize(name, positive)
87
- @original = name.to_s
88
- @positive = positive
89
- end
90
-
91
- def positive?
92
- !!@positive
93
- end
94
-
95
- def negate!
96
- @positive = !positive?
97
- end
98
-
99
- def without_question_mark
100
- @original.to_s.sub /\?$/, ''
101
- end
102
-
103
- def have
104
- without_question_mark.sub /has_/, 'have_'
105
- end
106
-
107
- def assertion
108
- if positive?
109
- "assert_page_#{without_question_mark}"
110
- else
111
- "refute_page_#{without_question_mark}"
112
- end
113
- end
114
-
115
- def expectation
116
- if positive?
117
- "must_#{have}"
118
- else
119
- "wont_#{have}"
120
- end
121
- end
122
-
123
- end
124
-
125
- end
126
- end