similar to: Stub ActionController::Base#params

Displaying 20 results from an estimated 8000 matches similar to: "Stub ActionController::Base#params"

2007 Oct 26
3
Specing with Subdomains as Account Keys
How do you go about implementing and rspecing subdomains as account keys? I''m sure that this must be an issues for others as well. So I have an app using subdomains as account keys. The Application Controller sets up @current_company in a before filter. Everything is done within the context of the @current_company. After reading about Demeter''s Revenge
2007 Nov 20
2
confirming that a model instance was correctly created from POST params
I''m wondering whether I''m wasting my time trying to verify that an addition I''ve made to legacy code is in fact setting a new attribute on a model. Substruct''s (http://dev.subimage.com/projects/substruct) OrderHelper contains this method: 1 def create_order_from_post 2 @use_separate_shipping_address = params[:use_separate_shipping_address]
2007 Oct 25
1
Mocking/Stubbing help with subdomain as account key
My app uses account_location to set up subdomains as account keys. In my controllers, all my model operations are scoped through the @current_person object. The question is: How do I test this with RSpec''s mocking and stubbing? Basically, I need to test that @current_person.things is getting the find message and returning @thing. I''ve tried stubbing and mocking
2008 Jan 30
2
Stubbing controller methods vs model methods
I had an error that I couldn''t figure out, then when writing up a question for the forum I figured it out. The thing is I don''t understand why the change that was made works and why what existed before didn''t. Here is the initial post when I had the error: ---------------------------------- In the controllers/application.rb file I have a method that finds the account
2007 May 17
2
Stubbing authentication across multiple controllers
Hi, I''m new to RSpec, so I''m not too sure of the best practises in stubbing. I was thinking along the lines of including a helper method that would stub out a users id and posts to sessions/create. It works fine when speccing SessionsController, but of course it fails when it is included into other controllers specs, because of the post. I''ve tried posting to an
2006 Nov 10
3
Stubbing Time.now in trunk
I''m a big fan of stubbing Time.now so it returns a known value. I used to be able to use stubba and say: @time_now = Time.parse("Jan 1 2001") Time.stubs(:now).returns(lambda{@time_now}) However, something in trunk broke that. Fine, rspec''s got its own stubbing lib now, so I tried switching to that: @time_now = Time.parse("Jan 1 2001")
2007 Jun 15
6
problem getting started with stubbing in rails controller specs
Hello, Ingo! I''m copying your question to a new e-mail instead of replying to try to keep message threads separate. Have you tried setting up your expectation before issuing the get statement? For example, take this out of the setup block: get ''index'', :locale => ''en'' and move it after:
2007 Jul 27
5
File.stub!
Hi, I''m trying to stub File.open and whenever I do, rspec blows up with the following error message (undefined method `add'' for nil:NilClass), which seems to happen because method __add in class Proxy is calling #add on global $rspec_mocks, which in turn is nil. Can someone explain what I''m doing wrong, as I can''t seem to stub anything out! Here''s
2007 Sep 13
2
Failing to raise an exception in a stub
I''ve come across rather strange behaviour when trying to raise an exception in a stubbed method. I''m speccing the behaviour of a Rails create action, where I''m using save! to catch failed saves. In the case of working save, I''m using the following stub: @client.stub!(:save!).and_return(true) which works fine. However, in the negative case,
2008 Jan 28
2
Could this controller test be made simpler?
In a create controller method I am testing the else clause that occurs when the model is unable to be saved. Sounds simple enough, but because model is created before the save and the form has to be re-filled I now have to stub a model and all the attributes. Since the error messages are displayed I also have to stub some methods within the model that allow the error messages to be displayed
2006 Dec 21
3
Stubbing an instance method on a class
Hi all, I''m not sure if I''ve missed it, but I couldn''t find any docs for stubbing an instance method on a class. For example: class Foo; end Foo.stub!(:my_instance_method).and_return(nil) The reason (I think) I need this is because a certain class (Test::Unit::TestCase) expects an argument (name of method) to new and throws an exception if that instance method
2009 Jan 27
2
[RSpec] Error when returning multiple values from a stub
Hey guys. I''ve just found some odd behaviour within RSpec 1.1.12 , and would like to know whether this is a bug, or I''m doing something wrong. When I give multiple return values to a stub, like this: SubtitleFile.stub!(:new).and_return @sf1, @sf2 RSpec complains: Mock ''SubtitleFile_1001'' received unexpected message :size with (no args) However, if I
2011 Jun 23
2
RSpec book help; why won't this stub method work?
Subscription model-------------------------------------------- class Subscription < ActiveRecord::Base has_one :user def can_send_message? if user.sent_messages.count < limit true else false end end end Subscription model spec-------------------------------------------- require ''spec_helper'' describe Subscription do describe
2007 Oct 05
7
Easy AR association stubbing
I''ve added a method to the mock class that makes it pretty easy to stub associations in rails. I''ve been using it for awhile and it seems to cut down on a lot of setup code for the controller and model specs that use associations. #before @person = mock_model(Person) posts = mock(''post_proxy'') posts.stub!(:build).and_return(mock_model(Post, :save => true))
2010 Jun 23
1
RSpec, plugins and stubbing controller methods
Hello, I have some code that is going to be used in other applications, so I decided to bundle the code (mostly controllers and views) into a plugin to make sharing easier. I copied the RSpec tests for the controllers into the plugin as well. The plugin RSpec tests run, however when it gets to stubbing controller methods it does not work. For example:
2007 Oct 08
6
stub actions that depend on the parameter
Hi, I''m pretty new to all related to bdd and rspec and I have the following question. Is it possible to stub actions that return different objects depending on the parameteres they were called with? Something like this: MyClass.stub!(:method).with(1).and_return(@mock_object_1) MyClass.stub!(:method).with(2).and_return(@mock_object_2) I know I could use
2008 Sep 17
1
Stubbing Paperclip calls to Amazon S3 (for Rspec)
Would anyone happen to know how to stub a call to S3 from Paperclip? I''ve searched every where and no one seems to have posted anything about this. I''ve done very little in the way of spec''ing dependencies on external services, so any ideas on how to do this with Paperclip & S3 would be most appreciated. I''m happy with stubbing out Thinking Sphinx - would
2008 Jan 10
4
Mocking and stubbing Rails'' association extensions
I''m having a lot of trouble stubbing out an association extension for some view tests. Example rails code modeling a music album: class Album < ActiveRecord::Base has_many :songs do def streamable find(:all, :conditions => ''streamable = 1'') end end end So for a given Album instance (say @album), I need to be able to stub both
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) would be equivalent to
2010 Jul 13
2
[Rspec] Difference between stub and message expectation with any_number_of_times
I''m wondering what''s the difference between stub and message expectation with any_number_of_times, for example: myMock = mock("mymock") myMock.stub!(:is_a?).with(MyClass).and_return(false) and myMock = mock("mymock") myMock.should_receive(:is_a?).with(MyClass).any_number_of_times.and_return(false) because is_a? may not be called at all, it just like a