Displaying 20 results from an estimated 1000 matches similar to: "rescue"
2010 Aug 08
2
issue with rescue_action_in_public! and testing 404 responses
Hello,
I''m new to rails and I''m trying to wrap my heads around how to spec
controllers using RSpec (using rails 3rc1 and rspec 2.0.0.beta.19).
The problem I''ve run into is when I want to test that my controllers respond
with a 404 for unfound records.
Whenever I run the spec, the ActiveRecord::RecordNotFound exception is not
caught by rails, causing the spec
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 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 a little lighter. I am hardly able to
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''
2008 Sep 02
4
Rescue rails errors
Hi all,
Sometime, I get the following error in my application:
ActionController::InvalidAuthenticityToken in
ManageController#site_servers
ActionController::InvalidAuthenticityToken
I tried to put the code in manage controller between begin ... rescue
... end but it didn''t catch the error.
So I tried in the application.rb controller, I put the forgery code
between begin ... rescue ...
2007 Sep 13
2
Failing to raise an exception in a stub
I''ve come across rather strange behaviour when trying to raise an
exception in a stubbed method.
I''m 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,
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)
2008 Feb 13
5
Example controller spec no worky?
I''m trying to spec a dead simple "show non-existent record should render
404" case, but it seems the RecordNotFound exception is making it
impossible for some reason.
#controller
def show
@event = Event.find(params[:id])
end
#spec - pretty much straight from the rspec site
before do
Event.stub!(:find)
get :show, :id => ''broken''
end
#
2008 Aug 21
1
rescue_from failing to rescue [from]
Having some weird failures of rescue_from in all my specs. They still
rescue in actual usage, just not in my specs. Made a pastie of the code:
http://pastie.org/257399 This is with latest [as of 1:00 PM Eastern time
zone] rspec/rspec-rails/edge. Thanks in advance for any replies on this.
RSL
--
Posted via http://www.ruby-forum.com/.
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
2007 Feb 05
1
long jumping out of code in specs
I wrote this abomination just now, and wonder if anyone else has had
experience with the pattern behind it. In short, I''m specing an
after_create hook on an ActiveRecord model, that calls a bunch of
private methods. Instead of stubbing all those private methods (which
is verboten anyway, as well as impossible because creating the object
which owns those methods is what I''m
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
2009 Feb 10
2
rescue_from for NoMethodError
Hi everyone,
I was just trying to catch some exceptions in my app,
for "Record Not Found" I used this
in my application.rb file
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
rescue_from ActionController::NoMethodError, :with => :show_error
private
def record_not_found
render :text => "404 Not Found", :status =>
2008 Apr 30
7
rescue_from issue with AWS - uninitialized constant
The new rescue_from in edge rails seems to conflict with
ActionWebService, which I need for various other purposes. When I
define, for example (with AWS gem installed):
<b>rescue_from ActionController::RoutingError, :with
=> :page_not_found</b>
I get the exception:
<b>uninitialized constant
ActionWebService::Dispatcher::ActionController::Base</b>
OK, so AWS
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
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
2009 Dec 25
18
rescue_from ActionController::RoutingError II
OK ... so I''m not supposed to use it but ...
Why doesn''t rescue_from ActionController::RoutingError work witht he
code from
http://www.rubyplus.org/episodes/20-Extended-RESTful-Authentication-Rails-2-App.html
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
# See ActionController::RequestForgeryProtection for details
2013 Nov 12
7
Hook into Exception Chain
Hi there,
I''m using Log4r in my rails projects. On log.error an email is sent using
the EmailOutputter.
I know changed the EmailOutputter to include a global var in the subject
(MDC) since the subject is normally static.
I want to set this var to the exception message, so it is sent as the
subject.
Can anyone tell me how to do this in rails?
Basically:
raise e or some other cause
2007 Jul 31
11
helper spec not finding rails core helpers
Hi,
My helper specs were going ok until I added a call to a rails
DateHelper method in one of my helpers
http://api.rubyonrails.com/classes/ActionView/Helpers/
DateHelper.html#M000574
The helper runs fine from my view templates, just dies in the spec test.
I boiled my question down to a simple (not too useful) example. I''m
not sure what I''m missing.
#
2007 Oct 21
7
exact exceptions in rescue_from
rescue_from stores exception class names in a hash table, and
associates them with handlers.
When an exception is raised there''s a name lookup, and if an entry is
found its handler is invoked. In particular rescue_from does not
emulate Ruby''s rescue semantics with regard to inheritance.
Which is the rationale? Don''t you think taking is_a? and declaration
order