capybara_minitest_spec 0.1.1 → 0.1.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.
- data/README.md +1 -5
- data/lib/capybara_minitest_spec/version.rb +1 -1
- data/lib/capybara_minitest_spec.rb +14 -2
- data/test/matchers_spec.rb +13 -0
- metadata +1 -1
data/README.md
CHANGED
@@ -24,13 +24,9 @@ Compatibility
|
|
24
24
|
|
25
25
|
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
26
|
|
27
|
-
TODO
|
28
|
-
----
|
29
|
-
|
30
|
-
* Better failure messages.
|
31
27
|
|
32
28
|
Testing
|
33
29
|
-------
|
34
30
|
|
35
|
-
This gem was tested by copying the Capybara spec located in 'spec/rspec/matchers_spec.rb' and altering the test to run with MiniTest.
|
31
|
+
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.
|
36
32
|
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.
|
@@ -13,7 +13,7 @@ module MiniTest::Expectations
|
|
13
13
|
# Define positive assertion.
|
14
14
|
positive_assertion_name = :"assert_page_#{without_question_mark}"
|
15
15
|
define_method positive_assertion_name do |page, *args|
|
16
|
-
assert wrap(page).send(matcher_name, *args),
|
16
|
+
assert wrap(page).send(matcher_name, *args), positive_failure_message(matcher_name, *args)
|
17
17
|
end
|
18
18
|
|
19
19
|
# Infect positive assertion.
|
@@ -23,7 +23,7 @@ module MiniTest::Expectations
|
|
23
23
|
# Define negative assertion.
|
24
24
|
negative_assertion_name = :"refute_page_#{without_question_mark}"
|
25
25
|
define_method negative_assertion_name do |page, *args|
|
26
|
-
refute wrap(page).send(matcher_name, *args),
|
26
|
+
refute wrap(page).send(matcher_name, *args), negative_failure_message(matcher_name, *args)
|
27
27
|
end
|
28
28
|
|
29
29
|
# Infect negative assertions.
|
@@ -43,4 +43,16 @@ module MiniTest::Expectations
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
def base_failure_message(matcher_name, *args)
|
47
|
+
"#{matcher_name}(#{args.join(', ')})"
|
48
|
+
end
|
49
|
+
|
50
|
+
def positive_failure_message(matcher_name, *args)
|
51
|
+
"Matcher failed: #{base_failure_message(matcher_name, *args)}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def negative_failure_message(matcher_name, *args)
|
55
|
+
"Matcher should have failed: #{base_failure_message(matcher_name, *args)}"
|
56
|
+
end
|
57
|
+
|
46
58
|
end
|
data/test/matchers_spec.rb
CHANGED
@@ -444,4 +444,17 @@ describe CapybaraMinitestSpec do
|
|
444
444
|
end.must_raise(/expected table "No such Table"/)
|
445
445
|
end
|
446
446
|
end
|
447
|
+
|
448
|
+
describe 'failure message' do
|
449
|
+
it 'shows matcher name and args' do
|
450
|
+
begin
|
451
|
+
'actual'.must_have_css('expected', :count => 1)
|
452
|
+
rescue MiniTest::Assertion => ex
|
453
|
+
exception = ex
|
454
|
+
else
|
455
|
+
flunk 'No exception was raised'
|
456
|
+
end
|
457
|
+
assert_equal 'Matcher failed: has_css?(expected, {:count=>1})', exception.message
|
458
|
+
end
|
459
|
+
end
|
447
460
|
end
|