Rspec undefined method build for #<Array:xxxx>
<p>I am getting this error message from Rspec</p>

<pre><code>Failure/Error: @address = @owner.addresses.build

 NoMethodError:
   undefined method `build' for #&lt;Array:0x007f9faba657f0&gt;
</code></pre>

<p>Below is snippet from my controller</p>

<pre><code> class AddressesController &lt; ApplicationController
   def new
     @owner   = Owner.find(params[:owner_id])
     @address = @owner.addresses.build
   end
 end
</code></pre>

<p>Below is snippet from my spec file:</p>

<pre><code>describe "GET #new" do 
  let(:owner) { create(:owner) }
  before { xhr :get, :new, owner_id: owner.id }

  it 'response will be success' do
    expect(response).to be_success
  end
end
</code></pre>

<p>Below is my route for <code>addresses#new</code></p>

<pre><code>new_owner_address GET    /owners/:owner_id/addresses/new(.:format)      addresses#new    
</code></pre>

<p><code>addresses.build</code> method is working fine in <code>console</code> and working fine in my application but it is failing on spec. Any suggestion will be highly appreciated. </p>

<p>Update:</p>

<p>factory:</p>

<pre><code>FactoryGirl.define do
  factory :owner do
    name 'foo'
    address 'bar'
    amount 200.00
    country 'foobar'
    state 'qax'
  end
end
</code></pre>

<p>Model and Associations:</p>

<pre><code> class Owner &lt; ActiveRecord::Base
   has_many :addresses, dependent: :destroy
 end

 class Address &lt; ActiveRecord::Base
   belongs_to :owner
 end
</code></pre>