モデルをテストしようとしていますが、モック モデルの作成に問題があります。
以下はコントローラーの一部です。
def show
@license = License.find(params[:id])
これが私のrspecの一部です:
it "can show a license" do
mocks = (1..3).map { mock_model(License) }
License.should_receive(:all).and_return(mocks)
post :show, {:id => 1}
ただし、rspec を実行するとエラーが発生します。
Failure/Error: License.should_receive(:all).and_return(mocks)
(<License(id: integer, license_id: string, location: string, format: string, license_type: string, language: string, context: string, licensor: string, licensee: string, resource: string, created_at: datetime, updated_at: datetime) (class)>).all(any args)
expected: 1 time
received: 0 times
また、これが機能するようになった場合、License オブジェクトの ID を変更するにはどうすればよいですか。「mocks[0].id = 5」は機能しますか?
どんな助けでも大歓迎です。ありがとう。