Created
October 9, 2012 21:13
-
-
Save agraves/3861481 to your computer and use it in GitHub Desktop.
Minitest controller test with clearance
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
require 'test_helper' | |
describe PagesController do | |
before{ sign_in } | |
subject{ PagesController.new } | |
%w{some_page another_page}.each do |page| | |
describe "rendering the #{page} page" do | |
it 'should render successfully' do | |
get :show, :id => page | |
assert_response(:success) | |
assert_template(page) | |
end | |
end | |
end | |
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
# This just shows the additions to our test_helper file | |
# Full file included under test_helper_full | |
# Add clearance test methods | |
require 'clearance/testing' | |
require "minitest/matchers" | |
require "clearance/testing" | |
# Register the Clearance matchers to minitest | |
Clearance::Testing::Matchers.module_eval do | |
def self.included(base) | |
instance_methods.each do |name| | |
base.register_matcher name, name | |
end | |
end | |
end | |
class MiniTest::Rails::ActionController::TestCase | |
include Clearance::Testing::Matchers | |
include Clearance::Testing::Helpers | |
def sign_in | |
sign_in_as create(:user) | |
end | |
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
ENV["RAILS_ENV"] = "minitest" | |
require File.expand_path('../../config/environment', __FILE__) | |
require "rails/test_help" | |
class << ActiveSupport::TestCase | |
remove_method :describe | |
end | |
require "minitest/spec" | |
require "minitest/autorun" | |
require "minitest/rails" | |
#require "minitest/rails/shoulda" | |
# Uncomment if you want Capybara in accceptance/integration tests | |
require "minitest/rails/capybara" | |
# Uncomment if you want awesome colorful output | |
require "minitest/pride" | |
# Add clearance test methods | |
require 'clearance/testing' | |
class MiniTest::Rails::ActiveSupport::TestCase | |
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. | |
# fixtures :all | |
# Add more helper methods to be used by all tests here... | |
include FactoryGirl::Syntax::Methods | |
end | |
# Do you want all existing Rails tests to use MiniTest::Rails? | |
# Comment out the following and either: | |
# A) Change the require on the existing tests to `require "minitest_helper"` | |
# B) Require this file's code in test_helper.rb | |
# MiniTest::Rails.override_testunit! | |
#Credit to wojtekmach at http://www.rubyflow.com/items/7606-writing-minitest-extensions | |
module MiniTest::Assertions | |
def assert_changes(obj, method, exp_diff) | |
before = obj.send method | |
yield | |
after = obj.send method | |
diff = after - before | |
assert_equal exp_diff, diff, "Expected #{obj.class.name}##{method} to change by #{exp_diff}, changed by #{diff}" | |
end | |
end | |
module MiniTest::Expectations | |
infect_an_assertion :assert_changes, :must_change | |
end | |
require "minitest/matchers" | |
require "clearance/testing" | |
# Register the Clearance matchers to minitest | |
Clearance::Testing::Matchers.module_eval do | |
def self.included(base) | |
instance_methods.each do |name| | |
base.register_matcher name, name | |
end | |
end | |
end | |
class MiniTest::Rails::ActionController::TestCase | |
include Clearance::Testing::Matchers | |
include Clearance::Testing::Helpers | |
# Override sign_in because I don't want to have FactoryGirl... | |
def sign_in | |
sign_in_as create(:user) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't need to override
sign_in
since you are using FactoryGirl.