title: Rspec post :create 'unknown keyword: '
body: <p>I'm new to Rspec and I am trying to test my controller methods for basic functionality. I know I'm not supposed to test basic functionality, but I'm doing it more for learning purposes than to build something. </p>
  
  <p>I have a controller called ProtocolsController. The controller is used for basic CRUD functionality. I am trying to test the controllers #create method. Below is my #create controller:</p>
  
  <pre><code>def create
      @protocol = Protocol.new(protocol_params)
  
      if @protocol.save
        flash[:notice] = 'New protocol added'
        redirect_back(fallback_location: 'test_results#index')
      else
        flash[:notice] = @protocol.errors[:name]
        render 'new'
      end
    end
  </code></pre>
  
  <p>To test the sad path, I want to pass to the controller a mock object that contains the necessary parameters for creating an instance of the Protocol class. To do this I have the following code:</p>
  
  <pre><code>  describe '#create' do
      it 'fails to save because the name already exists' do
        params = FactoryGirl.attributes_for(:protocol)
        post :create, :protocol =&gt; params
      end
    end 
  </code></pre>
  
  <p>Now I know the test is incomplete, but I am testing one line at a time and when I run Rspec I get the following error: </p>
  
  <pre><code>Failure/Error: post :create, :protocol =&gt; params
  
       ArgumentError:
         unknown keyword: protocol
  </code></pre>
  
  <p>But when I change post to:       <code>expect { post :create, :protocol =&gt; params }</code></p>
  
  <p>It works. Which brings me to my questions: </p>
  
  <ul>
  <li>Why is the first post (<code>post :create, :protocol =&gt; params</code>) failing?</li>
  <li>How would I go about sending a mock object to the controller?</li>
  <li>Why does the expect version work?</li>
  </ul>
  
  <p>Any insight into the questions will be much appreciated. I've been scratching my head trying to figure this out and my guess is that it's an obvious answer. </p>