search for: should_receive

Displaying 20 results from an estimated 280 matches for "should_receive".

2007 Oct 05
13
spec''ing view render partial collection, local variable not found
....rb:39: def before game = mock_model(Game, :name => ''The Battle for Blaze'', :salt_grains => 5000000, :people => 5000000, :days => nil, :created_at => "Mon Oct 01 00:02:44 -0400 2007", :enabled => true) game.should_receive(:name).and_return("The Battle for Blaze") game.should_receive(:salt_grains).and_return(5000000) game.should_receive(:people).and_return(5000000) game.should_receive(:days).and_return(nil) game.should_receive(:created_at).and_return("Mon Oct 01 00:02:44 -0400 2007&quot...
2009 Jul 08
1
[PATCH: host-browser replacement 0/3] replacement of host-browser on ovirt-server
The purpose of this patch is to replace the identify function in host-browser.rb with a new script, host-register.rb. host-register.rb is a qmf ruby console that interfaces with the newly added matahari qmf agent on the ovirt node. While it stores node data in the database with the same behavior as the original host-browser implementation, it acquires the data using the amqp protocol (and
2006 Oct 23
6
overriding mock expectations
There is one annoyance I''m encountering with the Mock API in rSpec. Overall it works well, as far as dynamic mocks go ;)... but there''s this one thing... It doesn''t allow overriding of expectations. example: m = mock("blah") m.should_receive(:one).any_number_of_times().and_return(1) m.should_receive(:one).and_return(1) The second call to should_receive is ignored. I believe it would be most convenient if the second call to should_receive would override the first. Why? What I would like to do is define all the should_receives on...
2007 Dec 29
15
Do you think it would look cleaner?
I was looking over some of my specs. I was thinking that the following: @game.should_receive(:name).and_return(''The Battle for Blaze'') @game.should_receive(:people).and_return(5000000) @game.should_receive(:activated).and_return(true) Would it look cleaner if I could do this instead? @game.should_recieve_and_return( :name => ''The Battle for Blaze''...
2007 Jun 03
3
should_receive.again
Hi, It appears that if I have 2 should_receives in a row, the latest one overrides the previous one(s). If there isn''t one, could we add a way to accumulate them, such as @thing.should_receive(:method).and_return(@value) @thing.should_receive(:method).again.and_return(@value) @thing.should_receive(:method).again.and_return(@value)...
2007 Aug 17
4
should_receive, used in the wrong place?
What do you guys think of this: if someone calls should_receive outside of an "it" block, it warns you. before(:each) do @foo = Foo.new @foo.should_receive(:monkeys) end would warn you that you''re setting an expectation in the wrong place, and that "stub" is correct when setting up objects. Opinions? courtenay
2007 Nov 01
2
Writing controller specs
One thing that is bothering me about my controller specs is that sometimes I end up with a number of examples that are the same except for the example name. The reason that this happens is that I''ve expressed all the expected behavior with should_receive. While this does more or less work as intended it doesn''t feel right. As an example, let''s say I''m writing code to post a comment and record the IP address. First, let''s handle the comment posting: describe ''post comment'' do before do...
2009 Jul 10
2
[PATCH: server 0/3] Add host-register.rb (replaces host-browser.rb in part)
Removes node identification functionality from host-browser.rb and adds a new script, host-register.rb, that takes over that functionality. The chief difference is that host-browser used a simple TCP server setup to get data from the node, while host-register uses the qpid bus to do so. Specifically, it communicates with the matahari qmf agent added to the node in two related patchsets to node
2008 Mar 08
3
should_receive(:foo).with(any_object)
...random number. I think mocking up the rand method is somehow ugly so I thought maybe this is the first time where I can take something from Java to Ruby ;) Java''s EasyMock mocking library knows things like "anyObject()" and "anyInteger()" in their method equivalent to should_receive. I like the idea so I added this to my Rails spec_helper.rb: class AnyObjectComparator attr_reader :object def ==(other) @object = other true end end class AnyNumberComparator < AnyObjectComparator def ==(other) super.==(other) other.is_a?(Numeric) end end def any_object @a...
2011 Jul 27
3
Rspec with ActionMailer and .deliver
...(@curriculum_comment, "created") Rails 3 code: CurriculumCommentMailer.comment_update(@curriculum_comment, "created").deliver In my controller spec, I test to see if the email was sent out. Rspec 1 it "emails the comment" do CurriculumCommentMailer.should_receive(:deliver_comment_update) post :create, :curriculum_comment => @curriculum_comment.attributes end Rspec 2 In my opinion, I expected the following code to work it "emails the comment" do CurriculumCommentMailer.should_receive(:comment_update)...
2007 Sep 30
9
Problems with testing nested routes using mocking
...and #----- virtual_host_controller_spec.rb describe VirtualHostsController, "handling GET /domains/1/virtual_hosts/1" do before do @domain = mock_model(Domain) @virtual_hosts = mock("virtual_hosts") @virtual_host = mock("virtual_host") Domain.should_receive(:find).with("1").and_return(@domain) @domain.should_receive(:virtual_hosts).and_return(@virtual_hosts) @virtual_hosts.should_receive(:find).and_return(@virtual_host) login_as :admin end def do_get get :show, :id => "1", :domain_id => "1&quot...
2007 Aug 12
5
stubbing a method that yeilds sequential results
I''ve just found myself stuck trying to rspec something so am hoping someone more knowledgable can help. I have a Connector class which has a class method ''results'' that yields results it get from a network service based on a set of attributes that I pass to it. I am wanting to yield these results from my Intermediate class up to the next
2008 Jan 13
2
should_receive twice and arguments
Hi all, I have a method calling Klass.create! two times with different arguments (this happens in a class reponsable for reading in a csv file) I want to test those like this: in one test: Klass.should_receive(:create!).with(:name => "foo").once in another: Klass.should_receive(:create!).with(:name => "foo2").once This doesn''t work because the ''once'' is only about the create! call, it doesn''t use the arguments to make the call unique. Can I...
2006 Jul 24
6
Mocking causes empty specification blocks
I''ve found myself mocking out a published api in my set-up method. This has led to some contexts having a large set-up and empty specifications. As the mocks get auto-verified, the specification blocks have nothing to do but serve as documentation. Does this sound bad? Chris
2008 Mar 14
2
Multiple should_receive(:render).with
I''m trying to specify that a particular view must render two different partials. My spec looks like: describe AClass do it do template.should_receive(:render).with(:partial => ''foo'', :locals => { ... }) ... end describe ''some conditional case'' do it do template.should_receive(:render).with(:partial => ''bar'', :locals => { ... }) ... end end en...
2007 Apr 12
3
specing class methods
...would I spec out Autotest.run? Two complications come to my mind: 1. How do I spec out class methods? (please point me to docs, if any. I can only find class level specing on "partial mocks" (of rails class objects) 2. How can I tell that new.run has been called, without saying should_receive(:new) and should_receive(:run) in separate specs? Another complication: How would I spec out the (instance level) run method, which has an infinite loop? def run hook :run reset add_sigint_handler loop do # ^c handler #...stuff... end hook :quit end Thank...
2007 Jun 11
2
Testing create in Rails controller
...ation. I am having a problem testing the admin controller create method and cannot quite see where I am going wrong so was hoping for a pointer :-) My spec looks like: describe AdminController do before(:each) do @product = mock("product") # Generally, prefer stub! over should_receive in setup. @product.stub!(:new_record?).and_return(false) Product.stub!(:new).and_return(@product) end it "should create a new, unsaved product on GET to new" do # Using should_receive here overrides the stub in setup. Even # though it is the same as the stub...
2007 Aug 17
11
[rspec] looking for a simple refresher
..." do before do @ticket = mock_model(Ticket, :to_param => ''1'', :save => true) Ticket.stub!(:new).and_return(@ticket) @params = {} end def do_post post :create, :ticket => @params end it "should create a new ticket" do @ticket.should_receive(:new).with(@params).and_return(@ticket) do_post end end Would someone provide with an explanation what I have to do to make this spec pass? Peepcode hasn''t released their screen cast on rspecing controllers yet =''( -------------- next part -------------- An HTML attachment...
2007 Jun 21
4
should_receive stubs methods?
Hey, I''m using rspec and rails and have a spec that tests if a before_filter is executed, I also have a spec that tests if a method called by the filter is executed. It appears however that when I should_receive something, it is no longer actually called when I fire the http request. I''m not sure how, or where exactly I should manually fire the filter, either before or after the http request sounds wrong. An option to should_receive that passes on the invocation would be helpful yet I see nothing...
2007 Jul 12
3
Agh, this is annoying. Why is this happening?
...@user.stub!(:id).and_return(1) @user.stub!(:login).and_return("moo") User.stub!(:find).and_return(@user) @params = {} end def do_post @request.session[:user] = @user.id post :create, :task => @params end it "should create a new task" do Task.should_receive(:user_id).with(@user.id).and_return(true) Task.should_receive(:new).with(@params).and_return(@task) do_post end it "should redirect to /tasks" do Task.should_receive(:user_id).with(@user.id).and_return(true) do_post response.should redirect_to(home_url) end end...