, . - , assert. , has_reply?, :
assert page.has_reply?("my reply")
must_have_reply, . , has_reply?. , .
" (.. )". , must_have_reply. , this subject. , . , (assert_equal, refute_equal) (must_be_equal, wont_be_equal). Matcher, API- Matcher.
API. , , Cabybara have_css matcher, Capybara HaveSelector API. Matchers , HasSelector.
require "minitest/matchers"
require "capybara/rspec/matchers"
module YourApp
module Matchers
def have_reply text
Capybara::RSpecMatchers::HaveSelector.new(:css, ".comment_body", :text => text)
end
def self.included base
instance_methods.each do |name|
base.register_matcher name, name
end
end
end
end
minitest_helper.rb Matchers, . ( .)
class MiniTest::Rails::ActiveSupport::TestCase
include YourApp::Matchers
end
Minitest Matchers . :
def test_using_an_assertion
visit root_path
assert_have_reply page, "my reply"
end
:
it "is an expectation" do
visit root_path
page.must_have_reply "my reply"
end
, , :
describe "with a subject" do
before { visit root_path }
subject { page }
it { must have_reply("my reply") }
must { have_reply "my reply" }
end
. "gem minitest-matchers", ' >= 1.2.0', register_matcher .