Forked from owenkellogg/custom_capybara_expectations.rb
Created
August 10, 2012 07:58
-
-
Save tors/3312507 to your computer and use it in GitHub Desktop.
MiniTest::Spec setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
page.must_have_content('Blog about this') | |
page.must_have_flash_message('Successfully created') | |
# and | |
page.wont_have_flash_message('There were errors') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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