[rspec-users] Troble running controller spec

Amit Kulkarni lists at ruby-forum.com
Mon Jun 8 09:31:45 EDT 2009


David Chelimsky wrote:
> On Fri, May 22, 2009 at 1:41 AM, Amit Kulkarni <lists at ruby-forum.com> 
> wrote:
>>
>> � 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)
> 

Hi,

I tried with the above command but it still gives the same error.Dont 
know what is wrong.I am following the same which is given in the book
Details are as follows

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' => 'manager' 
).and_return(@channel)
      post :create, :channel => {'brand_name' => 'manager' }
    end

    it "should save channel" do
      @channel.should_receive(:save)
      post :create
    end
  end


Following are the errors
{Please ignore the missing a's :-)}

ChnnelsController
  Chnnel Cretion
    should crete chnnel (FILED - 1)
    should sve chnnel (FILED - 2)

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:183:
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:188:
script/spec:4:

Finished in 0.305 seconds

2 exmples, 2 filures


-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list