当我尝试运行我的请求规范时收到以下错误:
POST :: /users/:id/authentications request::successful request#test_0001_Adds an authentication record to a user:
NoMethodError: undefined method `post' for #<#<Class:0x007fa607163028>:0x007fa6070012c0>
test/requests/authentications_test.rb:9:in `block (3 levels) in <main>'
这是测试本身:
require "minitest_helper"
describe "POST :: /users/:id/authentications request" do
describe "successful request" do
it "Adds an authentication record to a user" do
user = create_user
post user_authentications_path(user)
response.status.must_equal "200"
end
end
end
这是minitest_helper.rb
文件:
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require "minitest/autorun"
require "minitest/rails"
require "minitest/rails/capybara"
Dir[Rails.root.join("test/support/**/*.rb")].each {|f| require f}
class ActiveSupport::TestCase
end
# database cleaner
DatabaseCleaner.strategy = :transaction
class MiniTest::Spec
before :each do
DatabaseCleaner.start
end
after :each do
DatabaseCleaner.clean
end
end
class RequestTest < MiniTest::Spec
include Rails.application.routes.url_helpers
register_spec_type(/request$/, self)
end
事物的相关版本: Rails:3.2.13 minitest-rails:0.9.2 minitest-rails-capybara:0.9.0
我不能打电话真的没有意义post
。看起来网络上的所有其他示例都可以做到这一点。
对此的任何帮助将不胜感激。