这应该是一个简单的,但是找不到为什么导致测试失败.
运行rspec时,我收到以下错误.但是在发表了“发送”方式之后,一切正常.
运行rspec时,我收到以下错误.但是在发表了“发送”方式之后,一切正常.
1) Messages GET /messages works! (now write some real specs) Failure/Error: get target_app_messages_path(@message.target_app.id) ArgumentError: wrong number of arguments (2 for 0) # ./app/controllers/messages_controller.rb:37:in `send'
的routes.rb
resources :target_apps do resources :messages do member do post 'send' end end end
型号代码
class Message include Mongoid::Document belongs_to :target_app end
控制器代码
class MessagesController < ApplicationController def index ... end def show ... end ... def send ... end end
/spec/requests/message_spec.rb
describe "Messages" do describe "GET /messages" do let(:message) do FactoryGirl.create(:message) end it "works! (now write some real specs)" do # Run the generator again with the --webrat flag if you want to use webrat methods/matchers get target_app_messages_path(message.target_app.id) response.status.should be(200) end end
解决方法
Ruby中的每个对象都有一个send方法:
http://ruby-doc.org/core-1.9.3/Object.html
通过命名您的操作“发送”您造成名称冲突.尝试将该操作重命名为“sendmessage”或以不同的方式定义它.应该有一种方法可以将URL发送到名为“sendmessage”的动作.