Undefined method get

So here’s the deal. Was using rack-test in rspec, cause I like passing
paths instead of an action name, but it doesn’t have access to the
session, flash, cookies, etc. So I tried to switch to normal rspec and
here’s what I get (gist is working for me, so just pasting here)

error

NoMethodError in ‘PagesController should get the home page’
undefined method `get’ for
#ActiveSupport::TestCase::Subclass_1:0x401648c
./spec/functional/public/pages_controller_spec.rb:5:

spec

require File.join(File.dirname(FILE),’…’,’…’,‘spec_helper’)

describe PagesController do
it “should get the home page” do
get ‘home’
response.should be_redirect
end
end

controller

class PagesController < ApplicationController
def home
render :layout => false
end
end

spec_helper.rb

require ‘rubygems’
require ‘spork’

Spork.prefork do

Loading more in this block will cause your tests to run faster.

However,

if you change any configuration or code from libraries loaded

here, you’ll

need to restart spork for it take effect.

ENV[“RAILS_ENV”] ||= ‘test’
require File.dirname(FILE) + “/…/config/environment”
require ‘spec/autorun’
require ‘spec/rails’
require ‘faker’
require ‘nokogiri’

Spec::Runner.configure do |config|
config.before(:all) do
DataMapper.auto_migrate!
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []

end

config.before do
  @time_now = Time.now
  Time.stub!(:now).and_return(@time_now)

  def emails; ActionMailer::Base.deliveries end

  emails.clear

  repository do |r|
    transaction = DataMapper::Transaction.new(r)
    transaction.begin
    r.adapter.push_transaction(transaction)
  end
end

config.after do
  repository do |r|
    adapter = r.adapter
    while adapter.current_transaction
      adapter.current_transaction.rollback
      adapter.pop_transaction
    end
  end
end

end

end

Spork.each_run do

This code will be run each time you run your specs.

Dir[File.dirname(FILE) + ‘/helpers/*.rb’].each{|helper| require
helper}
require File.dirname(FILE) / ‘fixtures’
end

On Oct 29, 2009, at 6:04 PM, BrianTheCoder wrote:

#ActiveSupport::TestCase::Subclass_1:0x401648c
./spec/functional/public/pages_controller_spec.rb:5:

For rspec to know that you’re writing a controller spec and provide
the services you’re looking for (like the get() method), you need one
of two conditions:

  1. the file lives in the ./spec/controllers/ directory or any of its
    subdirectories

  2. explicit declaration:

describe PagesController, :type => :controller do

end

HTH,
David

end

require File.dirname(FILE) + “/…/config/environment”
ActionMailer::Base.deliveries = []

   while adapter.current_transaction

This code will be run each time you run your specs.

Dir[File.dirname(FILE) + ‘/helpers/*.rb’].each{|helper| require
helper}
require File.dirname(FILE) / ‘fixtures’
end


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Cheers,
David

Thanks. I ended up just instantiating the rails integration session
and operating off of that. Not the prettiest, but it does what I want
it to. Also apparently the ActionController::Response breaks some
methods that work on Rack::Response, go rails! sarcasm