capybara_minitest_spec 0.2.0 → 0.2.1
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.
- data/README.md +34 -10
- data/lib/capybara_minitest_spec/matcher.rb +1 -0
- data/lib/capybara_minitest_spec/version.rb +1 -1
- data/lib/capybara_minitest_spec.rb +1 -2
- data/test/custom_matcher_spec.rb +29 -0
- data/test/spec_helper.rb +0 -9
- data/test_app/test_app.rb +4 -0
- metadata +3 -1
data/README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
Capybara MiniTest Spec
|
2
|
-
======================
|
1
|
+
# Capybara MiniTest Spec
|
3
2
|
|
4
3
|
Define MiniTest::Spec expectations for Capybara node matchers.
|
5
4
|
|
6
|
-
Description
|
7
|
-
-----------
|
5
|
+
## Description
|
8
6
|
|
9
7
|
If you like using Capybara and RSpec, you're used to matchers like:
|
10
8
|
|
@@ -14,19 +12,45 @@ Now you can have similar functionality while using MiniTest::Spec:
|
|
14
12
|
|
15
13
|
page.must_have_content('Title')
|
16
14
|
|
17
|
-
Install
|
18
|
-
-------
|
15
|
+
## Install
|
19
16
|
|
20
17
|
gem install caypbara_minitest_spec
|
21
18
|
|
22
|
-
|
23
|
-
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
The gem iterates through all of Capybara::Node's matcher methods and defines these things for each one:
|
22
|
+
|
23
|
+
* positive assertion: assert_page_has_css(page, 'h1')
|
24
|
+
* positive expectation: page.must_have_css('h1')
|
25
|
+
* negative assertion: refute_page_has_css(page, 'h1')
|
26
|
+
* negative expectation: page.wont_have_css('h1')
|
27
|
+
|
28
|
+
### Custom Expectations
|
29
|
+
|
30
|
+
If you want to add your own custom page expectations, it's easy.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# First define a Capybara session method so that
|
34
|
+
# page.has_flash_message?(message) is available.
|
35
|
+
class Capybara::Session
|
36
|
+
def has_flash_message?(message)
|
37
|
+
within '#flash' do
|
38
|
+
has_content? message
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
# Then create a new CapybaraMiniTestSpec::Matcher.
|
43
|
+
CapybaraMiniTestSpec::Matcher.new(:has_flash_message?)
|
44
|
+
```
|
45
|
+
|
46
|
+
Now you can do `page.must_have_flash_message('Successfully created')`
|
47
|
+
|
48
|
+
## Compatibility
|
24
49
|
|
25
50
|
In theory, this should work with any version of Capybara, so the runtime dependency is not version specific. At the time of this writing, it was tested with Capybara 1.1.1.
|
26
51
|
|
27
52
|
|
28
|
-
Testing
|
29
|
-
-------
|
53
|
+
## Testing
|
30
54
|
|
31
55
|
This gem was tested by basically copying the Capybara spec located in 'spec/rspec/matchers_spec.rb' and altering the test to run with MiniTest.
|
32
56
|
Capybara uses xpath as a submodule of the git repository. When adding this gem to gemtesters (http://test.rubygems.org/gems/capybara_minitest_spec), it sounded like too much trouble to check out the submodule, so I just used the regular gem.
|
@@ -7,6 +7,5 @@ require "capybara_minitest_spec/version"
|
|
7
7
|
# define positive and negative MiniTest::Unit assertions and
|
8
8
|
# infect it both assertions to create MiniTest::Spec expectations.
|
9
9
|
Capybara::Node::Matchers.public_instance_methods.each do |matcher_name|
|
10
|
-
|
11
|
-
matcher.define_expectations
|
10
|
+
CapybaraMiniTestSpec::Matcher.new(matcher_name)
|
12
11
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Capybara::Session
|
4
|
+
def has_flash_message?(message)
|
5
|
+
within '#flash' do
|
6
|
+
has_content? message
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
CapybaraMiniTestSpec::Matcher.new(:has_flash_message?)
|
11
|
+
|
12
|
+
describe 'Custom matcher' do
|
13
|
+
include Capybara::DSL
|
14
|
+
|
15
|
+
before :each do
|
16
|
+
Capybara.default_selector = :css
|
17
|
+
visit '/flash_message'
|
18
|
+
end
|
19
|
+
|
20
|
+
after { Capybara.default_selector = :xpath }
|
21
|
+
|
22
|
+
it 'works with positive expectation' do
|
23
|
+
page.must_have_flash_message 'Barry Allen'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'works with negative expectation' do
|
27
|
+
page.wont_have_flash_message 'The Blob'
|
28
|
+
end
|
29
|
+
end
|
data/test/spec_helper.rb
CHANGED
@@ -12,12 +12,3 @@ MiniTest::Spec.register_spec_type //, MiniTest::Spec
|
|
12
12
|
$LOAD_PATH << File.join(__FILE__, '../../test_app')
|
13
13
|
require 'test_app'
|
14
14
|
Capybara.app = TestApp
|
15
|
-
|
16
|
-
# Set Capybara default selector to xpath.
|
17
|
-
class MiniTest::Spec
|
18
|
-
before :each do
|
19
|
-
Capybara.configure do |config|
|
20
|
-
config.default_selector = :xpath
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/test_app/test_app.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: capybara_minitest_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jared Ning
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- lib/capybara_minitest_spec/matcher.rb
|
69
69
|
- lib/capybara_minitest_spec/version.rb
|
70
70
|
- test/capybara_node_matchers_spec.rb
|
71
|
+
- test/custom_matcher_spec.rb
|
71
72
|
- test/matcher_spec.rb
|
72
73
|
- test/spec_helper.rb
|
73
74
|
- test_app/driver.rb
|
@@ -157,5 +158,6 @@ specification_version: 3
|
|
157
158
|
summary: MiniTest::Spec expectations for Capybara node matchers.
|
158
159
|
test_files:
|
159
160
|
- test/capybara_node_matchers_spec.rb
|
161
|
+
- test/custom_matcher_spec.rb
|
160
162
|
- test/matcher_spec.rb
|
161
163
|
- test/spec_helper.rb
|