[rspec-users] Troble running controller spec

David Chelimsky dchelimsky at gmail.com
Fri May 22 06:35:26 EDT 2009


On Fri, May 22, 2009 at 1:41 AM, Amit Kulkarni <lists at ruby-forum.com> wrote:
> Hi,
>
>    I am trying to execute controller spec by referring to RSpec book
> but it is diving me error.
>
> Following are the details:
> Ruby version : 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
> rspec - 1.2.4
> rails - 2.1.2
> OS - Vista Home
>
> My channels_controller_spec.rb(which is under
> rootproject/spec/controller directory) file contains:
>
> require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
>
> describe ChannelsController do
>  describe "Channel Creation" do
>   before(:each) do
>    @channel = mock_model(Channel, :save => nil)
>    Channel.stub!(:new).and_return(@channel)
>   end
>
>   it "should create channel" do
>    Channel.should_receive(:new).with(:brand_name => "test"
> ).and_return(@channel)

I *think* Rails converts the keys in this hash to strings. Try:

Channel.should_receive(:new).with('brand_name' => 'test').
  and_return(@channel)

HTH,
David

>    post :create, :channel => { :brand_name => "test" }
>  end
>
>  it "should save channel" do
>    @channel.should_receive(:save)
>    post :create
>  end
>  end
> end
>
> Similarly my channels_controller.rb contains
>
> def create
>  @channel= Channel.new params[:channel]
>  @channel.save
> end
>
> Now when i try to execute the spec it shows me error which i have
> mentiond below along with its backtrace
>
> FF.
>
> 1)
> Spec::Mocks::MockExpecttionError in 'ChnnelsController Chnnel Cretion
> should cre
> te chnnel'
> <Chnnel(id: integer, brnd_nme: string, logo_file_nme: string,
> logo_file_size: st
> ring, logo_content_type: string, points: integer, rnk: integer,
> overruled_rnk: b
> oolen, title: string, description: text, tgs: string, url: string,
> kit_file_nme:
>  string, kit_file_size: string, kit_content_type: string, ctive: boolen,
> bg_colo
> r: string, font_color: string, title_color: string, title_style: string,
> emotion
> l_file_nme: string, emotionl_file_size: string, emotionl_content_type:
> string, n
> cestor_id: integer, chnnel_ctegory_id: integer, creted_t: dtetime,
> updted_t: dte
> time) (clss)> expected :new with ({:brnd_nme=>"mnger"}) once, but
> received it 0
> times
> ./spec/controllers/chnnels_controller_spec.rb:11:
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/error_gen
> ertor.rb:53:in `__rise'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/error_gen
> ertor.rb:26:in `rise_expecttion_error'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/messge_ex
> pecttion.rb:229:in `generte_error'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/messge_ex
> pecttion.rb:192:in `verify_messges_received'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/proxy.rb:
> 190:in `verify_expecttions'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/proxy.rb:
> 189:in `ech'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/proxy.rb:
> 189:in `verify_expecttions'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/proxy.rb:
> 66:in `verify'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/methods.r
> b:34:in `rspec_verify'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/spce.rb:1
> 0:in `verify_ll'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/spce.rb:9
> :in `ech'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/spce.rb:9
> :in `verify_ll'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/dpters/mock_frm
> eworks/rspec.rb:13:in `verify_mocks_for_rspec'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_m
> ethods.rb:129:in `fter_ech_exmple'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_m
> ethods.rb:45:in `execute'
> C:/Progrm Files/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_m
> ethods.rb:37:in `execute'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_g
> roup_methods.rb:207:in `run_exmples'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_g
> roup_methods.rb:205:in `ech'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_g
> roup_methods.rb:205:in `run_exmples'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_g
> roup_methods.rb:103:in `run'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/exmple_g
> roup_runner.rb:23:in `run'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/exmple_g
> roup_runner.rb:22:in `ech'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/exmple_g
> roup_runner.rb:22:in `run'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/options.
> rb:119:in `run_exmples'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/commnd_l
> ine.rb:9:in `run'
> script/spec:4:
>
> 2)
> Spec::Mocks::MockExpecttionError in 'ChnnelsController Chnnel Cretion
> should sve
>  chnnel'
> Mock 'Chnnel_1002' expected :sve with (ny rgs) once, but received it 0
> times
> ./spec/controllers/chnnels_controller_spec.rb:16:
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/error_gen
> ertor.rb:53:in `__rise'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/error_gen
> ertor.rb:26:in `rise_expecttion_error'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/messge_ex
> pecttion.rb:229:in `generte_error'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/messge_ex
> pecttion.rb:192:in `verify_messges_received'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/proxy.rb:
> 190:in `verify_expecttions'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/proxy.rb:
> 189:in `ech'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/proxy.rb:
> 189:in `verify_expecttions'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/proxy.rb:
> 66:in `verify'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/methods.r
> b:34:in `rspec_verify'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/spce.rb:1
> 0:in `verify_ll'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/spce.rb:9
> :in `ech'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/mocks/spce.rb:9
> :in `verify_ll'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/dpters/mock_frm
> eworks/rspec.rb:13:in `verify_mocks_for_rspec'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_m
> ethods.rb:129:in `fter_ech_exmple'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_m
> ethods.rb:45:in `execute'
> C:/Progrm Files/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_m
> ethods.rb:37:in `execute'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_g
> roup_methods.rb:207:in `run_exmples'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_g
> roup_methods.rb:205:in `ech'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_g
> roup_methods.rb:205:in `run_exmples'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/exmple/exmple_g
> roup_methods.rb:103:in `run'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/exmple_g
> roup_runner.rb:23:in `run'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/exmple_g
> roup_runner.rb:22:in `ech'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/exmple_g
> roup_runner.rb:22:in `run'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/options.
> rb:119:in `run_exmples'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/commnd_l
> ine.rb:9:in `run'
>
> I had done same which is mentioned in the book still i dont know why i
> am getting this error.
> Please suggest :-)
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list