[rspec-users] Mocking Resolv::DNS?

2007-07-24 Thread Mikel Lindsaar
Hello Rspecers, I have a rails project where I am calling Resolv::DNS.open and then using the block to check a domain name. The code snippet in question is: domain = "mytest.com" Resolv::DNS.open do |dns| @mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX) end I obviousl

Re: [rspec-users] Mocking Resolv::DNS?

2007-07-24 Thread Pat Maddox
On 7/24/07, Mikel Lindsaar <[EMAIL PROTECTED]> wrote: > Hello Rspecers, > > I have a rails project where I am calling Resolv::DNS.open and then > using the block to check a domain name. > > The code snippet in question is: > >domain = "mytest.com" >Resolv::DNS.open do |dns| > @mx = dns

Re: [rspec-users] Mocking Resolv::DNS?

2007-07-24 Thread Mikel Lindsaar
Thank you, works perfectly! Regards Mikel On 7/24/07, Pat Maddox <[EMAIL PROTECTED]> wrote: > On 7/24/07, Mikel Lindsaar <[EMAIL PROTECTED]> wrote: > > Hello Rspecers, > > > > I have a rails project where I am calling Resolv::DNS.open and then > > using the block to check a domain name. > > > >

[rspec-users] Mock or Stub strategy for validates_uniqueness_of

2007-07-24 Thread Daniel N
Hi, I'm a bit stuck with mocking a unit test of a join model with regards to a validates_uniqueness_of clause. I have class Book < AR:B has_many :clippings various validates_presence_of etc end class Clip < AR:B has_many :clippings various validates_presence_of etc end class Clipping < A

Re: [rspec-users] Mock or Stub strategy for validates_uniqueness_of

2007-07-24 Thread Ashley Moran
On 24 Jul 2007, at 14:07, Daniel N wrote: > Any hints as to how to do this without using fixtures? I did this literally minutes ago. I don't use fixtures at all, ever. Instead I put the data in the before block, eg: describe Purchase, "assigned to a Quote that already has a saved purchase

Re: [rspec-users] Mock or Stub strategy for validates_uniqueness_of

2007-07-24 Thread Daniel N
On 7/24/07, Ashley Moran <[EMAIL PROTECTED]> wrote: On 24 Jul 2007, at 14:07, Daniel N wrote: > Any hints as to how to do this without using fixtures? I did this literally minutes ago. I don't use fixtures at all, ever. Instead I put the data in the before block, eg: describe Purchase, "as

[rspec-users] Possible Bug

2007-07-24 Thread Daniel N
I'm trying to test some code that has validates each and I've got a very strange failure Mock 'Book_1027' expected :store_with_privacy? with (#) but received it with (#) The Spec it "should check that a book can save a clip" do @user = mock_model( User, :id => 3 ) @clip = mock_model( Cl

Re: [rspec-users] Mock or Stub strategy for validates_uniqueness_of

2007-07-24 Thread Daniel N
On 7/24/07, Daniel N <[EMAIL PROTECTED]> wrote: On 7/24/07, Ashley Moran <[EMAIL PROTECTED]> wrote: > > > On 24 Jul 2007, at 14:07, Daniel N wrote: > > > Any hints as to how to do this without using fixtures? > > I did this literally minutes ago. I don't use fixtures at all, > ever. Instead

Re: [rspec-users] Possible Bug

2007-07-24 Thread Daniel N
On 7/25/07, Daniel N <[EMAIL PROTECTED]> wrote: I'm trying to test some code that has validates each and I've got a very strange failure Mock 'Book_1027' expected :store_with_privacy? with (#) but received it with (#) The Spec it "should check that a book can save a clip" do @user = moc

Re: [rspec-users] Possible Bug

2007-07-24 Thread David Chelimsky
On 7/24/07, Daniel N <[EMAIL PROTECTED]> wrote: > > > On 7/25/07, Daniel N <[EMAIL PROTECTED]> wrote: > > I'm trying to test some code that has validates each and I've got a very > strange failure > > > > Mock 'Book_1027' expected :store_with_privacy? with (# @name="Clip_1025">) but received it wit

Re: [rspec-users] Possible Bug

2007-07-24 Thread Daniel N
On 7/25/07, David Chelimsky <[EMAIL PROTECTED]> wrote: On 7/24/07, Daniel N <[EMAIL PROTECTED]> wrote: > > > On 7/25/07, Daniel N <[EMAIL PROTECTED]> wrote: > > I'm trying to test some code that has validates each and I've got a very > strange failure > > > > Mock 'Book_1027' expected :store_wit

Re: [rspec-users] Possible Bug

2007-07-24 Thread David Chelimsky
On 7/24/07, Daniel N <[EMAIL PROTECTED]> wrote: > > > > On 7/25/07, David Chelimsky <[EMAIL PROTECTED]> wrote: > > On 7/24/07, Daniel N <[EMAIL PROTECTED]> wrote: > > > > > > > > > On 7/25/07, Daniel N <[EMAIL PROTECTED]> wrote: > > > > I'm trying to test some code that has validates each and I've

[rspec-users] Rspec on rails with out database?

2007-07-24 Thread Eric Pugh
Hi all, I am trying to use rspec_on_rails in a Rails app that doesn't have a database. so far I have just been faking it out by dumping in a sqlite3 database just to make Rails happy. I was using for test::unit a rake task that eliminated the calls to database prep: # Added this .rake fil

[rspec-users] Mocking Access Control

2007-07-24 Thread Justin Williams
I'm trying to jump on the TDD/BDD bandwagon, but am having trouble understanding how i should mock my user. The user has a habtm relationship to a roles model (acl_system2 plugin), but I'm not sure how to tell rspec about a model. My code: describe UsersController do integrate_views before(

Re: [rspec-users] Mocking Access Control

2007-07-24 Thread David Chelimsky
On 7/24/07, Justin Williams <[EMAIL PROTECTED]> wrote: > I'm trying to jump on the TDD/BDD bandwagon, but am having trouble > understanding how i should mock my user. The user has a habtm > relationship to a roles model (acl_system2 plugin), but I'm not sure > how to tell rspec about a model. > >

[rspec-users] spec'ing helpers that use controller

2007-07-24 Thread Rick Tessner
Hi all, I'm in the process of creating rspecs for my helpers. One of the helpers in app/helpers/application_helper.rb looks like this: def page_name @page_name || "Define @page_name in #{controller.controller_name}::#{controller.action_name}" end The rspec is s

Re: [rspec-users] spec'ing helpers that use controller

2007-07-24 Thread Courtenay
Does this work? ApplicationHelper.stub!(:controller).and_return mock('controller', :controller_name => 'foo') On 7/24/07, Rick Tessner <[EMAIL PROTECTED]> wrote: > Hi all, > > I'm in the process of creating rspecs for my helpers. One of the > helpers in app/helpers/application_helper.rb looks

Re: [rspec-users] Mocking Access Control

2007-07-24 Thread Justin Williams
On 7/24/07, David Chelimsky <[EMAIL PROTECTED]> wrote: > Would you please post the code for the actions as well? def login if request.post? begin session[:user] = User.authenticate(params[:login][:email], params[:login][:password]).id if current_user.roles.include?(Role.find_by_title

Re: [rspec-users] spec'ing helpers that use controller

2007-07-24 Thread Rick Tessner
Hi, On Tue, 2007-24-07 at 15:26 -0700, Courtenay wrote: > Does this work? > > ApplicationHelper.stub!(:controller).and_return mock('controller', > :controller_name => 'foo') Sadly, no. Same result: undefined local variable or method `controller' for [RSpec example]: # -- Ri

Re: [rspec-users] Mock or Stub strategy for validates_uniqueness_of

2007-07-24 Thread Mikel Lindsaar
There would be a different way. In the idea of "Only test the code you write" all you really need to spec is that you have set the right association, because activerecord has it's own tests to ensure the uniq call works. You can do this with a call to reflect_on_association. Unfortunately that c

Re: [rspec-users] spec'ing helpers that use controller

2007-07-24 Thread Courtenay
On 7/24/07, Rick Tessner <[EMAIL PROTECTED]> wrote: > Hi, > > On Tue, 2007-24-07 at 15:26 -0700, Courtenay wrote: > > Does this work? > > > > ApplicationHelper.stub!(:controller).and_return mock('controller', > > :controller_name => 'foo') > > Sadly, no. Same result: > > undefined local

Re: [rspec-users] Mock or Stub strategy for validates_uniqueness_of

2007-07-24 Thread Daniel N
On 7/25/07, Mikel Lindsaar <[EMAIL PROTECTED]> wrote: There would be a different way. In the idea of "Only test the code you write" all you really need to spec is that you have set the right association, because activerecord has it's own tests to ensure the uniq call works. You can do this wit

Re: [rspec-users] Mock or Stub strategy for validates_uniqueness_of

2007-07-24 Thread Kyle Hargraves
Daniel N wrote: > On 7/25/07, Mikel Lindsaar <[EMAIL PROTECTED]> wrote: >> >> There would be a different way. >> >> In the idea of "Only test the code you write" all you really need to >> spec is that you have set the right association, because activerecord >> has it's own tests to ensure the uniq

Re: [rspec-users] Mock or Stub strategy for validates_uniqueness_of

2007-07-24 Thread Daniel N
On 7/25/07, Kyle Hargraves <[EMAIL PROTECTED]> wrote: Daniel N wrote: > On 7/25/07, Mikel Lindsaar <[EMAIL PROTECTED]> wrote: >> >> There would be a different way. >> >> In the idea of "Only test the code you write" all you really need to >> spec is that you have set the right association, becau

Re: [rspec-users] spec'ing helpers that use controller

2007-07-24 Thread Rick Tessner
Hi, This worked just fine. :) Thanks. On Tue, 2007-24-07 at 16:30 -0700, Courtenay wrote: > specing helpers just includes the module in your spec. > > So you can cheat like > > describe "Application Helper" do > helper_name :application > > def controller > @controller > end > >

Re: [rspec-users] Mock or Stub strategy for validates_uniqueness_of

2007-07-24 Thread Mikel Lindsaar
Kyle, That is a good point. We are after the behaviour, not the implementation. Regards Mikel On 7/25/07, Daniel N <[EMAIL PROTECTED]> wrote: > > > > On 7/25/07, Kyle Hargraves <[EMAIL PROTECTED]> wrote: > > Daniel N wrote: > > > On 7/25/07, Mikel Lindsaar <[EMAIL PROTECTED]> wrote: > > >> > >