0

返されたビデオ オブジェクトが入力したものと同じかどうかを確認する次のコードがあります。

ビデオ オブジェクトはPanda Streamオブジェクトであり、ホームページを参照すると、メソッドで入力したオブジェクトを正確Panda::Video.findに返す必要があります。Panda::Video.create

# screencast_spec.rb
before(:each) do
  @screencast = Factory.build(:screencast)
  @video = Panda::Video.create(:source_url => "http://panda-test-harness-videos.s3.amazonaws.com/panda.mp4")
end
it "should fetch the video with the #video method" do
  @screencast.video = @video
  @screencast.video.should == @video
end

# screencast.rb
# Returns the panda::video object
def video
  Panda::Video.find(self.video_id)
end
# Sets the +video_id+ reference
def video= video_object_or_id
  video_object_or_id = video_object_or_id.id unless video_object_or_id.is_a?(Integer)
  self.video_id = video_object_or_id
end

RSpec が返すエラーは次のとおりです。

1) Screencast#video should fetch the video with the #video method
Failure/Error: @screencast.video.should == @video
   expected: #<Panda::Video id: "dac9bf057c9b667f57096054a64625a1", created_at: "2012/01/29 18:04:07 +0000", updated_at: "2012/01/29 18:04:07 +0000", original_filename: "panda.mp4", source_url: "http://panda-test-harness-videos.s3.amazonaws.com/panda.mp4", duration: nil, height: nil, width: nil, extname: ".mp4", file_size: nil, video_bitrate: nil, audio_bitrate: nil, audio_codec: nil, video_codec: nil, fps: nil, audio_channels: nil, audio_sample_rate: nil, status: "processing", path: "dac9bf057c9b667f57096054a64625a1", cloud_id: "55372b1612963b045f27bb093fed0abb">
        got: #<Panda::Video id: "dac9bf057c9b667f57096054a64625a1", created_at: "2012/01/29 18:04:07 +0000", updated_at: "2012/01/29 18:04:07 +0000", original_filename: "panda.mp4", source_url: "http://panda-test-harness-videos.s3.amazonaws.com/panda.mp4", duration: nil, height: nil, width: nil, extname: ".mp4", file_size: nil, video_bitrate: nil, audio_bitrate: nil, audio_codec: nil, video_codec: nil, fps: nil, audio_channels: nil, audio_sample_rate: nil, status: "processing", path: "dac9bf057c9b667f57096054a64625a1", cloud_id: "55372b1612963b045f27bb093fed0abb"> (using ==)
   Diff:
 # ./spec/models/screencast_spec.rb:26:in `block (3 levels) in <top (required)>'

2 つのオブジェクト間に違いはないと言っている diff に注意してください。なぜ比較が失敗するのでしょうか?

あなたの誰かが何かポインタを持っているか、私が得ることができるすべてのガイダンスに感謝する前にパンダストリームをテストしようとした場合

4

1 に答える 1

0

ruby は等価性をテストするための 3 つの方法を提供します== eql? equals?。使用==するときは、オブジェクト ID で比較しています。ruby はこれに object-id を使用します。==重要なことは、文字列比較の場合と同じように、クラスを再定義できることです。

このトピックについて詳しく知りたくない場合は、次のブログ投稿をお勧めします: http://www.skorks.com/2009/09/ruby-equality-and-object-comparison/

于 2012-01-30T18:28:55.013 に答える