との統合テストでユーザーインスタンスに期待を設定:私のテストです...だから私は、コールバックを保存する上で起こることを確実にしようとしていますモカとカピバラ
user = create_user
login user
visit new_post_path
fill_in "post_title", :with => "my post"
user.expects(:publish_post!).once
click_button "post_submit"
と私が手:
1 )失敗: テスト:投稿は投稿を配置する必要があります。 (事後) [テスト/統合/ post_test.rb:72:__bind_1311708168_640179' /test/test_helper.rb:37:in
expectation_onで」 テスト/統合/ post_test.rb:70:__bind_1311708168_640179' `に]: ないすべての期待を満足 不満足期待した: - 正確に予想1回、まだ呼び出されていない:#.publish_post!(any_parameters) 満足の期待: - 何回でも許可されていますが、まだ呼び出されていません:Post(id:integer、title:string、method_of_exchange:string、you_tube_url:string、lat:decimal文字列、状態:文字列、郵便番号:文字列、国名、国名、国名、国名、国名、国名、国名、国名、国名、国名、国名、 :string、county:string、category_id:整数、slug:文字列、status:文字列、 - 任意の回数呼び出すことができます:{}。for(任意のパラメータ) - 決して期待できない、まだ起動されません:#!の.publish_post(any_parameters)
しかし、私のポストモデルではありません:
class Post < ActiveRecord::Base
belongs_to :user
after_create :publish
def publish
user.publish_post!
end
end
と私の記事コントローラの作成アクションは、実際にユーザーがポスト...
を割り当てませんclass PostsController < ApplicationController
def create
post = Post.new(params[:post])
post.user = current_user
post.save
end
end
...
手動でテストすると機能は正常に動作します。なぜ自動化されていないのでしょうか?