Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get wrong number of arguments (2 for 0) when running Rspec Test using get and delete

This should be a simple one, but just could not find out why it caused the testing failure. I kept getting the following error when running rspec. But after commenting "send" method, everything works fine.

  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

Model Code

class Message
  include Mongoid::Document
  belongs_to :target_app
end

Controller Code

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
like image 912
CCK Avatar asked Dec 18 '11 05:12

CCK


1 Answers

Every object in Ruby has a send method:

http://ruby-doc.org/core-1.9.3/Object.html

By naming your action "send" you caused a name conflict. Try renaming that action to "sendmessage" or defining it in a different way. There should be a way to have "send" in your URL map to an action named "sendmessage".

like image 143
David Grayson Avatar answered Sep 21 '22 14:09

David Grayson