minitest-capybara 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +37 -11
- data/VERSION +1 -0
- data/lib/minitest-capybara.rb +1 -17
- data/lib/minitest/capybara.rb +83 -0
- data/lib/minitest/capybara/version.rb +5 -0
- data/minitest-capybara.gemspec +3 -3
- data/test/minitest/capybara_test.rb +83 -0
- metadata +25 -36
- data/test/minitest-capybara_test.rb +0 -27
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d5d8349d1840c9e41fe11bbad48becf9e5528d6f
|
4
|
+
data.tar.gz: 6bc1d2578e4463b58ea58209234d03615c5476c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c189863a60328620e1bcfb47c472f15c2dc1f4482cfa440c6a8fc6feb0a5ba8c519bbff2ddf756190aa62342c5b6571365ba04f477537882d4d57d611b1c836
|
7
|
+
data.tar.gz: d4afd15a1059f04230e9805ee8d02ef0e02b9639bfb62aa3623abbaa553cf859a844596cca081a3ce8096bbda3f48b6df1f0fe800bc5b4e0f1f59a71d98910d1
|
data/README.md
CHANGED
@@ -4,8 +4,9 @@ Capybara matchers support for minitest unit & spec
|
|
4
4
|
|
5
5
|
## Why?
|
6
6
|
|
7
|
-
Capybara has good support for RSpec.
|
8
|
-
|
7
|
+
Capybara has good support for RSpec.
|
8
|
+
|
9
|
+
If you want to use it with minitest, you can of course write:
|
9
10
|
|
10
11
|
```ruby
|
11
12
|
assert page.has_content?("Hello")
|
@@ -20,6 +21,8 @@ With this project minitest gets all the good stuff.
|
|
20
21
|
|
21
22
|
## Usage
|
22
23
|
|
24
|
+
See example app: https://github.com/wojtekmach/minitest-capybara-example
|
25
|
+
|
23
26
|
Add to Gemfile:
|
24
27
|
|
25
28
|
```ruby
|
@@ -30,16 +33,25 @@ end
|
|
30
33
|
```
|
31
34
|
|
32
35
|
Next, I like to create seperate test class for acceptance tests.
|
33
|
-
Note, Rails 4.0 will support minitest/spec out of the box, so you would just
|
34
|
-
subclass `ActiveSupport::TestCase` instead of `MiniTest::Spec.`
|
35
36
|
|
36
37
|
```ruby
|
37
38
|
# test/test_helper.rb
|
38
39
|
require "capybara/rails"
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
# for just minitest/unit
|
42
|
+
class AcceptanceTest < Minitest::Unit::TestCase
|
42
43
|
include Capybara::DSL
|
44
|
+
include Minitest::Capybara::Assertions
|
45
|
+
|
46
|
+
def teardown
|
47
|
+
Capybara.reset_session!
|
48
|
+
Capybara.use_default_driver
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# for minitest/spec
|
53
|
+
class AcceptanceSpec < AcceptanceTest
|
54
|
+
extend Minitest::Spec::DSL
|
43
55
|
end
|
44
56
|
```
|
45
57
|
|
@@ -49,10 +61,24 @@ Finally, you can use it like this:
|
|
49
61
|
# test/acceptance/home_test.rb
|
50
62
|
require "test_helper"
|
51
63
|
|
52
|
-
class HomeTest <
|
64
|
+
class HomeTest < AcceptanceSpec
|
53
65
|
it "home test" do
|
54
66
|
visit "/"
|
55
|
-
|
67
|
+
|
68
|
+
assert_content "Homepage"
|
69
|
+
page.must_have_content "Homepage"
|
70
|
+
|
71
|
+
within ".login" do
|
72
|
+
refute_content "Signed in as"
|
73
|
+
page.wont_have_content "Signed in as"
|
74
|
+
end
|
75
|
+
|
76
|
+
assert_link "Sign in"
|
77
|
+
assert_link find(".login"), "Sign in"
|
78
|
+
find(".login").must_have_link("Sign in")
|
79
|
+
|
80
|
+
assert_selector 'li:first', text: "Item 1"
|
81
|
+
page.must_have_selector 'li:first', text: "Item 1"
|
56
82
|
end
|
57
83
|
end
|
58
84
|
```
|
@@ -66,7 +92,7 @@ Switching drivers is easy with [minitest-metadata]:
|
|
66
92
|
```ruby
|
67
93
|
require 'minitest-metadata'
|
68
94
|
|
69
|
-
class
|
95
|
+
class AcceptanceSpec
|
70
96
|
before do
|
71
97
|
if metadata[:js]
|
72
98
|
Capybara.current_driver = Capybara.javascript_driver
|
@@ -76,10 +102,10 @@ class AcceptanceTest
|
|
76
102
|
end
|
77
103
|
end
|
78
104
|
|
79
|
-
class HomeTest <
|
105
|
+
class HomeTest < AcceptanceSpec
|
80
106
|
it "home with ajax", js: true do
|
81
107
|
visit "/"
|
82
|
-
must_have_content "AJAX enabled..."
|
108
|
+
page.must_have_content "AJAX enabled..."
|
83
109
|
end
|
84
110
|
end
|
85
111
|
```
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
data/lib/minitest-capybara.rb
CHANGED
@@ -1,17 +1 @@
|
|
1
|
-
require
|
2
|
-
require "capybara/dsl"
|
3
|
-
require "capybara/rspec/matchers"
|
4
|
-
|
5
|
-
module Minitest
|
6
|
-
module Capybara
|
7
|
-
VERSION = "0.2.0"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
Capybara::RSpecMatchers.module_eval do
|
12
|
-
def self.included(base)
|
13
|
-
instance_methods.each do |name|
|
14
|
-
base.register_matcher name, name
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
require 'minitest/capybara'
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'minitest/capybara/version'
|
2
|
+
require 'minitest/spec'
|
3
|
+
|
4
|
+
module Minitest::Capybara
|
5
|
+
module Assertions
|
6
|
+
METHODS = Capybara::Session::NODE_METHODS.grep(/^has_/).map { |s| s.to_s.match(/has_(.*?)\?/)[1] }
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
raise "Make sure to include Capybara::Minitest::Assertions after Capybara::DSL" unless base < Capybara::DSL
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.assertion_name(method)
|
13
|
+
method.start_with?('no_') ? "refute_#{method.gsub(/^no_/, '')}" : "assert_#{method}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def assert_text(*args)
|
17
|
+
node, *args = prepare_args(args)
|
18
|
+
assert has_text?(*args), message { "Expected to include #{args.first.inspect}" }
|
19
|
+
end
|
20
|
+
alias_method :assert_content, :assert_text
|
21
|
+
|
22
|
+
def refute_text(*args)
|
23
|
+
node, *args = prepare_args(args)
|
24
|
+
assert has_no_text?(*args), message { "Expected not to include #{args.first.inspect}" }
|
25
|
+
end
|
26
|
+
alias_method :refute_content, :refute_text
|
27
|
+
|
28
|
+
def assert_selector(*args)
|
29
|
+
node, *args = prepare_args(args)
|
30
|
+
node.assert_selector(*args)
|
31
|
+
rescue Capybara::ExpectationNotMet => e
|
32
|
+
assert false, e.message
|
33
|
+
end
|
34
|
+
|
35
|
+
def refute_selector(*args)
|
36
|
+
node, *args = prepare_args(args)
|
37
|
+
node.assert_no_selector(*args)
|
38
|
+
rescue Capybara::ExpectationNotMet => e
|
39
|
+
assert false, e.message
|
40
|
+
end
|
41
|
+
|
42
|
+
ruby = ""
|
43
|
+
(METHODS - %w[text no_text content no_content selector no_selector]).each do |method|
|
44
|
+
assertion_name = method.start_with?('no') ? "refute_#{method.gsub(/^no_/, '')}" : "assert_#{method}"
|
45
|
+
|
46
|
+
ruby << <<-RUBY
|
47
|
+
def #{assertion_name}(*args)
|
48
|
+
node, *args = prepare_args(args)
|
49
|
+
assert node.has_#{method}?(*args), message { Capybara::Helpers.failure_message(*args) }
|
50
|
+
end
|
51
|
+
RUBY
|
52
|
+
end
|
53
|
+
class_eval(ruby)
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def prepare_args(args)
|
58
|
+
if args.first.is_a?(Capybara::Session) || args.first.kind_of?(Capybara::Node::Base)
|
59
|
+
args
|
60
|
+
else
|
61
|
+
[page, *args]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module Expectations
|
67
|
+
def self.expectation_name(method)
|
68
|
+
method.start_with?('no_') ? "wont_have_#{method.gsub(/^no_/, '')}" : "must_have_#{method}"
|
69
|
+
end
|
70
|
+
|
71
|
+
Assertions::METHODS.each do |method|
|
72
|
+
infect_an_assertion Assertions.assertion_name(method), expectation_name(method), :reverse
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class Capybara::Session
|
78
|
+
include Minitest::Capybara::Expectations
|
79
|
+
end
|
80
|
+
|
81
|
+
class Capybara::Node::Base
|
82
|
+
include Minitest::Capybara::Expectations
|
83
|
+
end
|
data/minitest-capybara.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "minitest
|
3
|
+
require "minitest/capybara/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "minitest-capybara"
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_dependency "
|
22
|
-
s.add_dependency "capybara", "~> 1.0"
|
21
|
+
s.add_dependency "capybara", "~> 2.0"
|
23
22
|
|
24
23
|
s.add_runtime_dependency "rake"
|
24
|
+
s.add_runtime_dependency "minitest", "~> 4.0"
|
25
25
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
|
3
|
+
require "capybara"
|
4
|
+
require "minitest/capybara"
|
5
|
+
|
6
|
+
Capybara.app = lambda { |env| [200, {}, "<div><h1>foo</h1><a href='/'>bar</a></div>"] }
|
7
|
+
|
8
|
+
describe "app" do
|
9
|
+
include Capybara::DSL
|
10
|
+
include Minitest::Capybara::Assertions
|
11
|
+
|
12
|
+
before do
|
13
|
+
visit "/"
|
14
|
+
end
|
15
|
+
|
16
|
+
# assertions
|
17
|
+
|
18
|
+
it "supports assert_content" do
|
19
|
+
assert_content("foo").must_equal true
|
20
|
+
proc { assert_content("BAD") }.must_raise Minitest::Assertion
|
21
|
+
end
|
22
|
+
|
23
|
+
it "supports refute_content" do
|
24
|
+
refute_content("BAD").must_equal true
|
25
|
+
proc { refute_content("foo") }.must_raise Minitest::Assertion
|
26
|
+
end
|
27
|
+
|
28
|
+
it "supports assert_selector" do
|
29
|
+
assert_selector "h1", text: "foo"
|
30
|
+
assert_selector :css, "h1", text: "foo"
|
31
|
+
proc { assert_selector "h1", text: "BAD" }.must_raise Minitest::Assertion
|
32
|
+
proc { assert_selector :css, "h1", text: "BAD" }.must_raise Minitest::Assertion
|
33
|
+
end
|
34
|
+
|
35
|
+
it "supports refute_selector" do
|
36
|
+
refute_selector "h1", text: "BAD"
|
37
|
+
proc { refute_selector "h1", text: "foo" }.must_raise Minitest::Assertion
|
38
|
+
end
|
39
|
+
|
40
|
+
it "supports assert_link" do
|
41
|
+
assert_link 'bar'
|
42
|
+
proc { assert_link("BAD") }.must_raise Minitest::Assertion
|
43
|
+
end
|
44
|
+
|
45
|
+
it "supports refute_link" do
|
46
|
+
refute_link 'BAD'
|
47
|
+
proc { refute_link("bar") }.must_raise Minitest::Assertion
|
48
|
+
end
|
49
|
+
|
50
|
+
# expectations
|
51
|
+
|
52
|
+
it "supports must_have_content" do
|
53
|
+
page.must_have_content "foo"
|
54
|
+
proc { page.must_have_content "BAD" }.must_raise Minitest::Assertion
|
55
|
+
end
|
56
|
+
|
57
|
+
it "supports wont_have_content" do
|
58
|
+
page.wont_have_content "BAD"
|
59
|
+
proc { page.wont_have_content "foo" }.must_raise Minitest::Assertion
|
60
|
+
end
|
61
|
+
|
62
|
+
it "supports must_have_selector" do
|
63
|
+
page.must_have_selector "h1", text: "foo"
|
64
|
+
page.must_have_selector :css, "h1", text: "foo"
|
65
|
+
proc { page.must_have_selector "h1", text: "BAD" }.must_raise Minitest::Assertion
|
66
|
+
proc { page.must_have_selector :css, "h1", text: "BAD" }.must_raise Minitest::Assertion
|
67
|
+
end
|
68
|
+
|
69
|
+
it "supports wont_have_selector" do
|
70
|
+
page.wont_have_selector "h1", text: "BAD"
|
71
|
+
proc { page.wont_have_selector "h1", text: "foo" }.must_raise Minitest::Assertion
|
72
|
+
end
|
73
|
+
|
74
|
+
it "supports must_have_link" do
|
75
|
+
page.must_have_link 'bar'
|
76
|
+
proc { page.must_have_link("BAD") }.must_raise Minitest::Assertion
|
77
|
+
end
|
78
|
+
|
79
|
+
it "supports wont_have_link" do
|
80
|
+
page.wont_have_link 'BAD'
|
81
|
+
proc { page.wont_have_link("bar") }.must_raise Minitest::Assertion
|
82
|
+
end
|
83
|
+
end
|
metadata
CHANGED
@@ -1,64 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-capybara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Wojciech Mach
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-06-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: capybara
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
19
|
+
version: '2.0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
26
|
+
version: '2.0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
28
|
+
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
33
|
+
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
40
|
+
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
42
|
+
name: minitest
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
47
|
+
version: '4.0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
54
|
+
version: '4.0'
|
62
55
|
description: Capybara matchers support for minitest unit and spec
|
63
56
|
email:
|
64
57
|
- wojtek@wojtekmach.pl
|
@@ -70,38 +63,34 @@ files:
|
|
70
63
|
- Gemfile
|
71
64
|
- README.md
|
72
65
|
- Rakefile
|
66
|
+
- VERSION
|
73
67
|
- lib/minitest-capybara.rb
|
68
|
+
- lib/minitest/capybara.rb
|
69
|
+
- lib/minitest/capybara/version.rb
|
74
70
|
- minitest-capybara.gemspec
|
75
|
-
- test/minitest
|
71
|
+
- test/minitest/capybara_test.rb
|
76
72
|
homepage: ''
|
77
73
|
licenses: []
|
74
|
+
metadata: {}
|
78
75
|
post_install_message:
|
79
76
|
rdoc_options: []
|
80
77
|
require_paths:
|
81
78
|
- lib
|
82
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
-
none: false
|
84
80
|
requirements:
|
85
|
-
- -
|
81
|
+
- - '>='
|
86
82
|
- !ruby/object:Gem::Version
|
87
83
|
version: '0'
|
88
|
-
segments:
|
89
|
-
- 0
|
90
|
-
hash: -2882241969094489830
|
91
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
-
none: false
|
93
85
|
requirements:
|
94
|
-
- -
|
86
|
+
- - '>='
|
95
87
|
- !ruby/object:Gem::Version
|
96
88
|
version: '0'
|
97
|
-
segments:
|
98
|
-
- 0
|
99
|
-
hash: -2882241969094489830
|
100
89
|
requirements: []
|
101
90
|
rubyforge_project: minitest-capybara
|
102
|
-
rubygems_version:
|
91
|
+
rubygems_version: 2.0.3
|
103
92
|
signing_key:
|
104
|
-
specification_version:
|
93
|
+
specification_version: 4
|
105
94
|
summary: Capybara matchers support for minitest unit and spec
|
106
95
|
test_files:
|
107
|
-
- test/minitest
|
96
|
+
- test/minitest/capybara_test.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require "minitest-capybara"
|
2
|
-
require "minitest/autorun"
|
3
|
-
|
4
|
-
describe "test" do
|
5
|
-
include Capybara::RSpecMatchers
|
6
|
-
|
7
|
-
it "supports have_selector" do
|
8
|
-
subject = "<h1>hello <a>asd</a></h1>"
|
9
|
-
args = [:css, "h1 a", {:text => "asd"}]
|
10
|
-
|
11
|
-
assert_have_selector subject, *args
|
12
|
-
subject.must_have_selector *args
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
Capybara.app = lambda { |env| [200, {}, "<p><h1>foo</h1></p>"] }
|
17
|
-
|
18
|
-
describe "app" do
|
19
|
-
include Capybara::RSpecMatchers
|
20
|
-
include Capybara::DSL
|
21
|
-
|
22
|
-
it "works" do
|
23
|
-
visit "/"
|
24
|
-
assert_have_content(page, "foo").must_equal true
|
25
|
-
proc { refute_have_content page, "foo" }.must_raise MiniTest::Assertion
|
26
|
-
end
|
27
|
-
end
|