Skip to content

Instantly share code, notes, and snippets.

@owenkellogg
Created March 30, 2012 23:10
Show Gist options
  • Save owenkellogg/2257519 to your computer and use it in GitHub Desktop.
Save owenkellogg/2257519 to your computer and use it in GitHub Desktop.
MiniTest::Spec setup
# test/support/custom_capybara_expectations.rb
module CustomCapybaraExpectations
def has_flash_message?(message)
within '#flash' do
has_content? message
end
end
end
Capybara::Session.send :include, CustomCapybaraExpectations
CustomCapybaraExpectations.public_instance_methods(false).each do |name|
CapybaraMiniTestSpec::Matcher.new(name)
end
page.must_have_content('Blog about this')
page.must_have_flash_message('Successfully created')
# and
page.wont_have_flash_message('There were errors')
# test/test_helper.rb
require 'spork'
Spork.prefork do
# Environment.
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
# MiniTest and Capybara.
require 'minitest/autorun'
require 'capybara/rails'
# Require ruby files in support dir.
Dir[File.expand_path('test/support/*.rb')].each { |file| require file }
# Database cleaner.
DatabaseCleaner.strategy = :truncation
class MiniTest::Spec
before :each do
DatabaseCleaner.clean
end
end
# If description name ends with 'integration', use this RequestSpec class.
# It has all the integration test goodies.
class RequestSpec < MiniTest::Spec
include Rails.application.routes.url_helpers
include Capybara::DSL
include IntegrationHelpers
end
MiniTest::Spec.register_spec_type /integration$/i, RequestSpec
end
Spork.each_run do
FactoryGirl.reload
Rails.application.reload_routes!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment