ruby on rails - RSpec reporting an error, but outputs are the same -
i specing videocontroller create action :
it 'creates new video given valid parameters' video = { :title=>"example title", :description=>"description", :url=>"http://www.youtube.com/watch?v=b6spea_xhp4", :provider=>"youtube" } video.should_receive(:save).with("title"=>"example title", :description=>"description", :provider=>"youtube", :views=>0, :likes=>0, :provider_video_id=>'b6spea_xhp4', :thumb=>"http://img.youtube.com/vi/b6spea_xhp4/2.jpg") post :create, :video => video end
i error :
1) videoscontroller post create creates new video given valid parameters failure/error: video.should_receive(:save).with("title"=>"example title", :description=>"description", :provider=>"youtube", :views=>0, :likes=>0, :provider_video_id=>'b6spea_xhp4', :thumb=>"http://img.youtube.com/vi/b6spea_xhp4/2.jpg") (<video(id: integer, title: string, description: text, thumb: string, provider_video_id: string, provider: string, views: integer, likes: integer, created_at: datetime, updated_at: datetime) (class)>).save({"title"=>"example title", :description=>"description", :provider=>"youtube", :views=>0, :likes=>0, :provider_video_id=>"b6spea_xhp4", :thumb=>"http://img.youtube.com/vi/b6spea_xhp4/2.jpg"}) expected: 1 time received: 0 times
however, output suggests both rspec expectation , result same :
# extracted output # expectation : "title"=>"example title", :description=>"description", :provider=>"youtube", :views=>0, :likes=>0, :provider_video_id=>'b6spea_xhp4', :thumb=>"http://img.youtube.com/vi/b6spea_xhp4/2.jpg" # result : "title"=>"example title", :description=>"description", :provider=>"youtube", :views=>0, :likes=>0, :provider_video_id=>"b6spea_xhp4", :thumb=>"http://img.youtube.com/vi/b6spea_xhp4/2.jpg"
videocontroller
def create method = 'get_' + params[:video][:provider] + '_video_id' params[:video][:provider_video_id] = video.send(method, params[:video][:url]) params[:video][:thumb] = video.get_thumb_from_youtube(params[:video][:provider_video_id]) params[:video][:views] = params[:video][:likes] = 0 @video = video.new(params[:video]) if @video.save! redirect_to video_path(@video), notice:'video added successfully.' else render :new end end
the way passing params looks weird me, case
it 'creates new video given valid parameters' params = {:video => { :title=>"example title", :description=>"description", :url=>"http://www.youtube.com/watch?v=b6spea_xhp4", :provider=>"youtube" }} video.should_receive(:save).with(params[:video]) post :create, params end
the way accepts params hash of hash , looks missing in spec.
Comments
Post a Comment