capybara-minitest 0.9.2

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b1cd121160c99cd542ea847802338679aa51728
4
+ data.tar.gz: 08c55103d678da5813148afd32d6e49dd879f41e
5
+ SHA512:
6
+ metadata.gz: 6cf690e631a6f76e599e2b23d621cf34ba710ad732d97fe4d3a26df2cacb96ce599bfc41c3d3dd7ff00ec535e1dd67e41c2724af27a8381dd593a080da73613b
7
+ data.tar.gz: 9d995ed346f53c4d396de8bb425376ec4e580a2f2ee3751cc11ad6fdc3133b19303f5171f4fb220da2dd8f3edd64fd40d736fd2c67ab57e41600246c3bc7a572
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Dennis Stevense
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,74 @@
1
+ Capybara::Minitest
2
+ ==================
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/capybara-minitest.svg)](http://badge.fury.io/rb/capybara-minitest)
5
+ [![Dependency Status](https://gemnasium.com/decafdennis/capybara-minitest.svg)](https://gemnasium.com/decafdennis/capybara-minitest)
6
+ [![Build Status](https://travis-ci.org/decafdennis/capybara-minitest.svg?branch=master)](https://travis-ci.org/decafdennis/capybara-minitest)
7
+ [![Code Climate](https://codeclimate.com/github/decafdennis/capybara-minitest/badges/gpa.svg)](https://codeclimate.com/github/decafdennis/capybara-minitest)
8
+ [![Coverage Status](https://coveralls.io/repos/decafdennis/capybara-minitest/badge.png)](https://coveralls.io/r/decafdennis/capybara-minitest)
9
+ [![Inline docs](http://inch-ci.org/github/decafdennis/capybara-minitest.svg?branch=master)](http://inch-ci.org/github/decafdennis/capybara-minitest)
10
+
11
+ If you're using `Minitest::Test` with the `Capybara::DSL` for your tests, this
12
+ gem will allow you to do:
13
+
14
+ ```ruby
15
+ # With Capybara::Minitest::Assertions included
16
+ assert_has_text page, 'Squeak', 'optional message'
17
+ ```
18
+
19
+ instead of:
20
+
21
+ ```ruby
22
+ # Without Capybara::Minitest
23
+ assert page.has_text?('Squeak'), 'optional message'
24
+ ```
25
+
26
+ The assertions are dynamically generated from Capybara's RSpec matchers. You can
27
+ optionally provide custom failure messages and the backtrace will be cleaned up
28
+ for you.
29
+
30
+ You can see the full list of assertions (and refutations) in the
31
+ [auto-generated RDoc](https://github.com/decafdennis/capybara-minitest/blob/master/lib/capybara/minitest/assertions/rdoc.rb).
32
+
33
+ ## Install
34
+
35
+ ```ruby
36
+ # Gemfile
37
+ gem 'capybara-minitest'
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ```ruby
43
+ require 'capybara/minitest/assertions'
44
+
45
+ class AcceptanceTest < Minitest::Test
46
+ include Capybara::DSL
47
+ include Capybara::Minitest::Assertions
48
+ end
49
+ ```
50
+
51
+ Or, if you're using Rails:
52
+
53
+ ```ruby
54
+ require 'capybara/minitest/assertions'
55
+
56
+ class AcceptanceTest < ActionDispatch::IntegrationTest
57
+ include Capybara::DSL
58
+ include Capybara::Minitest::Assertions
59
+ end
60
+ ```
61
+
62
+ ## Example
63
+
64
+ ```ruby
65
+ class RodentTest < Minitest::Test
66
+ include Capybara::DSL
67
+ include Capybara::Minitest::Assertions
68
+
69
+ def test_squeak
70
+ visit '/rodent'
71
+ assert_has_text page, 'Squeak', 'optional message'
72
+ end
73
+ end
74
+ ```
@@ -0,0 +1,4 @@
1
+ require 'capybara-minitest/version'
2
+
3
+ module CapybaraMinitest
4
+ end
@@ -0,0 +1,3 @@
1
+ module CapybaraMinitest
2
+ VERSION = '0.9.2'
3
+ end
@@ -0,0 +1,5 @@
1
+ module Capybara
2
+ # Provides minitest extensions for Capybara.
3
+ module Minitest
4
+ end
5
+ end
@@ -0,0 +1,42 @@
1
+ require 'capybara/minitest/assertions/matcher'
2
+ require 'capybara/minitest/assertions/rdoc'
3
+
4
+ module Capybara
5
+ module Minitest
6
+ # Include this module in your minitest tests to get assertions based on
7
+ # Capybara's RSpec matchers.
8
+ module Assertions
9
+ # Define assertions for each of the RSpec matchers that come with
10
+ # Capybara.
11
+ Matcher.all.each do |matcher|
12
+ matcher.assertions.each do |assertion|
13
+ define_method assertion.name do |*args|
14
+ # We typically get a minimum of 2 arguments: the test subject and
15
+ # some test value. Sometimes that is followed by a hash of options.
16
+ # Assume if the last argument is a string, then it's a custom
17
+ # message.
18
+ if args.length > 2 && args.last.is_a?(String)
19
+ custom_message = args.pop
20
+ else
21
+ custom_message = nil
22
+ end
23
+
24
+ test_result, failure_message = assertion.test(*args)
25
+
26
+ begin
27
+ assert test_result, message(custom_message) { failure_message }
28
+ rescue Exception => e
29
+ # Exclude ourselves from the backtrace, so that assertion failure
30
+ # messages show the right file and line number.
31
+ if e.class.name.include?('::Assertion')
32
+ e.backtrace.reject! { |item| item.include?(__FILE__) }
33
+ end
34
+
35
+ raise e
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,125 @@
1
+ require 'capybara/rspec/matchers'
2
+
3
+ module Capybara
4
+ module Minitest
5
+ module Assertions
6
+ # Represents one of the Capybara RSpec matchers.
7
+ class Matcher
8
+ include Capybara::RSpecMatchers
9
+
10
+ # Returns an array of matchers representing the recognized Capybara
11
+ # RSpec matchers.
12
+ def self.all
13
+ Capybara::RSpecMatchers.public_instance_methods.map do |matcher_name|
14
+ new(matcher_name) if recognizes_name?(matcher_name)
15
+ end.compact
16
+ end
17
+
18
+ # Determines whether the given RSpec matcher is recognized by this
19
+ # class.
20
+ def self.recognizes_name?(name)
21
+ name.to_s.match(/^have_/)
22
+ end
23
+
24
+ # The name of the RSpec matcher, e.g. have_text.
25
+ attr_reader :name
26
+
27
+ # Initializes a new matcher based on the given RSpec matcher name.
28
+ def initialize(name)
29
+ unless self.class.recognizes_name?(name)
30
+ fail ArgumentError, 'Unrecognized matcher name.'
31
+ end
32
+
33
+ @name = name.to_s
34
+ end
35
+
36
+ # Returns the matcher's name in third person.
37
+ #
38
+ # matcher.name # => have_text (infinitive form)
39
+ # matcher.third_person_name # => has_text (third person form)
40
+ #
41
+ def third_person_name
42
+ @third_person_name ||= @name.gsub(/^have_/, 'has_')
43
+ end
44
+
45
+ # Returns a new Capybara RSpec matcher object for the given matcher
46
+ # arguments. This is what would be returned by have_text('Foo'), for
47
+ # example.
48
+ def matcher(*args)
49
+ send(@name, *args)
50
+ end
51
+
52
+ # Returns a new array of assertions for this matcher.
53
+ def assertions
54
+ [MatcherAssertion.new(self), MatcherRefutation.new(self)]
55
+ end
56
+ end
57
+
58
+ # Represents an assertion based on a Capybara RSpec matcher.
59
+ class MatcherAssertion
60
+ # The matcher this assertion is based on.
61
+ attr_reader :matcher
62
+
63
+ # Initializes a new assertion with the given matcher.
64
+ def initialize(matcher)
65
+ @matcher = matcher
66
+ end
67
+
68
+ # The name of the assertion.
69
+ #
70
+ # assertion.matcher.name # => have_text
71
+ # assertion.name # => assert_has_text
72
+ #
73
+ def name
74
+ "#{self.class.name_prefix}_#{@matcher.third_person_name}"
75
+ end
76
+
77
+ # Executes the assertion by testing it against the matcher on the given
78
+ # test subject and with the provided arguments. Returns an array with
79
+ # the test result (as a boolean) and the failure message.
80
+ def test(subject, *args)
81
+ # Create an RSpec matcher object.
82
+ matcher = @matcher.matcher(*args)
83
+ # Perform the match.
84
+ test_result = matcher.send(self.class.matcher_test_method, subject)
85
+ # Get the failure message, which has to be done after the matching.
86
+ failure_message = matcher.send(self.class.matcher_failure_message_method)
87
+
88
+ [test_result, failure_message]
89
+ end
90
+
91
+ # The prefix for method names of this kind of assertion.
92
+ def self.name_prefix
93
+ 'assert'
94
+ end
95
+
96
+ # The test method called on the RSpec matcher for this kind of
97
+ # assertion.
98
+ def self.matcher_test_method
99
+ :matches?
100
+ end
101
+
102
+ # The failure message method called on the RSpec matcher for this kind
103
+ # of assertion.
104
+ def self.matcher_failure_message_method
105
+ :failure_message
106
+ end
107
+ end
108
+
109
+ # Represents a refutation based on a Capybara RSpec matcher.
110
+ class MatcherRefutation < MatcherAssertion
111
+ def self.name_prefix
112
+ 'refute'
113
+ end
114
+
115
+ def self.matcher_test_method
116
+ :does_not_match?
117
+ end
118
+
119
+ def self.matcher_failure_message_method
120
+ :failure_message_when_negated
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,31 @@
1
+ require 'erb'
2
+ require 'capybara/minitest/assertions/matcher'
3
+
4
+ BASE_FILE = __FILE__.chomp('.rake')
5
+ TEMPLATE_FILE = "#{BASE_FILE}.rb.erb"
6
+ OUTPUT_FILE = "#{BASE_FILE}.rb"
7
+
8
+ module Capybara
9
+ module Minitest
10
+ module Assertions
11
+ # Context for rdoc.rb.erb.
12
+ class RDocTemplate
13
+ extend ERB::DefMethod
14
+ def_erb_method 'render', TEMPLATE_FILE
15
+
16
+ def initialize
17
+ @assertion_names = Matcher.all.map do |matcher|
18
+ matcher.assertions.map(&:name)
19
+ end.flatten
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ desc 'Regenerate the RDoc for the Capybara assertions.'
27
+ task OUTPUT_FILE do
28
+ File.open(OUTPUT_FILE, 'w') do |f|
29
+ f.write(Capybara::Minitest::Assertions::RDocTemplate.new.render)
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ # This file is auto-generated. To regenerate:
2
+ # $ rake lib/capybara/minitest/assertions/rdoc.rb
3
+
4
+ module Capybara
5
+ module Minitest
6
+ module Assertions
7
+ # Provide documentation for dynamically defined assertion methods.
8
+ # :method: assert_has_selector
9
+ # :method: refute_has_selector
10
+ # :method: assert_has_xpath
11
+ # :method: refute_has_xpath
12
+ # :method: assert_has_css
13
+ # :method: refute_has_css
14
+ # :method: assert_has_text
15
+ # :method: refute_has_text
16
+ # :method: assert_has_content
17
+ # :method: refute_has_content
18
+ # :method: assert_has_title
19
+ # :method: refute_has_title
20
+ # :method: assert_has_link
21
+ # :method: refute_has_link
22
+ # :method: assert_has_button
23
+ # :method: refute_has_button
24
+ # :method: assert_has_field
25
+ # :method: refute_has_field
26
+ # :method: assert_has_checked_field
27
+ # :method: refute_has_checked_field
28
+ # :method: assert_has_unchecked_field
29
+ # :method: refute_has_unchecked_field
30
+ # :method: assert_has_select
31
+ # :method: refute_has_select
32
+ # :method: assert_has_table
33
+ # :method: refute_has_table
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,12 @@
1
+ # This file is auto-generated. To regenerate:
2
+ # $ rake lib/capybara/minitest/assertions/rdoc.rb
3
+
4
+ module Capybara
5
+ module Minitest
6
+ module Assertions
7
+ # Provide documentation for dynamically defined assertion methods.
8
+ <% @assertion_names.each do |assertion_name| %># :method: <%= assertion_name %>
9
+ <% end %>
10
+ end
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-minitest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.2
5
+ platform: ruby
6
+ authors:
7
+ - Dennis Stevense
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ description: Provides assertions for minitest based on Capybara's RSpec matchers.
84
+ email:
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - LICENSE.txt
90
+ - README.md
91
+ - lib/capybara-minitest.rb
92
+ - lib/capybara-minitest/version.rb
93
+ - lib/capybara/minitest.rb
94
+ - lib/capybara/minitest/assertions.rb
95
+ - lib/capybara/minitest/assertions/matcher.rb
96
+ - lib/capybara/minitest/assertions/rdoc.rake
97
+ - lib/capybara/minitest/assertions/rdoc.rb
98
+ - lib/capybara/minitest/assertions/rdoc.rb.erb
99
+ homepage: https://github.com/decafdennis/capybara-minitest
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.2.2
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Capybara assertions for minitest.
123
+ test_files: []