Displaying 20 results from an estimated 4000 matches similar to: "Does a mock model have to satisfy contraints"
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 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 12
3
Agh, this is annoying. Why is this happening?
My problem:
Mock ''Task_1005'' received unexpected message :user_id= with (1)
No matter what I do to try to stub that out it will still fail out and give
me that message.
Here is my spec
describe TasksController, "handling POST /tasks" do
before(:each) do
@task = mock_model(Task, :to_param => "1", :save => true)
2007 May 20
9
How to test for exceptions
Hi folks,
I''m in the process of converting a Test::Unit functional test to RSpec, but I''ve run into a slight problem. I tried looking through the documentation but I still don''t know what I missed.
Thanks in advance,
Blake
describe VenuesController, "on update" do
before(:each) do
@venue = mock("venue")
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
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 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 Jan 24
2
A spec where interaction-based testing breaks down... (at least for now)
Here are the specs:
context "Finding all the stylesheets available to a company" do
setup do
@mock_company = mock("company")
@mock_company.stub!(:to_param).and_return "1"
Stylesheet.stub!(:find)
end
def do_find
Stylesheet.find_available_to @mock_company
end
specify "should convert the company into a parameter" do
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 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 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 Feb 17
1
"warning: object#id will be deprecated" with mocks
hi all
I have the following code in a spec:
@user = mock("user")
User.stub!(:authenticate).and_return(@user)
@user.should_receive(:id).once.and_return(99)
post :login, {:username => ''username'', :password => ''password''}
session[:user_id].should == 99
it works as expected but I get the following warning when I run the spec:
warning:
2010 Jul 29
1
Testing controller and action with parameters
I have an action and I am testing it like this:
The action:
==========
def create
@event = Evento.new(params[:event])
@event.aproved = false
if @event.save
redirect_to :action => "index"
else
render :action => "new"
end
end
The RSpec test:
==============
before do
@event = mock_model(Event)
2009 Feb 20
6
How to mock an object defined in the before_filter function?
Hello,
I am trying to implement the following scenario, but I am stuck ...
The thing is I want to initialize a variable @comment when the stub
function "find_comment" is called.
The way I do it below doesn''t work, since
"before_filter :find_comment" returns true/false and @comment
initialization is done inside it. Could you please give me a hint how
to do it?
One
2007 Oct 05
13
spec''ing view render partial collection, local variable not found
I''m trying to spec out a render partial collection but I get the following
error
2)
NoMethodError in ''/games/_game.rhtml should show game name''
undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c>
/Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in
`matches?''
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
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)
2007 Jun 02
7
I''m really bad at controllers, help please.
Hey,
Sorry for so many questions - I''m really bad at this right now.
I''m trying to cover the following code w/ rspec
def index
if params[:user_id]
@user = User.find(params[:user_id])
@messages = @user.messages
end
end
So basically what I''m doing is listing all the messages for a user,
provided there is an id parameter.
describe
2008 Mar 08
3
should_receive(:foo).with(any_object)
Hey,
I just ran into a situation where I would like to expect a method call
with an argument I know and another one, which is a 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
2007 Jul 18
10
Rails - Mock going out of scope?
Hello list,
I think I have a rails related RSpec problem with a mock going out of
scope on a recursive call to a model.
The code is at: http://pastie.textmate.org/79821 if you want to see it
highlighted. I have pasted it below as well.
Basically, I have an acts_as_nested_set model called "Node", which
works fine. I have a function which finds the language name of the
node instance.