Displaying 20 results from an estimated 100000 matches similar to: "should_receive"
2006 Dec 18
2
should_receive and multiple return values
Hi
I just got bit by a misunderstanding about and_return.
I''ve got this controller method parse_parameters that loops over
query string parameters and parses out vehicle registration dates.
We have to turn these into one of three bands (Jan-Feb, Mar-Aug, Sep-
Dec) so I wrote a method (registration_date_to_band_year_and_month)
takes a date and returns two return values, the year
2007 Oct 26
1
Spec custom finders
I have some finders in my models where I write some of the sql myself. I
of course want to test these, but am not sure the best way. Should I just
let them roll through to the db, and verify they return the correct
objects based on the fixtures I load, or should I spec the actual query? I
know that DB access is sort of frowned upon, but is this a situation where
it is more or less acceptable? My
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 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
2008 Jan 13
2
should_receive twice and arguments
Hi all, I have a method calling Klass.create! two times with different
arguments (this happens in a class reponsable for reading in a csv file)
I want to test those like this:
in one test: Klass.should_receive(:create!).with(:name => "foo").once
in another: Klass.should_receive(:create!).with(:name => "foo2").once
This doesn''t work because the
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
2008 Mar 14
2
Multiple should_receive(:render).with
I''m trying to specify that a particular view must render two different partials.
My spec looks like:
describe AClass do
it do
template.should_receive(:render).with(:partial => ''foo'', :locals => { ... })
...
end
describe ''some conditional case'' do
it do
template.should_receive(:render).with(:partial =>
2007 Aug 17
4
should_receive, used in the wrong place?
What do you guys think of this: if someone calls should_receive
outside of an "it" block, it warns you.
before(:each) do
@foo = Foo.new
@foo.should_receive(:monkeys)
end
would warn you that you''re setting an expectation in the wrong place,
and that "stub" is correct when setting up objects.
Opinions?
courtenay
2007 Nov 15
2
Trouble using should_receive
I have this code trying to ensure my reset method works. I want to
make sure all the participants have their destroy method called.
# in my spec for Room
r = Room.new(:name => ''bob'')
r.save
p = Participant.new(:login => ''a'', :password =>
''b'', :password_confirmation => ''b'')
p.room = r
2007 Jun 14
1
rspec will_paginate
Hi Rspec-Users,
I''m not sure if I am correctly specing my index since I''m using
will_paginate.
params[:filter_by] will filter the paginate list accordingly.
Tickets Controller:
def index
@tickets = Ticket.filter_status_by(params[:filter_by],params[:page])
end
Ticket Model:
def self.filter_status_by(status, page, per_page = 10)
conditions = {:status => false} if
2007 Oct 22
0
Pending should_receive shows as FIXED
I have a mock should_receive expectation wrapped in a "pending" block, and
it appears as being fixed when the specs are run, when in reality it is
not. Anyone else experience this behavior? I''m assuming this is because
the mock waits until the "it" block completion to determine expectations
rather than its enclosing "pending" block.
Steve
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
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:
2008 Mar 08
1
Session empty after request
Can anyone tell me what I''m doing wrong here?
it ''should try to set the current user from the session'' do
controller.session[SessionKeys::USER_ID] = 1
user = mock_model(User)
User.stub!(:find).and_return(user)
User.should_receive(:find).with(1).and_return(user)
controller.should_receive(:set_current_user)
do_request
end
When I watch the spec with my
2013 May 11
1
STDOUT.should_receive(:puts).with Works *** (:print) fails
I use: STDOUT.should_receive(:puts).with...... many times in RSPEC
However, I have a couple of "do you want(Y/N)?" where I use ''print''
and apparently ..(:print).with... does not work. I can change ''print''
to ''puts'' and it works perfectly.
How do I test :print and ...getch("y") for input???
Any help would be
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 Jun 21
4
should_receive stubs methods?
Hey,
I''m using rspec and rails and have a spec that tests if a before_filter is
executed, I also have a spec that tests if a method called by the filter is
executed. It appears however that when I should_receive something, it is no
longer actually called when I fire the http request. I''m not sure how, or
where exactly I should manually fire the filter, either before or after the
2008 Jun 12
1
how do I mock the Rails Logger with should_receive?
Hey Guys,
I''m trying to mock the Rails Logger for the following code:
...
rescue TimeoutError => error
$logger.error("#{self.name} Timeout for #{path}: #{error}") and return
rescue SocketError => error
$logger.error("#{self.name} SocketError for #{path}: #{error}") and
return
rescue StandardError => error
2008 Jun 12
1
Does anyone know how to mock the Rails Logger then set expectations with should_receive?
Hey Guys,
I''m trying to mock the Rails Logger for the following code:
...
rescue TimeoutError => error
$logger.error("#{self.name} Timeout for #{path}: #{error}") and return
rescue SocketError => error
$logger.error("#{self.name} SocketError for #{path}: #{error}") and
return
rescue StandardError => error
2007 Oct 16
6
Failure trying to test ApplicationController
I''m trying to write some tests for the ApplicationController as shared
tests that can be run in all of my other controller tests, but am getting
a nil.rewrite error. Below is what I have...
describe AccountController do
it_should_behave_like ''Application controller''
end
describe ''Application controller'', :shared => true do
it