minitest-capybara-unit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/lib/minitest-capybara-unit.rb +95 -0
- data/lib/minitest-capybara-unit/version.rb +7 -0
- data/minitest-capybara-unit.gemspec +19 -0
- metadata +85 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Francesco Rodriguez
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Minitest::Capybara::Unit
|
2
|
+
|
3
|
+
MiniTest::Unit assertions for Capybara node matchers.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'minitest-capybara-unit'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install minitest-capybara-unit
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
<table>
|
22
|
+
<thead>
|
23
|
+
<tr>
|
24
|
+
<th>Capybara</th>
|
25
|
+
<th>Minitest Capybara Unit</th>
|
26
|
+
</tr>
|
27
|
+
</thead>
|
28
|
+
<tbody>
|
29
|
+
<tr>
|
30
|
+
<td>assert page.has_button?</td>
|
31
|
+
<td>assert_page_has_button</td>
|
32
|
+
<tr>
|
33
|
+
<tr>
|
34
|
+
<td>refute page.has_button?</td>
|
35
|
+
<td>refute_page_has_button</td>
|
36
|
+
<tr>
|
37
|
+
</tbody>
|
38
|
+
</table>
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'minitest/unit'
|
2
|
+
require 'capybara'
|
3
|
+
|
4
|
+
module Minitest
|
5
|
+
module Capybara
|
6
|
+
module Unit
|
7
|
+
class Matcher
|
8
|
+
attr_reader :name
|
9
|
+
|
10
|
+
def initialize(node_matcher_name)
|
11
|
+
@name = MatcherName.new(node_matcher_name)
|
12
|
+
define_assert
|
13
|
+
define_refute
|
14
|
+
end
|
15
|
+
|
16
|
+
def define_assert
|
17
|
+
define_assertion
|
18
|
+
end
|
19
|
+
|
20
|
+
def define_refute
|
21
|
+
name.negate!
|
22
|
+
define_assertion
|
23
|
+
end
|
24
|
+
|
25
|
+
def test(page, *args)
|
26
|
+
wrap(page).send(name.original, *args)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.failure_message(assertion_method, matcher_name, *args)
|
30
|
+
if assertion_method == 'assert'
|
31
|
+
message = "Matcher failed: "
|
32
|
+
else
|
33
|
+
message = 'Matcher should have failed: '
|
34
|
+
end
|
35
|
+
message += "#{matcher_name}(#{args.map(&:inspect).join(', ')})"
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def define_assertion
|
41
|
+
matcher = self
|
42
|
+
assertion_method = name.positive? ? 'assert' : 'refute'
|
43
|
+
|
44
|
+
::MiniTest::Assertions.send :define_method, name.assertion do |*args|
|
45
|
+
message = matcher.class.failure_message(assertion_method, matcher.name.original, *args)
|
46
|
+
send(assertion_method, matcher.test(page, *args), message)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def wrap(actual)
|
51
|
+
if actual.respond_to?("has_selector?")
|
52
|
+
actual
|
53
|
+
else
|
54
|
+
Capybara.string(actual.to_s)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
class MatcherName
|
61
|
+
attr_reader :original, :positive
|
62
|
+
|
63
|
+
def initialize(name)
|
64
|
+
@original = name
|
65
|
+
@positive = true
|
66
|
+
end
|
67
|
+
|
68
|
+
def positive?
|
69
|
+
!!positive
|
70
|
+
end
|
71
|
+
|
72
|
+
def negate!
|
73
|
+
@positive = !positive
|
74
|
+
end
|
75
|
+
|
76
|
+
def without_question_mark
|
77
|
+
original.to_s.sub(/\?$/, '')
|
78
|
+
end
|
79
|
+
|
80
|
+
def assertion
|
81
|
+
if positive?
|
82
|
+
"assert_page_#{without_question_mark}"
|
83
|
+
else
|
84
|
+
"refute_page_#{without_question_mark}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
Capybara::Node::Matchers.public_instance_methods.each do |matcher_name|
|
94
|
+
Minitest::Capybara::Unit::Matcher.new(matcher_name)
|
95
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/minitest-capybara-unit/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Francesco Rodriguez']
|
6
|
+
gem.email = ['lrodriguezsanc@gmail.com']
|
7
|
+
gem.description = %q{MiniTest::Unit assertions for Capybara node matchers}
|
8
|
+
gem.summary = %q{MiniTest::Unit assertions for Capybara node matchers}
|
9
|
+
gem.homepage = 'https://github.com/frodsan/minitest-capybara-unit'
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = 'minitest-capybara-unit'
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
gem.version = Minitest::Capybara::Unit::VERSION
|
16
|
+
|
17
|
+
gem.add_runtime_dependency 'minitest', '~> 3.1.0'
|
18
|
+
gem.add_runtime_dependency 'capybara', '~> 1.1.2'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minitest-capybara-unit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Francesco Rodriguez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: capybara
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.1.2
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.1.2
|
46
|
+
description: MiniTest::Unit assertions for Capybara node matchers
|
47
|
+
email:
|
48
|
+
- lrodriguezsanc@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/minitest-capybara-unit.rb
|
59
|
+
- lib/minitest-capybara-unit/version.rb
|
60
|
+
- minitest-capybara-unit.gemspec
|
61
|
+
homepage: https://github.com/frodsan/minitest-capybara-unit
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.23
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: MiniTest::Unit assertions for Capybara node matchers
|
85
|
+
test_files: []
|