Re: [rspec-users] raise_controller_errors

2007-07-09 Thread Edward Ocampo-Gooding
David Chelimsky wrote:
> On 7/9/07, Edward Ocampo-Gooding <[EMAIL PROTECTED]> wrote:
>> David Chelimsky wrote:
>>> Did you run "ruby script/generate rspec"?
>> Yep; but this time I let it regenerate spec.opts
>>
>> Turns out that the --drb flag is the culprit.
> 
> I don't understand how --drb is related to this. You said you were
> seeing a problem with a method that used to be in spec_helper.rb and
> has been removed (raise_controller_errors). What does that have to do
> with --drb?

No, it's always been a virgin generated spec_helper.rb file; I was just 
wondering earlier if I was missing something in that.

I previously had --drb in my spec.opts and was having those "undefined 
local variable or method `raise_controller_errors'", but after removing 
--drb, everything works as expected.

Edward
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] raise_controller_errors

2007-07-09 Thread David Chelimsky
On 7/9/07, Edward Ocampo-Gooding <[EMAIL PROTECTED]> wrote:
> David Chelimsky wrote:
> > Did you run "ruby script/generate rspec"?
>
> Yep; but this time I let it regenerate spec.opts
>
> Turns out that the --drb flag is the culprit.

I don't understand how --drb is related to this. You said you were
seeing a problem with a method that used to be in spec_helper.rb and
has been removed (raise_controller_errors). What does that have to do
with --drb?

>
> I'll file (or look for a similar) bug report.
>
> Edward
>
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] raise_controller_errors

2007-07-09 Thread Edward Ocampo-Gooding
David Chelimsky wrote:
> Did you run "ruby script/generate rspec"?

Yep; but this time I let it regenerate spec.opts

Turns out that the --drb flag is the culprit.

I'll file (or look for a similar) bug report.

Edward

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] raise_controller_errors

2007-07-09 Thread David Chelimsky
Did you run "ruby script/generate rspec"?

http://rspec.rubyforge.org/upgrade.html

On 7/9/07, Edward Ocampo-Gooding <[EMAIL PROTECTED]> wrote:
> Hi Folks,
>
> I think I've run into a problem after upgrading to edge rspec [revision
> 2160], but I'm not sure where to fix things.
>
> Default controller specs that look like this:
>
> 
> require File.dirname(__FILE__) + '/../spec_helper'
>
> describe PurchaseController do
>
>#Delete this example and add some real ones
>it "should use PurchaseController" do
>  controller.should be_an_instance_of(PurchaseController)
>end
>
> end
>
> 
>
> are now causing errors like these:
>
> 
> NameError in 'PurchaseController should use PurchaseController'
> undefined local variable or method `raise_controller_errors' for [RSpec
> example]:#
> ./spec/models/../spec_helper.rb:12:
> 
>
> For the record, my spec_helper.rb is just the default generated one:
>
> 
> ENV["RAILS_ENV"] = "test"
> require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
> require 'spec/rails'
>
> Spec::Runner.configure do |config|
>config.use_transactional_fixtures = true
>config.use_instantiated_fixtures  = false
>config.fixture_path = RAILS_ROOT + '/spec/fixtures'
> end
> 
>
> Am I missing something in spec_helper.rb or do I have some residual
> stuff from a previous version of rspec? I'm pretty sure that I've gotten
> rid of the generated stuff, but could I be missing something?
>
> Thanks,
> Edward
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] raise_controller_errors

2007-07-09 Thread Edward Ocampo-Gooding
Hi Folks,

I think I've run into a problem after upgrading to edge rspec [revision 
2160], but I'm not sure where to fix things.

Default controller specs that look like this:


require File.dirname(__FILE__) + '/../spec_helper'

describe PurchaseController do

   #Delete this example and add some real ones
   it "should use PurchaseController" do
 controller.should be_an_instance_of(PurchaseController)
   end

end



are now causing errors like these:


NameError in 'PurchaseController should use PurchaseController'
undefined local variable or method `raise_controller_errors' for [RSpec 
example]:#
./spec/models/../spec_helper.rb:12:


For the record, my spec_helper.rb is just the default generated one:


ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'spec/rails'

Spec::Runner.configure do |config|
   config.use_transactional_fixtures = true
   config.use_instantiated_fixtures  = false
   config.fixture_path = RAILS_ROOT + '/spec/fixtures'
end


Am I missing something in spec_helper.rb or do I have some residual 
stuff from a previous version of rspec? I'm pretty sure that I've gotten 
rid of the generated stuff, but could I be missing something?

Thanks,
Edward
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Mocking User.find( :all, :limit => 10 )

2007-07-09 Thread David Chelimsky
On 7/9/07, Johan Sørensen <[EMAIL PROTECTED]> wrote:
>
>
> On Jul 9, 2007, at 5:42 PM, David Chelimsky wrote:
>
>
>
>
>
>
> As opposed to getting into complicated mocking scenarios, consider
>
> abstracting this logic into your model:
>
> http://blog.caboo.se/articles/2007/6/19/rspec-notes-from-the-trenches-2
>
>
>
>
> Agreed that this is a good approach in terms of dealing w/ rails
>
> models.
>
> I generally agree with this, no doubt. But when the it comes to big apps and
> bigger test/spec suites, all that database communication (and fixtures
> creation/teardown), slows testruns downs and that lowers the chances of
> people running them regularly.
> There's of course many different ways of dealing with this (another I'm
> doing is reworking the way fixtures work), but in a way I see it the same
> way as I do with, say, XML-RPC models (or REST, or other networking related
> models) that I maybe I don't really need to test communication with the
> network backend all the time, but more interested in that my model
> implementation behave like I expect them to when it comes to sending data to
> the client. Of course this starts to turn into a slightly slippery slope
> when it comes to rails since it relies so much its direct database mapping.
>
> I'm still trying this approach out along with other things to cut down specs
> runtime , and I eagerly await the day it bites me in the arse. :)
>
>
> As for the question of isolating specific key/value pairs in a
>
> hash, you could do this:
>
>
>
>
> obj.should_receive(:message) do |*args|
>
>   hash = args.pop
>
>   hash[interesting_key].should == expected_value
>
> end
>
>
>
>
> It's not pretty, but it works.
>
>
>
>
> The other thing you might consider is a custom matcher. Something like:
>
>
>
>
> obj.should_receive(:message).with(has_key_value(key,
> value))
>
>
>
>
> The mock framework can use these just as the expectation framework -
>
> though mocks rely on == instead of matches.
> Cheers, I didn't know that you could do custom matchers for those kind of
> expectations too.

It's not exactly widely publicized :) But that's how rspec's own
anything, numeric, etc mock argument matchers work.

>
> JS
>
>
>
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Mocking User.find( :all, :limit => 10 )

2007-07-09 Thread Johan Sørensen


On Jul 9, 2007, at 5:42 PM, David Chelimsky wrote:



As opposed to getting into complicated mocking scenarios, consider
abstracting this logic into your model:
http://blog.caboo.se/articles/2007/6/19/rspec-notes-from-the- 
trenches-2


Agreed that this is a good approach in terms of dealing w/ rails
models.


I generally agree with this, no doubt. But when the it comes to big  
apps and bigger test/spec suites, all that database communication  
(and fixtures creation/teardown), slows testruns downs and that  
lowers the chances of people running them regularly.
There's of course many different ways of dealing with this (another  
I'm doing is reworking the way fixtures work), but in a way I see it  
the same way as I do with, say, XML-RPC models (or REST, or other  
networking related models) that I maybe I don't really need to test  
communication with the network backend all the time, but more  
interested in that my model implementation behave like I expect them  
to when it comes to sending data to the client. Of course this starts  
to turn into a slightly slippery slope when it comes to rails since  
it relies so much its direct database mapping.


I'm still trying this approach out along with other things to cut  
down specs runtime , and I eagerly await the day it bites me in the  
arse. :)



As for the question of isolating specific key/value pairs in a
hash, you could do this:

obj.should_receive(:message) do |*args|
  hash = args.pop
  hash[interesting_key].should == expected_value
end

It's not pretty, but it works.

The other thing you might consider is a custom matcher. Something  
like:


obj.should_receive(:message).with(has_key_value(key, value))

The mock framework can use these just as the expectation framework -
though mocks rely on == instead of matches.


Cheers, I didn't know that you could do custom matchers for those  
kind of expectations too.


JS


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Mocking User.find( :all, :limit => 10 )

2007-07-09 Thread David Chelimsky
On 7/9/07, Josh Knowles <[EMAIL PROTECTED]> wrote:
>
>
> On 7/9/07, Johan Sørensen <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> >
> >
> > Is there a way in RSpec to check for a specific hash key (or evaluating
> other things along those lines) in the parameter expectation using the
> should_receive(:find).with(...) construct?
>
>
> As opposed to getting into complicated mocking scenarios, consider
> abstracting this logic into your model:
> http://blog.caboo.se/articles/2007/6/19/rspec-notes-from-the-trenches-2

Agreed that this is a good approach in terms of dealing w/ rails
models. As for the question of isolating specific key/value pairs in a
hash, you could do this:

obj.should_receive(:message) do |*args|
  hash = args.pop
  hash[interesting_key].should == expected_value
end

It's not pretty, but it works.

The other thing you might consider is a custom matcher. Something like:

obj.should_receive(:message).with(has_key_value(key, value))

The mock framework can use these just as the expectation framework -
though mocks rely on == instead of matches.

David

>
>
>
>
> --
> Josh Knowles
> [EMAIL PROTECTED]
> http://joshknowles.com
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Mocking User.find( :all, :limit => 10 )

2007-07-09 Thread Johan Sørensen


On Jul 9, 2007, at 5:38 PM, Josh Knowles wrote:


On 7/9/07, Johan Sørensen <[EMAIL PROTECTED]> wrote:


Is there a way in RSpec to check for a specific hash key (or  
evaluating other things along those lines) in the parameter  
expectation using the should_receive(:find).with(...) construct?



As opposed to getting into complicated mocking scenarios, consider  
abstracting this logic into your model: http://blog.caboo.se/ 
articles/2007/6/19/rspec-notes-from-the-trenches-2



Well, that's where it is, and for various reasons writing to the  
database is something I'm avoiding as long as I can (speedy tests and  
complex fk constraints being a few of them). I'm still not convinced  
that it's a good idea to do that for model specs, but that's another  
topic ;)


JS___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Mocking User.find( :all, :limit => 10 )

2007-07-09 Thread Josh Knowles

On 7/9/07, Johan Sørensen <[EMAIL PROTECTED]> wrote:




Is there a way in RSpec to check for a specific hash key (or evaluating
other things along those lines) in the parameter expectation using the
should_receive(:find).with(...) construct?




As opposed to getting into complicated mocking scenarios, consider
abstracting this logic into your model:
http://blog.caboo.se/articles/2007/6/19/rspec-notes-from-the-trenches-2




--
Josh Knowles
[EMAIL PROTECTED]
http://joshknowles.com
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Mocking User.find( :all, :limit => 10 )

2007-07-09 Thread Johan Sørensen


On Jul 9, 2007, at 5:00 PM, Daniel N wrote:


My Bad... Please ignore

On 7/10/07, Daniel N <[EMAIL PROTECTED]> wrote:
  it "should find all users" do
User.should_receive(:find).with( :all, :limit => 10 ).and_return 
([EMAIL PROTECTED])

do_get
  end


Sorry for piggybacking on your post, but since you've apparantly  
figured out your isssue I have a slightly similar question; sometimes  
I have (in ActiveRecord) a verbose #find I want to mock out using  
should_receive, maybe looking something along this:
Foo.find(:all, :select => "foos.*, bars.*, :joins => "join bazzers on  
foos.baz_id = ..", :conditions => "quux = 1", etc etc)
... But all I really may care about with a specific mock expectation  
is that it gets the right :conditions key in the passed-in hash.


Is there a way in RSpec to check for a specific hash key (or  
evaluating other things along those lines) in the parameter  
expectation using the should_receive(:find).with(...) construct?


JS

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Mocking User.find( :all, :limit => 10 )

2007-07-09 Thread Daniel N

My Bad... Please ignore

On 7/10/07, Daniel N <[EMAIL PROTECTED]> wrote:


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([EMAIL PROTECTED])
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) once, but received it 0 times

If I remove the :limit from the controller
@users = User.find(:all)

I get
User expected :find with (:all, {:limit=>10}) once, but received it 0
times

How do I spec mocks with options passed to them?

Cheers
Daniel

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

[rspec-users] Mocking User.find( :all, :limit => 10 )

2007-07-09 Thread Daniel N

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([EMAIL PROTECTED])
   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) once, but received it 0 times

If I remove the :limit from the controller
@users = User.find(:all)

I get
User expected :find with (:all, {:limit=>10}) once, but received it 0 times

How do I spec mocks with options passed to them?

Cheers
Daniel
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

[rspec-users] Is it bad to use a shared example in rspec_helper.rb?

2007-07-09 Thread Daniel N

I want to extract the method for logging in so that I don't have to include
it in each before call.

Is it bad to use a describe block within the rspec_helper in a rails project
for controller tests?

I have in my spec_helper.rb

describe "an authenticated request", :shared => true do
 before( :each ) do
   @u = mock_model( User )
   mock_login( @u )
 end

 def mock_login( user )
   session[:user] = user
   controller.send( :instance_variable_set, :@current_user, user )
   controller.stub!( :current_user ).and_return( user )
 end

end


which I then share in my relevant controller tests with

 it_should_behave_like "an authenticated request"

Is this bad?
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users