This post is about Rails 3.1 application acceptance testing with MiniTest::Spec and Capybara.
It is a continuation of my previous post. Please note that it covers only an acceptance spec example addition into already configured and working application, as described in previous post.
Add to your Gemfile:
group :test do gem 'capybara_minitest_spec end
Don't forget to run bundler against your new Gemfile content:
$ bundle install
Add to your test/minitest_helper.rb:
require "capybara/rails" # make url helpers, fixtures # and capybara/dsl with matchers # available within acceptance spec class MiniTest::Rails::Acceptance < MiniTest::Rails::Spec include MiniTest::Rails::Fixtures include Capybara::DSL include Rails.application.routes.url_helpers end # make #describe BDD style available MiniTest::Spec.register_spec_type /AcceptanceTest$/, MiniTest::Rails::Acceptance
Generate sample controller and view:
This should create some files for you.
$ rails generate controller Website index
Add sample content into app/views/website/index.html.erb:
Config route in config/routes.rb:
Create test/acceptance/website_test.rb with sample test:
require "minitest_helper" describe "WebsiteAcceptanceTest" do it "website must be capybara friendly;)" do visit website_index_path page.must_have_content("Hello Capybara!") end end
Create new rake task within lib/tasks/test_acceptance.rake:
namespace :test do Rake::TestTask.new(:acceptance => "test:prepare") do |t| t.libs << "test" t.pattern = 'test/acceptance/**/*_test.rb' end end
Run all acceptance tests at once using:
$ rake test:acceptance
This post is based on some other sources. Please take a look at them to find more: