为什么我的控制器的spec文件找不到post方法?

时间:2013-07-13 06:07:28

标签: ruby-on-rails rspec

/spec/controllers/postbacks_controller_spec.rb中,我有:

require 'spec_helper'
describe PostbacksController, :type => :controller do
  include RSpec::Rails::ControllerExampleGroup
    describe "receive" do
    etc etc ... ... etc etc
    post "postbacks/#{@postback.id}/receive", @parameters
    @postback.content.should == @parameters
  end
end

为什么会出现以下错误?

NoMethodError: undefined method `post' for #

Gemfile包括:

group :test do
  gem "binding_of_caller"
  gem "capybara"
  gem "database_cleaner"
  gem "launchy"
  gem "respec"
  gem "rspec-rails"
  gem "parallel_tests"
  gem "zeus-parallel_tests"
  gem "better_errors"
end

/spec/spec_helper.rb是:

require "rubygems"
require "database_cleaner"
ENV["RAILS_ENV"] ||= "test"
require File.expand_path("../../config/environment", __FILE__)
require "rspec/rails"
require "capybara/rspec"
require "capybara/rails"
require "capybara/dsl"
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
  config.mock_with :rspec
  config.fail_fast = true
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.before(:each) { ActionMailer::Base.deliveries.clear }
  config.use_instantiated_fixtures = false 
  config.include(Capybara, :type => :integration)
  config.use_transactional_fixtures = false
  config.before(:suite) do
    DatabaseCleaner.strategy = :deletion
    DatabaseCleaner.clean_with(:truncation)
  end
  config.before(:each) do
    DatabaseCleaner.start
  end
  config.after(:each) do
    DatabaseCleaner.clean
  end
  config.after do
    if example.metadata[:type] == :feature && example.exception.present? && page.current_path.present?
      save_and_open_page
    end
  end
end

1 个答案:

答案 0 :(得分:0)

我认为您不需要在控制器规范中包含控制器的url。以下是适用于我的语法:

describe "POST my_action" do
  it "blah blah" do
    post :my_action, {:id => id, :x => x, :y => y}
    ...
  end
end