similar to: Stubbing an instance method on a class

Displaying 20 results from an estimated 7000 matches similar to: "Stubbing an instance method on a class"

2007 Nov 02
1
stub calls to an instance method before it is created?
I am desperately in need of functionality such as Mocha offers with their any_instance method. I see that there is an open ticket for a similar feature in RSpec, but it does not look like anything have been done. Is there any other way around this? https://rubyforge.org/tracker/index.php?func=detail&aid=6791&group_id=797&atid=3152 Here is what I am doing, and why I feel I need this
2007 Mar 27
3
Stubbing out method for all instances
I am using the acts_as_state_machine plugin to control state of an object in my app, however when testing this I need to be able to stub out the guard conditions so that state will change when I fire off an event without depending on other models. Guard conditions simply return true or false so I have an instance method: def encoded? <check state of other objects> return true
2007 Apr 07
5
Integration Specs On Rails
Now that RSpec is nearing 1 dot oh, are there any plans to implement an integration testing equivalent in RSpec On Rails?
2007 Feb 07
3
odd mock behavior
I''m seeing some odd behavior around the should_receive() when given a block combined with some cardinality. For example, with the following... my_mock.should_receive(:foo).twice do |i| puts i end ... the spec passes but i never gets puts''ed. With the following... my_mock.should_receive(:foo) do |i| puts i end ... i gets puts''ed twice but the spec fails because
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 Feb 23
2
Deferred success for specs?
I''ve started using specs as a to-do list. I write explicitly violated specs so I know what to come back to. But a lot of the time, that means if I start to work on another piece of functionality covered by the same spec, it''s hard to tell what I''m working on now from the explicit failues. I run all my specs through TextMate to use the HTML output, so I go by
2007 Jul 29
24
View-Driven-Development by Behavior-Driven-Development and RSpec
One of the things that turned me on to BDD and RSpec was speccing views first, that the desired end would drive the development. In previous projects while using Test::Unit I would try to make educated guesses as to what would be needed in the model and controllers to derive the view without actually writing the view until afterwards. This is all because testing relied on each previous
2006 Nov 03
10
[PLUGIN] rspec_resource_generator - RESTful scaffold generator with RSpec specifications
rspec_resource_generator ======================== By Pat Maddox Use this generator to generate RESTful scaffolding with RSpec specifications. Syntax is exactly the same as the scaffold_resource generator: ./script/generate rspec_resource ModelName [field:type field:type] When you run this generator, it will create a migration, model, and model spec file. In addition, it gives you a RESTful
2007 Jul 30
4
Stubbing Observers in rails?
In most of my tests I''d like to be able to stub out the observers for my models, but I''m not sure the best way to do this. I doesn''t look like there is a way to stub all instance methods, and I don''t seem to be able to stub early enough to stub out the observer as it''s instantiated. I can think of several hackish ways to get around it, but I was
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")
2006 Dec 20
16
Edge RSpec on Rails...what did I forget?
Started a new Rails project, and installed RSpec and the Rails plugin vendor/plugins/rspec (svn://rubyforge.org/var/svn/rspec/trunk/rspec) - 1332 vendor/plugins/rspec_on_rails (svn://rubyforge.org/var/svn/rspec/trunk/rspec_on_rails/vendor/plugins/rspec_on_rails) - 1332 Generated the rspec file, created a model...the spec runs fine if I do ruby spec/models/foo_spec.rb. Running rake though gives
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
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 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
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
2007 Oct 30
1
Facets and/or Nested Describes
I have to confess that I did not know about facets before reading Ashley Moran''s post: http://aviewfromafar.net/2007/10/21/quick-and-dirty-facets-in-rspec-trunk Not knowing about the facets solution, I made a couple of feature requests for nested describes: http://rubyforge.org/tracker/index.php?func=detail&aid=14980&group_id=797&atid=3152
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 Sep 30
9
Problems with testing nested routes using mocking
Hello forum I have there to files #----- virtual_host_controller.rb class VirtualHostsController < ApplicationController before_filter :capture_domain # GET /domain/1/virtual_hosts/1 def show @virtual_host = @domain.virtual_hosts.find(params[:id]) respond_to do |format| format.html # show.rhtml end end private def capture_domain if
2007 Apr 11
10
DRYer controller specs
So, I''ve been following the recommendations for controller specs here: http://blog.davidchelimsky.net/articles/2006/11/09/tutorial-rspec-stubs-and-mocks Most notably: a single expectation per specify block; the setup block contains only stubs; mock expectations each get their own specify block. (I''m still using 0.8, so I haven''t gotten the describe/it goodness yet.) I
2007 Aug 06
1
Stubbing Enumerable#each
I have a mock of an instance of a class which descends from Array: class ArrayDescendent < Array; end #... in the specs... @descendent = mock ArrayDescendent How would I stub out ArrayDescendent#each, which is inherited from Array, to return multiple values successively? I could use and_yield, but that is raising an arity error (the anonymous function/ block should expect only *one