Permalink
Browse files

Merge pull request #53 from keithpitt/fix-testcase-for-rails-4

Fixed TestHelper for Rails 4
  • Loading branch information...
2 parents 19fffa2 + eea67c4 commit 97ae3a86d8343a22fcb9985ce0d283a903c63510 @Sutto Sutto committed Mar 5, 2013
Showing with 45 additions and 6 deletions.
  1. +2 −2 Gemfile
  2. +2 −2 Rakefile
  3. +12 −2 lib/rocket_pants/test_helper.rb
  4. +29 −0 spec/integration/rspec_spec.rb
View
4 Gemfile
@@ -1,4 +1,4 @@
-source :rubygems
+source 'https://rubygems.org'
# Allow testing multiple versions with Travis.
rails_version = ENV['RAILS_VERSION']
@@ -23,4 +23,4 @@ end
gem 'active_model_serializers'
-gemspec
+gemspec
View
4 Rakefile
@@ -7,7 +7,7 @@ require 'bundler/gem_tasks'
desc "Run all specs in spec directory (excluding plugin specs)"
RSpec::Core::RakeTask.new(:spec)
-INTEGRATION_LIBS = %w(will_paginate kaminari active_record active_model_serializers)
+INTEGRATION_LIBS = %w(will_paginate kaminari active_record active_model_serializers rspec)
namespace :spec do
@@ -33,4 +33,4 @@ namespace :spec do
end
end
-task :default => ([:spec] + INTEGRATION_LIBS.map { |l| "spec:integration:#{l}" })
+task :default => ([:spec] + INTEGRATION_LIBS.map { |l| "spec:integration:#{l}" })
View
14 lib/rocket_pants/test_helper.rb
@@ -5,6 +5,8 @@ module TestHelper
extend ActiveSupport::Concern
included do
+ require 'action_controller/test_case'
+
# Extend the response on first include.
class_attribute :_default_version
unless ActionController::TestResponse < ResponseHelper
@@ -13,7 +15,7 @@ module TestHelper
end
module ResponseHelper
-
+
def recycle_cached_body!
@_parsed_body = @_decoded_body = nil
end
@@ -73,7 +75,15 @@ def have_decoded_response(value)
protected
# Like process, but automatically adds the api version.
- def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
+ def process(action, http_method = 'GET', *args)
+ # Rails 4 changes the method signature. In rails 3, http_method is actually
+ # the paramters.
+ if http_method.kind_of?(String)
+ parameters, session, flash = args
+ else
+ parameters = http_method
+ end
+
response.recycle_cached_body!
parameters ||= {}
if _default_version.present? && parameters[:version].blank? && parameters['version'].blank?
View
29 spec/integration/rspec_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+describe TestController, 'rspec integration', :integration => true, :target => 'rspec' do
+ # Hack to allow us to include the ActionController::TestCase::Behaviour module
+ def self.setup(*args); end
+ def self.teardown(*args); end
+
+ # Important to include behaviour before the RocketPants::TestHelpers
+ include ActionController::TestCase::Behavior
+ include RocketPants::TestHelper
+ include RocketPants::RSpecMatchers
+
+ default_version 1
+
+ before do
+ @routes = TestRouter
+ @controller = TestController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ end
+
+ describe 'should have_exposed' do
+ it "allows you to asset what should have been exposed by an action" do
+ get :echo, :echo => "ping"
+
+ response.should have_exposed(:echo => "ping")
+ end
+ end
+end

0 comments on commit 97ae3a8

Please sign in to comment.