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 に答える