Repository is archived
No commit activity in last 3 years
No release in over 3 years
Use Capybara matchers with MiniTest. Specifically, it defines MiniTest::Spec expectations like page.must_have_content('content').
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

>= 0
>= 0.9.4

Runtime

 Project Readme

CapybaraMiniTestSpec

DEPRECATED

Capybara now supports minitest out of the box. So this gem is no longer necessary.

Build Status

Description

If you've used Capybara and RSpec, you've probably used matchers like:

page.should have_content('Title')

With CapybaraMiniTestSpec you can have similar functionality while using MiniTest::Spec:

page.must_have_content('Title')

You can also use the TestUnit style assertions:

assert_page_has_content page, 'Title'

But if you really want to be simple with MiniTest::Unit, you don't need this gem. You can do the following without this gem:

assert page.has_content?('Title'), 'Your custom failure message'

However, if you choose to use this gem, you get Capybara's failure messages as if you were using RSpec matchers.

assert_page_has_content?('<h1>Content</h1>', 'No such Text')
# fails with 'expected there to be text "No such Text" in "Content"'

You can see all the available matchers [here] (https://github.com/jnicklas/capybara/blob/master/lib/capybara/rspec/matchers.rb). CapybaraMiniTestSpec iterates through those "have_x" methods and creates corresponding MiniTest assertions/expectations.

Install

# Gemfile
gem 'capybara_minitest_spec'

NOTE: If after installing the Capybara gem, Nokogiri isn't installed, it's a known bug (teamcapybara/capybara#882).

Rails

If you choose to use Rails's default ActionDispatch::IntegrationTest, just extend Minitest::Spec::DSL. E.g.

# Maybe in a helper or something.
ActionDispatch::IntegrationTest.extend Minitest::Spec::DSL

Otherwise you may see this exception: NoMethodError: undefined method 'assert_page_has_content' for nil:NilClass.

Compatibility

Capybara

In theory, this should work with Capybara >= 2. The latest version it was tested with was Capybara 2.4.1.

For Capybara < 2 support, use a version of this gem < 1.0.

Minitest

Supports Minitest >= 4. It may work for earlier versions, I just haven't tested it. If you need it to support an earlier version, let me know and I'll see what I can do.

Ruby

Check .travis.yml.

Cucumber

Cucumber is not officially supported. See #10 for a possible workaround.

Testing

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.