0

/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
4

1 回答 1

0

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

describe "POST my_action" do
  it "blah blah" do
    post :my_action, {:id => id, :x => x, :y => y}
    ...
  end
end
于 2013-07-13T06:18:30.277 回答