Displaying 20 results from an estimated 5000 matches similar to: "specing class methods"
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 Apr 13
21
ZenTest autotest now handles RSpec, yay!
Josh Knowles http://joshknowles.com/ just let me know that ZenTest Autotest
3.50 now handles your RSpec specs.
http://blog.zenspider.com/archives/2007/04/zentest_version_350_has_been_released.html
That''s a great news.
Josh also shared with me a quick hack to make autotest work with only the
RSpec plugin installed.
Add the following into your ~/.autotest file
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 Nov 13
2
Trouble stubbing a method
Hey guys,
I''ll try to explain this without the model code at first, since there is so
much, but if need be, I''ll pastie it.
I have an Order model that makes API calls to a payment
gateway(TrustCommerce) during validation(to verify the credit card
information). I''d like to stub this behavior to avoid thousands of calls to
TrustCommerce a day(autotest).
All the calls
2008 Mar 05
3
having trouble specing an ajax request
Do I need to spec an AR. If yes, what is the best way to spec this.
here is the code -
def index
@deals = Deal.paginate(:all, :conditions =>
prepare_search_conditions, :order
=> ''created_at DESC'', :page => params[:page]
)
if request.xhr?
render :update do |page|
page.replace_html "table", :partial =>
2007 May 30
18
autotest and rspec_on_rails not happy
Hi,
I''ve been using the rspec and rspec_on_rails plugins quite happily on
my Rails project for a while now. Today I noticed the autotest
support in RSpec-1.0.3 and decided to give that a spin.
Oh tragedy!
$ autotest
loading autotest/rails_rspec
./vendor/plugins/rspec_on_rails/lib/autotest/rails_rspec.rb:33:in
`initialize'': undefined method `singularize''
2007 Jul 09
12
Mocking User.find( :all, :limit => 10 )
Hi,
I''m trying to setup a mock for my controller test but I can''t get it to
recognise the mock.
I use
it "should find all users" do
User.should_receive(:find).with( :all, :limit => 10
).and_return([@user])
do_get
end
and in the controller
@users = User.find(:all, :limit => 10 )
But this does not work. It gives me
User expected :find with (:all)
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
2008 Mar 15
3
[HELP]No :secret given to the #protect_from_forgery call
I am starting to BDD. When specing the controller I want to test for
object creation:
it "deberia crear una nueva persona en post create" do
Usuario.should_receive(:create).with({:nombre => "camilo", :clave
=> "secreta", :tipo => "administrador"}).and_return(@usuario)
post ''create'', {:usuario => {:nombre =>
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 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 Aug 22
1
mock framework ethics question
Hi James, Jim, and everyone else who''s listening.
I''ve been investigating an interesting bug related to mocks and rails
AssociationProxies. See
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=12547&group_id=797
for details.
The crux is that if you do this (rspec mock syntax):
obj.should_receive(:msg).with(mock_of_a_model)
and the implementation does
2008 Nov 07
6
How to spec a (Trollop-based) binary’s internal state?
I?m trying to spec a ?binary?, and as previously discussed on this list,
I?m trying to do it ?from outside? ? i.e., by calling it with Kernel#`
and observing the (side-)effects.
Unfortunately, this doesn?t really let me spec expectations about its
internals. Let?s assume I have a -d flag and I parse it with Trollop to
set Conf.debug:
opts = Trollop::options do
opt :debug, ''Print debug
2007 Jul 28
2
specing a call to render :layout => "some_layout"
I''m trying to specify that an action should be rendered with a given layout
one particular spec.
What I''ve got at the moment is this.
it "should render with the grabber layout" do
controller.should_receive( :render ).with( :layout => "my_layout" )
do_get
end
This doesnt work even though this call to render is being executed.
render :layout
2008 Aug 26
9
stub_model() and ActiveRecord Associations
Hi all,
I have what I thought was quite a simple requirement but something to
do with the way ActiveRecord''s associations work is making it quite
puzzling.
I guess I can sum it up with this failing test:
before(:each) do
@source_comment = @source.comments.create(:user_id => 1)
@target_comment = @target.comments.create(:user_id => 1)
end
2007 May 23
2
rspec mocha and controller specs without integrated_views
The ability to choose a mocking framework is great as I prefer mocha, but I
am have problems.
On my controller specs, I am forced to ''integrate_views'' as the following
code below shows you, the mocking of views is rspec specific. See stub!
versus mocha''s stub
unless block_given?
unless integrate_views?
2007 Oct 26
3
Specing with Subdomains as Account Keys
How do you go about implementing and rspecing subdomains as account
keys? I''m sure that this must be an issues for others as well.
So I have an app using subdomains as account keys. The Application
Controller sets up @current_company in a before filter. Everything is
done within the context of the @current_company.
After reading about Demeter''s Revenge
2010 Nov 12
2
pending tests fail when I switch to mock_with :mocha
First of all, please direct me into how better to search existing threads in
this mailing list.
Ok to my rspec 2.0.1 mocha 0.9.8 issue:
given a controller test
before do
subject.expects(:authenticate).once
end
it "should bla bla" do
pending "PENDING, shouldn''t fail?"
end
with
config.mock_with :rspec
it''s ok: pending, but with