Displaying 20 results from an estimated 10000 matches similar to: "Mocking documentation"
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 Nov 18
9
Not sure why this is failing
I am not sure why the tests don''t see the call of the new method for the
Address class. It can be seen in the controller method where the
Address.new is called.
>> @address = Address.new(params[:address])
What am I doing wrong?
Thanks for the help.
Here is the error message:
Spec::Mocks::MockExpectationError in ''UsersController handling POST
/users should create a new
2007 Jul 18
5
Mocking Rails association collections
Rails model association collections allow you to do nifty things like:
article.comments.find(:all, :conditions => {:created_at > 1.day.ago})
Has anyone found a good way to mock this up? I''m currently doing this:
@comment1 = mock_model(Comment)
comments = mock(Array)
comments.stub!(:find).and_return([@comment1])
@article = mock_model(Article)
2008 May 26
7
Mocking Models in Controller Specs...
I find myself doing this kind of thing a lot in Controller Specs:
@vacancy = mock_model(Vacancy)
@vacancy.stub!(:reference)
@vacancy.stub!(:title)
@vacancy.stub!(:created_at)
@vacancy.stub!(:updated_at)
@vacancy.stub!(:body)
@vacancy.stub!(:contract)
@vacancy.stub!(:location)
@vacancy.stub!(:salary)
@vacancy.stub!(:benefits)
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))
2007 Sep 18
2
rSpec / Nested Routes / Mocks
I''m having a terrible time trying to test a nested route with rSpec.
I can''t seem to tell rSpec to expect the call @item.user. The
following error message plagues me not matter how I try to fuss with
the mock:
Spec::Mocks::MockExpectationError in ''ItemsController handling POST /
items should redirect to the new course on successful save''
Mock
2007 Jun 24
6
mocking errors
What is the correct way to mock out the errors on a Rails model?
I''m assuming i need to say
@mock_thing = mock_model(Thing)
@mock_thing_errors = mock("errors")
@mock_thing_errors.should_receive(:full_messages).and_return("An error")
@mock_thing.should_receive(:errors).and_return(@mock_thing_errors)
Just wanted to check the best practice on this kind of thing and how
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 30
4
Mocking with Calculated Results
I am setting up an AR mock object and wanted to sanity check it. My
intent is to mix this into all my examples and then override/add
methods where necessary. Note that I''ve anticipated three cases for
find:
find with one numeric argument => object
find with :all => Array
find with anything else => nil
This roughly approximates how ActiveRecord::find works in this case
2007 Jun 07
4
checking associated objects have been deleted
I have the following model:
class Book < ActiveRecord::Base
has_many :taggings, :dependent => :delete_all
has_many :tags, :through => :taggings
end
is it possible to check that associated taggings are being destroyed
using mocks? I don''t want to test that rails is deleting the
associations, I want to test that I have specified the association as
a dependent one.
the only
2007 Jul 24
6
Mocking Access Control
I''m trying to jump on the TDD/BDD bandwagon, but am having trouble
understanding how i should mock my user. The user has a habtm
relationship to a roles model (acl_system2 plugin), but I''m not sure
how to tell rspec about a model.
My code:
describe UsersController do
integrate_views
before(:each) do
@user = mock_model(User)
2008 Jun 03
9
Build rspec-rails as a gem?
I can''t figure out how to build rspec-rails as a gem when just cloned
from github... there isn''t any .gemspec file or rake task that does
this. Any help?
--
Posted via http://www.ruby-forum.com/.
2007 Oct 08
6
spec''in controllers request for nested routes
describe PlayersController, "handling GET /saltmines/games/1/players" do
before do
@game = mock_model(Game, :to_param => "1")
@game.stub_association!(:players, :find => mock_model(Player))
end
def do_get
get :index, :game_id => @game
end
it "should be successful" do
do_get
response.should be_success
end
it "should
2007 Oct 18
4
Mocking models provided in Rails plugins
Hey folks,
How do I mock a model that is given to me by a Rails plugin? I''m
trying to mock Session from the restful_authentication plugin but I
get a number of errors telling me RSpec doesn''t recognize Session.
NameError in ''SessionsController handling GET /sessions/new should be
successful''
uninitialized constant Session
An example of my usage:
2007 Jul 24
4
Possible Bug
I''m trying to test some code that has validates each and I''ve got a very
strange failure
Mock ''Book_1027'' expected :store_with_privacy? with (#<Clip:0x1a99b96
@name="Clip_1025">) but received it with (#<Clip:0x1a99b96
@name="Clip_1025">)
The Spec
it "should check that a book can save a clip" do
@user =
2007 Apr 20
5
stubbing with and without a string
What is the difference between these two ways of mocking (with and
without the string):
mock(''Object'')
and
mock(Object)
?
Scott
2007 Jun 25
5
strange mock error
I''m testing using the rspec mocking framework and rspec 1.0.5 and I''m
getting the following strange error:
#<Spec::Mocks::Mock:0x337f7c8> expected :set_defaults with (#<Service:
0x19c4040 @name="Service_1023">, {"1"=>"1", "2"=>"2"}) but received
it with (#<Service:0x19c4040
2009 Feb 25
2
How to properly mock a complex object "comment.initiator.group.name"?
I am wondering what is the best way to mock such expression:
"comment.initiator.group.name"
What I do now is:
===========================
comment = mock_model(Comment)
initiator = mock_model(User)
group = mock_model(Group, :name => "Admin")
initiator.stub!(:group).and_return(group)
comment.stub!(:initiator).and_return(initiator)
===========================
So it becomes
2012 Aug 03
1
Mock_model not recognizing act_as_mappable
I am using mock_model in my tests, and I encountered a situation where my
stub is failing. Here''s the scenario:
Controller:
@locations = Location.al(:bounds=>bounds)l
@locations.sort_by_distance_from([bounds.center.lat,bounds.center.lng])
Rspec:
@location = mock_model(Location)
Location.stub(:all).and_return([@location])
2007 Aug 17
11
[rspec] looking for a simple refresher
I''ve been off the rspec for a few months and I''m trying to get back on it.
1)
Spec::Mocks::MockExpectationError in ''TicketsController handling POST
/tickets should create a new ticket''
Mock ''Ticket_1001'' expected :new with ({}) once, but received it 0 times
./spec/controllers/tickets_controller_spec.rb:16:
script/spec:4:
class