Displaying 20 results from an estimated 10000 matches similar to: "and_return broken when using arrays"
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
2006 Nov 10
2
mock syntax order
I have the following statement
mock_requester.should_receive(:request_with).with
("x").any_number_of_times.and_return(@object)
which works fine, but when i do it backwards, which makes the same
amount of sense syntactically, it fails
mock_requester.should_receive(:request_with).with("x").and_return
(@object).any_number_of_times
are all of the mock options
2007 Nov 01
2
Can''t use #exactly when #and_return influences it.
I want my class Reader to loop on the content of its Stack until false is
returned. I also want an optional argument to exist that limits how many
times the stack will be read, even if some elements are left. I was trying
to spec this last bit but ended up on a false positive.
Hope the example will be clear enough:
#spec_reader.rb
describe Reader do
it "should stop reading items when
2006 Oct 25
2
mock parameter problem
Here''s another one.
spec:
m = mock("blah")
m.should_receive(:foo).with(1)
code:
m.foo(2)
Failure message:
Mock ''blah'' expected ''foo'' once, but received it 0 times
------
Twice now I''ve gotten this failure message and wasted time trying to
understand why the method foo() was not being called despite all
evidence suggesting
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 Dec 04
10
Unexpected message on :attr_accessor
This may be a dumb noob issue, but I haven''t found any answers while seaching
the forum--
I have a controller method
def edit
@user = User.find params[:id]
@user.password_confirmation = @user.password
end
The User class has an "attr_accessor :password_confirmation" definition (so
"password_confirmation" doesn''t exist in the users table). My spec
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 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 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
2007 May 08
4
help with rspec''ing controller
Hi,
I''m a rspec newbie. I''m having trouble with rspec''ing a simple
controller to Create a record.
I''ve tried a couple of approaches and still get errors:
Mock ''remedy'' expected :save! with (any args) once, but received it 0
times
-or-
Mock ''Remedy'' received unexpected message :save with (no args).
Here are my two
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 Jul 24
2
Mocking Resolv::DNS?
Hello Rspecers,
I have a rails project where I am calling Resolv::DNS.open and then
using the block to check a domain name.
The code snippet in question is:
domain = "mytest.com"
Resolv::DNS.open do |dns|
@mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
end
I obviously want to stub this out, especially for speed but can''t
quite work out how.
I
2008 Mar 05
7
mocking successive return values
I''m having a problems mocking successive return values. I don''t know
if I''m doing something wrong or if this is a limitation of rspec
mocks. Any ideas of what I may be doing wrong?
I''m trying to test the generate_quote_number method. It generates a
quote number, looks to see if it is in the db already. If it is, it
calls itself to try again. I want
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 Jun 11
2
Testing create in Rails controller
Hi All
So I am a first-time caller ;-) ... and have been trying to apply
RSpec to the depot example in Dave Thomas'' book as I build the
application.
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 =
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 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
2011 Jul 27
3
Rspec with ActionMailer and .deliver
I''m in the process of migrating from Rails 2 with rspec 1 to Rails 3 with
rspec 2, the process has been going pretty well, however, today I came
across an issue that I wanted to share.
I have a controller that sends out an email through a mailer.
Rails 2
code: CurriculumCommentMailer.deliver_comment_update(@curriculum_comment,
"created")
Rails 3 code:
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 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