Displaying 19 results from an estimated 19 matches for "and_raise".
2007 May 10
5
Shared behavior and_raise problem, and site aestetics
Hello,
Is anyone else having trouble with the and_raise method on mocks,
with respect to shared behaviors? If I do the following instead:
foo.should_receive(:bar).and_return { raise }
everything seems to work. I have been supplying no arguments to
and_raise, by the way.
Also, you may want to make the background in the code examples on the
home page...
2007 Aug 07
4
Problems with raising errors on a mocked object
I''m trying to mock a object to raise a certain error. By doing so I
get a ArgumentError on ActiveRecord''s save! method:
http://pastie.caboo.se/85628
I''ve tried to debug it but just can''t seem to find what I''m doing
wrong. Any help is greatly appreciated.
Cheers,
Eivind Uggedal
2008 Mar 19
2
rescue
...oesnt test my code''s response
# controller
def edit
@foo = Foo.find(params[:id])
rescue
flash[:notice] = "Unknown foo #{params[:id]}"
redirect_to foos_path
end
# spec
it "should flash error if not found" do
Foo.should_receive(:find).and_raise
get :edit, :id => ''1''
flash[:notice].should == "Unknown foo 1"
end
# run
Exception in...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080318/dc23a3bc/attachmen...
2007 Sep 13
2
Failing to raise an exception in a stub
...speccing the behaviour of a Rails create action, where I''m using
save! to catch failed saves. In the case of working save, I''m using
the following stub:
@client.stub!(:save!).and_return(true)
which works fine.
However, in the negative case,
@client.stub!(:save!).and_raise(ActiveRecord::RecordInvalid)
The save! call in the controller doesn''t seem to work. I get the
following error:
ArgumentError in ''ClientsController POST /clients with invalid
parameters should show new form again''
wrong number of arguments (0 for 1)
/Users/jarkko/Sit...
2008 Feb 13
5
Example controller spec no worky?
...r_template("#{RAILS_ROOT}/public/404.html")
response.response_code.should == 404
end
#end spec
Because I''m stubbing find does that mean the RecordNotFound exception
doesn''t happen and thus the 404 doesn''t render? I tried stubbing and
using should_raise, and_raise, whatever the heck it is, but I just don''t
get it, nothing seems to work. It behaves as expected when browser
tested! :O
I''m going to spontaneously combust!
[RSpec 1.1.2, Rails 2.0.2, ZenTest 3.8.0]
--
Posted via http://www.ruby-forum.com/.
2007 Oct 26
7
Weird failing spec
Hi guys,
I have a weird failing spec, for which I just cannot figure out the
reason of failure. I''m now rewriting my controller specs based on the
advice of David and Ashley, and I got stuck on this (see: [rspec-
users] specing rescue, ensure and else blocks of an Exception).
http://pastie.caboo.se/111221
I''ve tried everything, like stubbing out :update_attributes! , even
2007 Dec 06
6
mock libraries, Object#send, and Object#__send__
What is the appropriate way to stub out (and put an expectation on
Object#__send__), without getting warnings from the Rspec mock library?
Scott
2006 Nov 22
3
Controller Isolation
Hi,
I have a project that I had running under rspec 0.6.x and recently upgraded
to 0.7.2.
I am trying to isolate my controllers from the database as I go through and
change all the specs to run under 0.7.2.
I am having a problem where I need to make the create! method return the
mocked object as well as raise RecordInvalid exception. Is this at all
possible?
I use the rescue statement in my
2010 Aug 08
2
issue with rescue_action_in_public! and testing 404 responses
...not the correct way to test missing records?
My full example: (using factory_girl, rspec mocks and devise)
it "respons with 404 when trying to edit non-existing reads" do
rescue_action_in_public!
sign_in(@user)
Read.should_receive(:find_by_id_and_user_id!).with(2,
@user.id).and_raise(ActiveRecord::RecordNotFound)
get :edit, :id => 2
response.status.should eql 404
end
and the exception:
1) ReadsController resources respons with 404 for non existing reads for GET
/reads/2/edit
Failure/Error: get :edit, :id => 2
ActiveRecord::RecordNotFound
Thanks,
/C...
2007 Jan 09
6
rcov seg fault
Hi
Trying to get rcov going (has been working), but with the following context
and specs it fails.
context ''/account POST with invalid attendee'' do
controller_name :account
setup do
Attendee.stub!(:create!).and_raise(ActiveRecord::RecordInvalid.new(
Attendee.new))
end
specify ''should raise on create'' do
Attendee.should_receive(:create!).with({ ''name'' => ''Attendee''
}).and_raise(ActiveRecord::RecordInvalid.new(Attendee.new))
post :create, :atte...
2007 Feb 05
1
long jumping out of code in specs
...ng though this gauntlet respond properly to all the calls it
gets.
In my case calling RssParser.new is evidence enough that my code
executed like it should.
class SpecShortcut < Exception; end
specify "should call the standard parsing methods" do
RssParser.should_receive(:new).and_raise(SpecShortcut)
lambda{do_action}.should_raise(SpecShortcut)
end
Feeling pain like this while writing specs is usally an indication
that the code could be better designed. But I don''t see how else one
could spec ActiveRecord''s after_create hook, without going through
with moc...
2007 Aug 08
5
Can''t seem to spec a ActiveRecord::RecordInvalid exception properly...
1 def create
2 @user = User.new(params[:user])
3 @user.save!
4 self.current_user = @user
5 redirect_to user_path(@user)
6 flash[:notice] = "Thanks for signing up!"
7 rescue ActiveRecord::RecordInvalid
8 render :action => ''new''
9 end
I can''t seem to properly spec this out. I am trying numerous things, the
latest one is
2007 Aug 23
6
controller spec with model that validates_uniqueness
I want to use mocks and stubs to test the controller, but am having
trouble getting my validation not to trigger. Here''s the code:
# spec:
Image.stub!(:find).and_return(@image)
@image.should_receive(:save!).once.with(:any_args)
put :update, :id => @image.id, :category_id =>
@category.id, :image => {:name => ''test'', :image_number =>
2007 Oct 26
5
specing rescue, ensure and else blocks of an Exception
Greetings,
I''m using rspec with rcov for my applications and there is one issue
which I cannot solve nor can find any proper information regarding
it: specing what is in a rescue block in case of an exception.
I''m using Ruby on Rails and I usually make use of exceptions in my
controllers, like the following example:
def action
@foo = Foo.find(1)
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 Dec 29
15
Do you think it would look cleaner?
I was looking over some of my specs.
I was thinking that the following:
@game.should_receive(:name).and_return(''The Battle for Blaze'')
@game.should_receive(:people).and_return(5000000)
@game.should_receive(:activated).and_return(true)
Would it look cleaner if I could do this instead?
@game.should_recieve_and_return(
:name => ''The Battle for Blaze''
2007 Nov 04
3
Specing raising error, handling, and then not raising error
Hey guys and gals,
I have a snippet of code:
Net::SMTP(@host, @port, @from_domain) do |smtp|
@emails.each do |email|
begin
smtp.send_message email.encoded, email.from, email.destinations
@emails_sent += 1
rescue Exception => e
# blah
end
end
end
What I want to do is:
Say there are 4 emails.
First email is sent OK
On the second email smtp raises a IOError
2007 Aug 31
48
Deprecating the mocking framework?
I saw in one of Dave C.''s comments to a ticket that "our current plan
is to deprecate the mocking framework." I hadn''t heard anything about
that, but then again I haven''t paid super close attention to the list.
Are we planning on dumping the mock framework in favor of using Mocha
(or any other framework one might want to plug in?).
Pat
2007 Jul 26
5
Coding standards and whitespace
...ndle/Commands/Alternate File.tmCommand
RSpec.tmbundle/Commands/Run Focussed Specification.tmCommand
RSpec.tmbundle/Commands/Run Specifications - Normal.tmCommand
RSpec.tmbundle/Commands/Run Specifications in selected files or
directories.tmCommand
RSpec.tmbundle/info.plist
RSpec.tmbundle/Snippets/and_raise.tmSnippet
RSpec.tmbundle/Snippets/and_return_block.tmSnippet
RSpec.tmbundle/Snippets/and_return_value.tmSnippet
RSpec.tmbundle/Snippets/and_throw.tmSnippet
RSpec.tmbundle/Snippets/and_yield.tmSnippet
RSpec.tmbundle/Snippets/any_number_of_times.tmSnippet
RSpec.tmbundle/Snippets/at_least.tmSnippet
RS...