[rspec-users] Authenticating before tests

2007-09-13 Thread Luke Galea
Hi all,

I'm using Goldberg, an engine that provides roles based access  
control for my app. I need to login before I can do controller tests,  
but I can't find any examples of people doing this.

Could someone point me in the right direction?

I thought the simplest way would be to either call the login action  
from my other tests before(:all), but I can't seem to find how to  
call another controller from within the spec for a different  
controller. (Results in @controller is nil).

I've also tried setting session[:user] in before(:all), but session  
is nil at that point!

Any help would be greatly appreciated.

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


Re: [rspec-users] Authenticating before tests

2007-09-13 Thread Jarkko Laine

On 13.9.2007, at 15.25, Luke Galea wrote:


Hi all,

I'm using Goldberg, an engine that provides roles based access
control for my app. I need to login before I can do controller tests,
but I can't find any examples of people doing this.

Could someone point me in the right direction?


This is what we do:

in spec_helper.rb:

  include AuthenticatedTestHelper

  def login_as(user)
controller.send :current_user=, user
  end

Then, in a before(:all) block, I can say login_as(@user) with a user  
object. This assumes you're using restful_authentication (and should  
work with acts_as_authenticated as well).




I thought the simplest way would be to either call the login action
from my other tests before(:all), but I can't seem to find how to
call another controller from within the spec for a different
controller. (Results in @controller is nil).


You can't and shouldn't do that. Just find out how your particular  
authentication system determines the login and create a helper method  
like login_as above to simulate the login.


--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi




smime.p7s
Description: S/MIME cryptographic signature
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Checking out Rspec

2007-09-13 Thread Bret Pettichord
On 9/12/07, Scott Taylor <[EMAIL PROTECTED]> wrote:

> I have been having connection problems with rspec's rubyforge
> repository for a long time.  I'm running my own mirror if you want
> the subversion link (although the revision numbers are a little bit
> off).
>
> Generally, though, if you are having problems with this sort of thing
> on rubyforge, you should try contacting them directly (Rubyforge has
> it's own tracker).  They would know more about this stuff than the
> rspec project admins.


Thanks for your help. I have several projects hosted at Rubyforge (and have
contacted Tom for help on many occassions) but my first impression was that
this particular error was not a connection problem, but rather something
specific about the way the code was checked in. Apparently others are not
having this problem, so my next guess is that this is something specific to
Subclipse. I will install TortoisseSVN next and see what happens with that.
I would appreciate it if you could send me a link to your SVN mirror.

If, however, there was something specific about the error message that made
you think it really was a connection, let me know and I'll talk to Tom about
it. I ran into the same problem with the same file in three different
attempts to checkout or update.

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

Re: [rspec-users] Checking out Rspec

2007-09-13 Thread Jay Levitt
On 9/13/2007 9:43 AM, Bret Pettichord wrote:
> On 9/12/07, *Scott Taylor* <[EMAIL PROTECTED] 
> > wrote:
> 
> I have been having connection problems with rspec's rubyforge
> repository for a long time.  I'm running my own mirror if you want
> the subversion link (although the revision numbers are a little bit
> off).
> 
> Generally, though, if you are having problems with this sort of thing
> on rubyforge, you should try contacting them directly (Rubyforge has
> it's own tracker).  They would know more about this stuff than the
> rspec project admins.
> 
> 
> Thanks for your help. I have several projects hosted at Rubyforge (and 
> have contacted Tom for help on many occassions) but my first impression 
> was that this particular error was not a connection problem, but rather 
> something specific about the way the code was checked in. Apparently 
> others are not having this problem, so my next guess is that this is 
> something specific to Subclipse. I will install TortoisseSVN next and 
> see what happens with that. I would appreciate it if you could send me a 
> link to your SVN mirror.

Hmm, I just checked out RSpec on Subclipse last week w/no problems. 
What platform are you on, which SVN adapter, etc.?  I was using Mac OS X 
10.4.10, Eclipse 3.3, Subclipse 1.2.4, SVNKit.

Jay
> 
> If, however, there was something specific about the error message that 
> made you think it really was a connection, let me know and I'll talk to 
> Tom about it. I ran into the same problem with the same file in three 
> different attempts to checkout or update.
> 
> Bret
> 
> 
> 
> 
> ___
> 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] Authenticating before tests

2007-09-13 Thread sinclair bain
Hi!
Have you considered mocking / stubbing to test in isolation if that is
appropriate ?

sinclair

On 9/13/07, Luke Galea <[EMAIL PROTECTED]> wrote:
>
> Hi all,
>
> I'm using Goldberg, an engine that provides roles based access
> control for my app. I need to login before I can do controller tests,
> but I can't find any examples of people doing this.
>
> Could someone point me in the right direction?
>
> I thought the simplest way would be to either call the login action
> from my other tests before(:all), but I can't seem to find how to
> call another controller from within the spec for a different
> controller. (Results in @controller is nil).
>
> I've also tried setting session[:user] in before(:all), but session
> is nil at that point!
>
> Any help would be greatly appreciated.
>
> Thanks,
> Luke
> ___
> 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] Failing to raise an exception in a stub

2007-09-13 Thread Jarkko Laine
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,

@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/Sites/koulutusweb/app/controllers/clients_controller.rb: 
41:in `create'


The line #41 consists only of

@client.save!

I'm at a loss seeing where the wrong number of arguments is really  
happening because save! certainly shouldn't assume any args.  
Moreover, both cases work fine in the real app, so it seems to me  
something funky is happening when stubbing the method.


Anyone else stumbled upon anything similar?

Cheers,
//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi




smime.p7s
Description: S/MIME cryptographic signature
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Checking out Rspec

2007-09-13 Thread Bret Pettichord
>
> Hmm, I just checked out RSpec on Subclipse last week w/no problems.
> What platform are you on, which SVN adapter, etc.?  I was using Mac OS X
> 10.4.10, Eclipse 3.3, Subclipse 1.2.4, SVNKit.


I'm using Eclipse 3.3 on windows with Subclipse 1.2.3. I also reproduced the
problem using TortoisseSVN 1.4.5. I've reproduced it on two different
machines.

Just to clarify, are you all also checking out from
svn://rubyforge.org/var/svn/rspec/trunk and not from a subdirectory?

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

Re: [rspec-users] Authenticating before tests

2007-09-13 Thread Jarkko Laine


On 13.9.2007, at 19.52, sinclair bain wrote:


Hi!

Have you considered mocking / stubbing to test in isolation if that  
is appropriate ?


Right, my example was also assuming that you are using mocks for users.

//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi




smime.p7s
Description: S/MIME cryptographic signature
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Failing to raise an exception in a stub

2007-09-13 Thread aslak hellesoy
On 9/13/07, Jarkko Laine <[EMAIL PROTECTED]> wrote:
> 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,
>
>  @client.stub!(:save!).and_raise(ActiveRecord::RecordInvalid)
>

Passing a class only works if the new method takes 0 args. Otherwise
you have to pass an exception instance. ActiveRecord::RecordInvalid
takes one.

@client.stub!(:save!).and_raise(ActiveRecord::RecordInvalid.new(@client))

> 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/Sites/koulutusweb/app/controllers/clients_controller.rb:
> 41:in `create'
>
> The line #41 consists only of
>
>  @client.save!
>
> I'm at a loss seeing where the wrong number of arguments is really
> happening because save! certainly shouldn't assume any args.
> Moreover, both cases work fine in the real app, so it seems to me
> something funky is happening when stubbing the method.
>
> Anyone else stumbled upon anything similar?
>
> Cheers,
> //jarkko
>
> --
> Jarkko Laine
> http://jlaine.net
> http://dotherightthing.com
> http://www.railsecommerce.com
> http://odesign.fi
>
>
>
> ___
> 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] Philosophical questions

2007-09-13 Thread Pat Maddox
On 9/12/07, Evan David Light <[EMAIL PROTECTED]> wrote:
>  Disclaimer: The following are observations by a relatively new user (couple
> of weeks) of RSpec and not intended as RSpec trollbait.  Also, forgive me if
> similar topics have been discussed elsewhere on the mailing list.  I at
> least did the due diligence of a quick search.
>
>  That said...
>
>  I've been positively thrilled with RSpec for use outside of Rails.  It has
> been in my attempts to use it within Rails that I have begun to question
> whether and how it can buy me much more than Test::Unit.
>
>  I recently began using RSpec to drive the design, in BDD fashion, of a
> Rails app.  Believing that behavior is best measured from the user's
> experience, I started by writing a View spec.  I considered this a top-down
> approach.  Were I still using Test::Unit, I likely would have started in the
> same place that I usually do out of habit: the Model.
>
>  However, the more googling that I've done, the more that I noticed that
> most RSpec articles, where they addressed Rails, were primarily focused on
> the Model.  I began to wonder, "are people using RSpec much like people were
> using Test::Unit?"  I've seen that some people eschew View Specs.  However,
> in lieu of that, how does one spec the interface that should, in theory,
> drive the design of the application?
>
>  Ultimately, I'm left with similar perspective to Jordan's: View specs will
> be brittle.  They'll span multiple Behaviors as there will be at least one
> per action -- leading me to wonder if BDD, or at least RSpec, is necessarily
> the best way to try to spec the View.  However, Controllers and Models seem
> as though they would work reasonably well.
>
>  Can anyone recommend some approaches for tackling BDD starting from the
> View down?
>
> Thanks,
> Evan
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>

Hi Evan,

I think you have the right idea about approaching specification from
the user's viewpoint (or more appropriately, as David C said, business
value).  It just seems like you're not completely familiar with the
tools that RSpec provides.  Nothing wrong with that, because one of
the most important tools still hasn't been officially released!

View specs are for unit testing your view, not for exercising
functionality.  In fact they shouldn't do very much at all.  They
should be pretty simple...make sure that certain attributes from an
object are being displayed, perhaps how some of the markup is
structured, etc.  That can be brittle, and will become painfully so if
you specify too much.  You'll want to specify the bare minimum it
takes to get the job done.

Others have mentioned Story Runner, which is a new feature of RSpec.
I'm pretty jazzed about it, because it's a very lightweight tool for
acceptance tests.  The structure is clean, it just makes sense to me.
I wrote an introduction which you can find at
http://evang.eli.st/blog/2007/9/1/user-stories-with-rspec-s-story-runner.
 It also has links to some of Dan North's articles which are a great
resource for really getting BDD.

As far as tackling BDD from the top down...for me, it all starts with
a Story.  This can be a bit tough if you don't write user stories to
define features, and instead just get told "hey we should add this."
However I've found that writing an initial user story forces me to
really clarify what a feature means to our product.  Also Story Runner
makes it incredibly easy to share the stories with others.  If one of
our customers tells me something doesn't work right, but I think it
does, I can show him the story I wrote.  We've already resolved an
issue like this...I showed him the story, he said that he was making
different assumptions.  I coded those up into the story and off we
went.

I hope you check out Story Runner, it's a really cool tool.  If your
development philosophy is about creating business value, then it
should totally vibe with you.  From there you use the finer-grained
aspects of RSpec to achieve that business value with code that doesn't
drive you insane :)

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


Re: [rspec-users] Philosophical questions

2007-09-13 Thread David Chelimsky
On 9/13/07, Evan David Light <[EMAIL PROTECTED]> wrote:
> My immediate impression was Story == Use Case.

Story == User Story

User Stories are not the same thing as Use Cases. You may want to
google around for some writing on that.

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


Re: [rspec-users] Philosophical questions

2007-09-13 Thread Evan David Light
On Sep 13, 2007, at 6:10 PM, Pat Maddox wrote:

> On 9/12/07, Evan David Light <[EMAIL PROTECTED]> wrote:
>> ... (Evan's RSpec n00bish ramblings) ...

>> Thanks,
>> Evan
>>
>>
>
> Hi Evan,
>
> I think you have the right idea about approaching specification from
> the user's viewpoint (or more appropriately, as David C said, business
> value).  It just seems like you're not completely familiar with the
> tools that RSpec provides.  Nothing wrong with that, because one of
> the most important tools still hasn't been officially released!
>

Quite so.  Certainly not with RSpec-on-Rails at least.  I have been  
milling around the RDoc. in my spare moments and have written a few  
specs for a statistical analysis tool that I wrote recently.  Work  
has been  dragging me away from coding too much lately.  Fortunately,  
I've had this afternoon and have all of tomorrow to get my hands dirty.

> View specs are for unit testing your view, not for exercising
> functionality.  In fact they shouldn't do very much at all.  They
> should be pretty simple...make sure that certain attributes from an
> object are being displayed, perhaps how some of the markup is
> structured, etc.  That can be brittle, and will become painfully so if
> you specify too much.  You'll want to specify the bare minimum it
> takes to get the job done.
>

Understood.  Admittedly, I had not even seen a Rails Integration  
Test until I after I read a few posts on this list and did some  
googling.  I've been fortunate to be able to pick Ruby for my current  
project but I haven't had an excuse to develop a production Rails app  
until a few days ago.  I've only done a lot of tinkering at home for  
which I now wish that I had used TDD or BDD.  That said...

> Others have mentioned Story Runner, which is a new feature of RSpec.
> I'm pretty jazzed about it, because it's a very lightweight tool for
> acceptance tests.  The structure is clean, it just makes sense to me.
> I wrote an introduction which you can find at
> http://evang.eli.st/blog/2007/9/1/user-stories-with-rspec-s-story- 
> runner.
>  It also has links to some of Dan North's articles which are a great
> resource for really getting BDD.
>

I know!  I saw them both!  After reading David's messages from  
yesterday, I was inspired to checkout from trunk this afternoon,  
plowed through some of the spec for Story Runner,  and then some of  
the examples.  I love what I see.  My immediate impression was Story  
== Use Case.  That seems to be bear out the more that I looked at the  
RSpec for Story Runner and at the code samples.  In fact, I was just  
getting ready to dig into writing my first Story when I decided to  
pop over to the mailing list for a second.  Who needs to read an  
RDoc? ;-)

> As far as tackling BDD from the top down...for me, it all starts with
> a Story.

I can totally see that.  Use cases tend to proceed lower level  
requirements in the waterfall process (not that many of us are using  
this one anymore...).

> This can be a bit tough if you don't write user stories to
> define features, and instead just get told "hey we should add this."

Not necessarily.  Just as you say below, the Story lets you put meat  
on that skeleton of an idea.

> We've already resolved an
> issue like this...I showed him the story, he said that he was making
> different assumptions.  I coded those up into the story and off we
> went.
>

Very cool.

> I hope you check out Story Runner, it's a really cool tool.  If your
> development philosophy is about creating business value, then it
> should totally vibe with you.  From there you use the finer-grained
> aspects of RSpec to achieve that business value with code that doesn't
> drive you insane :)

Seriously, this is exactly the kind of thing that I was looking for  
when I mistakenly began playing with View specs.

Now I'm also going to have to "Storify" my personal Rails project  
when I get some spare time!

Thanks guys.  This looks like it will be very useful.  More as I dig  
in.

Evan Light
IMs (all): sleight42
http://evan.tiggerpalace.com



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


[rspec-users] Need help in View Spec

2007-09-13 Thread Shaker

Hello everyone:
  I am kind of puzzled in writing spec on view partials. I can not find much
information about the "should have_tag" syntax in Rspec. Can rspec test a
particular attribute of a tag (e.g. input tag)? Let me put an example here:
#../view/group/_index
  

  
I want to test the "onclick" attribute in the input tag, which ensure that
clicking the button will call the correct Javascript method. How should I
do?
  Great thanks for any help.
-- 
View this message in context: 
http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667395
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] Need help in View Spec

2007-09-13 Thread Shaker

Yes, I have gone through the documentation before, and I read the reference
of 'assert_select' as well. But I still can not figure out a way of testing
attributes in a tag. What I know is we can use:
  should have_tag("tag#id") or should have_tag("tag.class")
to select a tag, whereas I don't know how to select an attribute and test
it!
Another problem is the tag does not have id or class sometimes, does it mean
that is no way of selecting it?

David Chelimsky-2 wrote:
> 
> On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>> I can not find much
>> information about the "should have_tag" syntax in Rspec.
> 
> http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Matchers.html#M11
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667582
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] Need help in View Spec

2007-09-13 Thread David Chelimsky
On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>
> Yes, I have gone through the documentation before, and I read the reference
> of 'assert_select' as well. But I still can not figure out a way of testing
> attributes in a tag. What I know is we can use:
>   should have_tag("tag#id") or should have_tag("tag.class")
> to select a tag, whereas I don't know how to select an attribute and test
> it!

That's all covered in the assert_select docs. Here's a cheat sheet you
might find useful.

http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/cheat/assert_select.html

so you can do this:

response.should have_tag("form[action=?][method=post]", foo_path(@foo))

HTH





> Another problem is the tag does not have id or class sometimes, does it mean
> that is no way of selecting it?
>
> David Chelimsky-2 wrote:
> >
> > On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
> >> I can not find much
> >> information about the "should have_tag" syntax in Rspec.
> >
> > http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Matchers.html#M11
> > ___
> > rspec-users mailing list
> > rspec-users@rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
> >
>
> --
> View this message in context: 
> http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667582
> Sent from the rspec-users mailing list archive at Nabble.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] Need help in View Spec

2007-09-13 Thread David Chelimsky
On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
> I can not find much
> information about the "should have_tag" syntax in Rspec.

http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Matchers.html#M11
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Need help in View Spec

2007-09-13 Thread David Chelimsky
On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>
> Sorry, that's another spec caused the error. It is working. Thank you very
> much

Glad you got it worked out.

Cheers,
David

>
> Shaker wrote:
> >
> > Hello
> >   To spec the example I mentioned before, I wrote the spec as what you
> > suggested
> > #../view/group/index_spec.rb
> >   describe "/group/_index_spec" do
> > it "should call JS function when click the button" do
> >   render '/group/_index'
> >   response.should have_tag("input[onclick=?]", "update()")
> > end
> >   end
> > However, it generated an error "Expecting a selector as the first
> > argument". What is wrong?
> >
> > David Chelimsky-2 wrote:
> >>
> >> On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
> >>>
> >>> Yes, I have gone through the documentation before, and I read the
> >>> reference
> >>> of 'assert_select' as well. But I still can not figure out a way of
> >>> testing
> >>> attributes in a tag. What I know is we can use:
> >>>   should have_tag("tag#id") or should have_tag("tag.class")
> >>> to select a tag, whereas I don't know how to select an attribute and
> >>> test
> >>> it!
> >>
> >> That's all covered in the assert_select docs. Here's a cheat sheet you
> >> might find useful.
> >>
> >> http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/cheat/assert_select.html
> >>
> >> so you can do this:
> >>
> >> response.should have_tag("form[action=?][method=post]", foo_path(@foo))
> >>
> >> HTH
> >>
> >>
> >>
> >>
> >>
> >>> Another problem is the tag does not have id or class sometimes, does it
> >>> mean
> >>> that is no way of selecting it?
> >>>
> >>> David Chelimsky-2 wrote:
> >>> >
> >>> > On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
> >>> >> I can not find much
> >>> >> information about the "should have_tag" syntax in Rspec.
> >>> >
> >>> >
> >>> http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Matchers.html#M11
> >>> > ___
> >>> > rspec-users mailing list
> >>> > rspec-users@rubyforge.org
> >>> > http://rubyforge.org/mailman/listinfo/rspec-users
> >>> >
> >>> >
> >>>
> >>> --
> >>> View this message in context:
> >>> http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667582
> >>> Sent from the rspec-users mailing list archive at Nabble.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
> >>
> >>
> >
> >
>
> --
> View this message in context: 
> http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667734
> Sent from the rspec-users mailing list archive at Nabble.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] Need help in View Spec

2007-09-13 Thread Shaker

Sorry, that's another spec caused the error. It is working. Thank you very
much

Shaker wrote:
> 
> Hello
>   To spec the example I mentioned before, I wrote the spec as what you
> suggested
> #../view/group/index_spec.rb
>   describe "/group/_index_spec" do
> it "should call JS function when click the button" do
>   render '/group/_index'
>   response.should have_tag("input[onclick=?]", "update()")
> end
>   end
> However, it generated an error "Expecting a selector as the first
> argument". What is wrong?
> 
> David Chelimsky-2 wrote:
>> 
>> On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>>>
>>> Yes, I have gone through the documentation before, and I read the
>>> reference
>>> of 'assert_select' as well. But I still can not figure out a way of
>>> testing
>>> attributes in a tag. What I know is we can use:
>>>   should have_tag("tag#id") or should have_tag("tag.class")
>>> to select a tag, whereas I don't know how to select an attribute and
>>> test
>>> it!
>> 
>> That's all covered in the assert_select docs. Here's a cheat sheet you
>> might find useful.
>> 
>> http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/cheat/assert_select.html
>> 
>> so you can do this:
>> 
>> response.should have_tag("form[action=?][method=post]", foo_path(@foo))
>> 
>> HTH
>> 
>> 
>> 
>> 
>> 
>>> Another problem is the tag does not have id or class sometimes, does it
>>> mean
>>> that is no way of selecting it?
>>>
>>> David Chelimsky-2 wrote:
>>> >
>>> > On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>>> >> I can not find much
>>> >> information about the "should have_tag" syntax in Rspec.
>>> >
>>> >
>>> http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Matchers.html#M11
>>> > ___
>>> > rspec-users mailing list
>>> > rspec-users@rubyforge.org
>>> > http://rubyforge.org/mailman/listinfo/rspec-users
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667582
>>> Sent from the rspec-users mailing list archive at Nabble.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
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667734
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] Need help in View Spec

2007-09-13 Thread Shaker

Hello
  To spec the example I mentioned before, I wrote the spec as what you
suggested
#../view/group/index_spec.rb
  describe "/group/_index_spec" do
it "should call JS function when click the button" do
  render '/group/_index'
  response.should have_tag("input[onclick=?]", "update()")
end
  end
However, it generated an error "Expecting a selector as the first argument".
What is wrong?

David Chelimsky-2 wrote:
> 
> On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>>
>> Yes, I have gone through the documentation before, and I read the
>> reference
>> of 'assert_select' as well. But I still can not figure out a way of
>> testing
>> attributes in a tag. What I know is we can use:
>>   should have_tag("tag#id") or should have_tag("tag.class")
>> to select a tag, whereas I don't know how to select an attribute and test
>> it!
> 
> That's all covered in the assert_select docs. Here's a cheat sheet you
> might find useful.
> 
> http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/cheat/assert_select.html
> 
> so you can do this:
> 
> response.should have_tag("form[action=?][method=post]", foo_path(@foo))
> 
> HTH
> 
> 
> 
> 
> 
>> Another problem is the tag does not have id or class sometimes, does it
>> mean
>> that is no way of selecting it?
>>
>> David Chelimsky-2 wrote:
>> >
>> > On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>> >> I can not find much
>> >> information about the "should have_tag" syntax in Rspec.
>> >
>> >
>> http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Matchers.html#M11
>> > ___
>> > rspec-users mailing list
>> > rspec-users@rubyforge.org
>> > http://rubyforge.org/mailman/listinfo/rspec-users
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667582
>> Sent from the rspec-users mailing list archive at Nabble.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
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667709
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] Failing to raise an exception in a stub

2007-09-13 Thread Jarkko Laine

On 13.9.2007, at 23.29, aslak hellesoy wrote:


On 9/13/07, Jarkko Laine <[EMAIL PROTECTED]> wrote:

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,

 @client.stub!(:save!).and_raise(ActiveRecord::RecordInvalid)



Passing a class only works if the new method takes 0 args. Otherwise
you have to pass an exception instance. ActiveRecord::RecordInvalid
takes one.

@client.stub!(:save!).and_raise(ActiveRecord::RecordInvalid.new 
(@client))


Cheers, that was it!

//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi




smime.p7s
Description: S/MIME cryptographic signature
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Philosophical questions

2007-09-13 Thread Jarkko Laine

On 14.9.2007, at 1.10, Pat Maddox wrote:

Others have mentioned Story Runner, which is a new feature of RSpec.
I'm pretty jazzed about it, because it's a very lightweight tool for
acceptance tests.  The structure is clean, it just makes sense to me.
I wrote an introduction which you can find at
http://evang.eli.st/blog/2007/9/1/user-stories-with-rspec-s-story- 
runner.

 It also has links to some of Dan North's articles which are a great
resource for really getting BDD.


+1 for Story Runner. I just installed it on a project for a client  
that were using controller specs heavily for end-to-end stuff. Even  
on an app running on Rails 1.2, the rspec trunk installed flawlessly  
with some minimal changes to the existing spec code. From what I  
learned, Story Runner is already highly usable even though it's not  
officially out.


//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi




smime.p7s
Description: S/MIME cryptographic signature
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users