2016-06-30 9 views
0

にもかかわらず、私は自分のアプリケーションのモデル、accepts_nested_attributes_for(:user)のモデルテストを書いているaccept_nested_attributes_forに失敗しました。ここで失敗のテストです:RSpecの+のshouldaテストは関係

describe UserApplication, "associations" do 
    it { should belong_to(:user) } 
    it { should accept_nested_attributes_for(:user) } 
end 

そして、ここでは、モデルの:

class UserApplication < ActiveRecord::Base 
    #attr_accessible all the fields 

    belongs_to :user 
    accepts_nested_attributes_for :user 
end 

私はshoulda-マッチャ2.8とRSpecのを使用していて、私の研究から、これはすべて正常に動作する必要があります。春も、他の奇妙さもありません。私が見ているエラーは次のとおりです。

1) UserApplication association 
Failure/Error: it { should accept_nested_attributes_for(:user) } 
NoMethodError: 
    undefined method `accept_nested_attributes_for' for #<RSpec::Core::ExampleGroup::Nested_2:0x007fec5c641a40> 
# ./spec/models/user_application_spec.rb:25:in `block (2 levels) in <top (required)>' 

何が原因か分かりません。これは奇妙な宝石紛争の嫌悪者かもしれないか、私は何か明白な行方不明ですか?

+0

should-matcherを最新バージョンにアップグレードしてもう一度試してみることはできますか?その特定のバージョンのドキュメントを見ることができません –

+0

@AnezioCampos shoulda-matcherを3.0にアップデートすると、私は現時点ではできないactivesupportを4.0にアップデートする必要があります。私はしばらくの間、レール3.2で立ち往生しています。 – octopushugs

+0

これは 'accept_nested_attributes_for(:user)}'は '' accepts_nested_attributes_for(:user)} ''でなければなりません。 '' accepts''に 's'がありません... ' ' – Hackerman

答えて

0

わかりましたので、私は間違っていたものを見るために私のツールを提供するために@PeterAlfvinに信用を与える必要があります。私のgemfileはgem 'shoulda-matchers'と指定されていましたが、それはaccepts_nested_attributes_forのサポートを持たないバージョン1.0しかロードしていませんでした。彼の提案は、https://stackoverflow.com/a/2954632/1008891を介して正しい方向に私を指摘した。 2.8.0を指定すると、すぐに何かを壊すことなく問題が修正されました。

関連する問題