Module: CapybaraMiniTestSpec
- Defined in:
- lib/capybara_minitest_spec.rb,
lib/capybara_minitest_spec/version.rb,
lib/capybara_minitest_spec/test_name.rb
Defined Under Namespace
Classes: NegativeTestName, PositiveTestName, TestName
Constant Summary collapse
- VERSION =
'1.0.7'
Class Method Summary collapse
-
.add_matcher(matcher_name) ⇒ Object
Define assertions and spec expectations for both positive and negative forms of the matcher name.
-
.define_assertion(test_name) ⇒ Object
Define an assertion using test_name.
- .define_expectation(test_name) ⇒ Object
-
.infect_assertion(test_name) ⇒ Object
Define the MiniTest::Spec expectation.
Class Method Details
.add_matcher(matcher_name) ⇒ Object
Define assertions and spec expectations for both positive and negative forms of the matcher name.
13 14 15 16 17 18 19 |
# File 'lib/capybara_minitest_spec.rb', line 13 def add_matcher(matcher_name) positive_name = CapybaraMiniTestSpec::PositiveTestName.new(matcher_name) negative_name = CapybaraMiniTestSpec::NegativeTestName.new(matcher_name) [positive_name, negative_name].each do |test_name| CapybaraMiniTestSpec.define_expectation(test_name) end end |
.define_assertion(test_name) ⇒ Object
Define an assertion using test_name. For example, if the test name is have_css, the assertion would be called assert_page_has_css.
Use either of Capybara::RSpecMatchers. Assert that it matches, and pass its failure message if it doesn’t.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/capybara_minitest_spec.rb', line 32 def define_assertion(test_name) method_name = test_name.assertion_name MiniTest::Assertions.send :define_method, method_name do |page, *args| matcher = test_name.matcher(*args) matches = matcher.send(test_name.match_method, page) = do matcher.send(test_name.) end assert matches, end end |
.define_expectation(test_name) ⇒ Object
21 22 23 24 |
# File 'lib/capybara_minitest_spec.rb', line 21 def define_expectation(test_name) define_assertion(test_name) infect_assertion(test_name) end |
.infect_assertion(test_name) ⇒ Object
Define the MiniTest::Spec expectation.
47 48 49 |
# File 'lib/capybara_minitest_spec.rb', line 47 def infect_assertion(test_name) MiniTest::Expectations.infect_an_assertion test_name.assertion_name, test_name.expectation_name, true end |