Assigns method returns nil in RSpec
<p>I am doing my testing with mocks and stubs but I keep getting nil in my output. I am not sure if it's the problem with the assigns method. Could I also know how I should debug this kind of problem? I am using rspec-rails 3.5.2 Thank you.</p>

<p>The failing test:</p>

<pre><code>describe 'guest user' do
   describe 'GET index' do
     let(:achievement) { instance_double(Achievement) }

     before do
       allow(Achievement).to receive(:get_public_achievements) { [achievement] }
     end

     it 'assigns public achievements to template' do
       get :index
       expect(assigns(achievement)).to eq([achievement])
     end
   end
end
</code></pre>

<p>The index action in the controller</p>

<pre><code> def index
   @achievements = Achievement.get_public_achievements
 end
</code></pre>

<p>The get_public_achievements in the achievement model</p>

<pre><code>  def self.get_public_achievements
     // empty method it's fine
  end
</code></pre>

<p>The error:</p>

<pre><code>1) AchievementsController guest user GET index assigns public achievements to template
 Failure/Error: expect(assigns(achievement)).to eq([achievement])

   expected: [#&lt;InstanceDouble(Achievement) (anonymous)&gt;]
        got: nil

   (compared using ==)
</code></pre>