Re: [rspec-users] Cucumber, more examples, tabular data input sets

2008-10-19 Thread Matt Wynne

On 18 Oct 2008, at 22:42, Ashley Moran wrote:



On Oct 18, 2008, at 9:51 pm, Zach Dennis wrote:


Given I login as Joe without the 'admin' privilege
When I GET /admin
Then I am notified that access was denied

More Examples:
| name | privilege | request_method | path| name |
| Joe  | admin | POST   | /invoices   | Joe  |
| Joe  | admin | PUT| /invoices/1 | Joe  |


How about just annotating them? eg

 Given I login as [name] Joe without the 'admin' privilege  
[missing_privilege]

 When I GET [request_method] /admin [path]
 Then I am notified that access was denied


I like this, and I agree with Joe that it's quite painful to have to
(a) include every substitutable step parameter in the table columns,  
even if it doesn't change in any scenario table row
(b) go hunting around in step definitions (or pretty console output  
looking for the underlines) to figure out which param is which


But I do also feel like it clutters up the scenario bit.

I wonder whether it might also work to have a different definition,  
like ScenarioTemplate: which doesn't actually run, but defines the  
skeleton into which the table values will be substituted. So Joe's  
example will work like this:


ScenarioTemplate: Non admins are rejected
Given I login as Joe without the '[privilege]' privilege
When I [request_method] /admin[path]
Then I am notified that access was denied

| privilege | request_method | path |
| Joe | GET | /admin |
| Joe | POST | /invoces/1 |

etc.

WDYT?

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


Re: [rspec-users] Mocks: expectations vs spying

2008-10-19 Thread Matt Wynne

On 18 Oct 2008, at 14:53, Pat Maddox wrote:


more first (and hopefully others will too).

Pat

[1] http://notahat.com/not_a_mock


Looks sweet - it will be in my first mock on Monday!

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


Re: [rspec-users] Running Cucumber with a Rails Rake task

2008-10-19 Thread Ben Emson
Zach Dennis wrote:
 To run all features you can run:
 
   rake features
 
 To run specific features you can do something like:
 
   script/cucumber --require features/steps features/path/to/my.feature
 
 If you want to run a particular scenario find out the line number of
 the first Given and run:
 
   script/cucumber --line 41 --require features/steps 
 features/path/to/my.feature
 
 Zach
 
 
 On Sat, Oct 18, 2008 at 4:33 PM, Ben Emson [EMAIL PROTECTED] wrote:
 demo Rake file works, but I'm not sure I've set it up correctly in my

 desc run stories

 file so that it will run all my stories?
 rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users

 
 
 
 --
 Zach Dennis
 http://www.continuousthinking.com
 http://www.mutuallyhuman.com


Thanks Aslak and Zach

I must apologise in my excitement I completely missed the Rails wiki 
section.
Thats just what I was looking for.  Thanks and keep up the good work.

BE...

-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Why @controller is nil error on loading fixtures in model?

2008-10-19 Thread Harry Bishop
Zach Dennis wrote:
 On Sat, Oct 18, 2008 at 6:10 PM, Harry Bishop [EMAIL PROTECTED] 
 wrote:
 '/../helpers/votes_spec_helper')

 but no change.

 I would appreciate some assistance here to get this off the ground.
 
 It's being you are calling put and I believe you want puts. The
 method put is a Rails testing method which tries to invoke a PUT
 http request on a given controller action. That is why you are getting
 @controller is nil.
 
 --
 Zach Dennis
 http://www.continuousthinking.com
 http://www.mutuallyhuman.com

yes that was the problem.  That d*** dyslexia again.
Thanks very much, as frustration had set in.
HR
-- 
Posted via http://www.ruby-forum.com/.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Surprising mock behavior

2008-10-19 Thread Zach Dennis
On Sun, Oct 19, 2008 at 1:34 AM, Mark Thomson [EMAIL PROTECTED] wrote:

 Zach Dennis wrote:

 I'm top posting... I wish I could inline post, but you provided a lot
 of generalizations for how you think things are working on your code,
 but you don't actually post concrete code (the should_receive and
 should_not_receive case you mentioned that wasn't acting like you'd
 expect). Perhaps this will help:

 * Mocks are not ordered by default.


 Yeah that's consistent with what I'm seeing. I mentioned ordering only
 because it was one of the things that came up in my mind as I was searching
 for a way to understand the different behaviors I was seeing.

 * If you want ordered message expectations on a mock you have to
 explicitly tell them to be ordered.


 Really, you can do that? I'm curious about how.

Checkout http://rspec.info/documentation/mocks/message_expectations.html

And look at the Ordering section.


 * You cannot enforce ordering across mocks.

 So without explicitly ordering, message expectations can be fulfilled
 in any order. For example the below will pass even though the
 expectation for 1 and 3 does not match the order in when the bar
 method is called:

file = Object.new
file.should_receive(:bar).with(1)
file.should_receive(:bar).with(3)

file.bar 3
file.bar 1



 Ok got that.

 Once a message expectation is fulfilled, if the object receives
 another message matching that expectation it will force it to fail.
 For example, the following would fail even though there are two
 expectations for bar to be called with 1, which match the two
 calls to file.bar:

file = Object.new
file.should_receive(:bar).with(1)
file.should_receive(:bar).with(1)

file.bar 1
file.bar 1


 This one kind of surprises me, but I understand your point.

 Using should_not_receive and should_receive on the same message gets
 tricky, because you can trick yourself into thinking the thing is
 passing when it shouldn't be. For example the below will fail because
 even though you call file.bar with 2, that matches the expectation
 that file.bar should not be called with 3:

file = Object.new
file.should_receive(:bar).with(1)
file.should_not_receive(:bar).with(3)

file.bar 1
file.bar 2


 Did you mean to say that will *not* fail since 2 will match not 3?

Yes, that's what I meant.

-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Surprising mock behavior

2008-10-19 Thread Pat Maddox
Can you please post an example of the spec and production code that
isn't behaving as you expect?

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


[rspec-users] Merb

2008-10-19 Thread Ashley Moran

Hi

Two questions:

Anyone using Merb here, and writing specs for it?  (I've just started  
tonight, so I'm figuring stuff out as I go along.)


And WDYAT of their spec extensions[1]?  Specifically their given

  given a item exists do
request(resource(:items), :method = POST,
  :params = { :item = {  }})
  end

  describe resource(:items) do

describe GET, :given = a item exists do
  before(:each) do
@response = request(resource(:items))
  end

  it has a list of items do
pending
@response.should have_xpath(//ul/li)
  end
end

  end

Have to say I was a bit surprised to learn they'd monkey-patched  
RSpec...


Ashley

[1] 
http://github.com/wycats/merb-core/tree/master/lib/merb-core/test/test_ext/rspec.rb


--
http://www.patchspace.co.uk/
http://aviewfromafar.net/

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


Re: [rspec-users] Merb

2008-10-19 Thread Ashley Moran


On Oct 19, 2008, at 9:43 pm, David Chelimsky wrote:


Well, in fairness to wycats, rspec doesn't really offer formal
extension points that would support this syntax, so he did the best he
could given what is available. We've had some discussion about this
and haven't landed anywhere firm yet.

My opinion is that rspec, as it stands right now, needs a bit of
internal cleanup before we start adding new features like that one.
Also, the way I'd like to see this go is that rspec exposes a formal
extension point - some sort of hook into pre and post-processing of
each example including any arguments it was given. Then the merb
extension could use a published API rather than monkey patching.



Ah, I understand now.  I didn't mean my comment in a negative way,  
just that Merb has a philosophy of simplicity and transparency, and  
monkey-patching is the Rails way to do things.  Hence my surprise.   
And spec code too... if anything's gonna make me nervous!


Is the Merb spec syntax (or something like it) something you'd like in  
the future?  (RSpec 2?)


Ashley

--
http://www.patchspace.co.uk/
http://aviewfromafar.net/

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


Re: [rspec-users] Merb

2008-10-19 Thread David Chelimsky
On Sun, Oct 19, 2008 at 4:11 PM, Ashley Moran
[EMAIL PROTECTED] wrote:

 On Oct 19, 2008, at 9:43 pm, David Chelimsky wrote:

 Well, in fairness to wycats, rspec doesn't really offer formal
 extension points that would support this syntax, so he did the best he
 could given what is available. We've had some discussion about this
 and haven't landed anywhere firm yet.

 My opinion is that rspec, as it stands right now, needs a bit of
 internal cleanup before we start adding new features like that one.
 Also, the way I'd like to see this go is that rspec exposes a formal
 extension point - some sort of hook into pre and post-processing of
 each example including any arguments it was given. Then the merb
 extension could use a published API rather than monkey patching.


 Ah, I understand now.  I didn't mean my comment in a negative way, just that
 Merb has a philosophy of simplicity and transparency, and monkey-patching is
 the Rails way to do things.  Hence my surprise.  And spec code too... if
 anything's gonna make me nervous!

 Is the Merb spec syntax (or something like it) something you'd like in the
 future?  (RSpec 2?)

Not sure about that yet. You can already accomplish the same thing
with a variety of existing structures and I think that this structure
brings up other questions like:

* how about a :when and :then?
* how does this impact the output?
* etc

However, I'm definitely interested in developing and committing to an
API that makes it easy to write extensions like this. Then wycats
could publish this as a separate extension gem, for example, and those
who like it can easily use it w/o concern for the fact that it is
monkey patching another library.



 Ashley

 --
 http://www.patchspace.co.uk/
 http://aviewfromafar.net/

 ___
 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] Merb

2008-10-19 Thread Ben Mabey

Caius Durling wrote:


On 19 Oct 2008, at 20:36, Ashley Moran wrote:

Anyone using Merb here, and writing specs for it?  (I've just started 
tonight, so I'm figuring stuff out as I go along.)


Funny you should post this, I picked up merb today as well (seeing as 
the API is finally frozen) and was thinking about posting to see if 
anyone else was.


You attempted to throw cucumber into the mix yet?


I used the told story runner with merb and I had no issues.  I haven't 
done any merb apps since cucumber but it looks like there is already a 
library to make using Cucumber in merb easy:


http://github.com/david/merb_cucumber/tree/master

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


Re: [rspec-users] Merb

2008-10-19 Thread Ashley Moran


On Oct 19, 2008, at 10:31 pm, Caius Durling wrote:

Funny you should post this, I picked up merb today as well (seeing  
as the API is finally frozen) and was thinking about posting to see  
if anyone else was.


You attempted to throw cucumber into the mix yet?



Of course!  :D

However, I'm using hand-rolled Celerity-based stuff, rather than the  
Webrat stuff in the generator.  So there's nothing merby about my  
cucumber files (well, file, right now), but then I like restricting  
Cucumber to talk over HTTP.


I've been taking notes, and hope to blog about the experience in the  
next week or two.


Ashley


--
http://www.patchspace.co.uk/
http://aviewfromafar.net/

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


Re: [rspec-users] RSpec vs Screw.Unit

2008-10-19 Thread Scott Taylor


On Oct 19, 2008, at 12:14 PM, Pat Maddox wrote:


Scott Taylor [EMAIL PROTECTED] writes:


On Oct 18, 2008, at 9:19 AM, Pat Maddox wrote:


Scott Taylor [EMAIL PROTECTED] writes:


As for #3, I'm
pretty sure that Ruby's method_missing allows one to raise an
exception easily.  Not sure what a Javascript mocking framework  
would

do in this case.


I'm not sure that I buy that this feature is very important.  Both
Javascript and Ruby blow up when you call a method that doesn't
exist on
it anyway.  What's the difference between Received unexpected  
message

'foo' and NoMethodError 'foo'?


Unless I'm mistaken, it's only when *another* method gets called on a
missing method that an error gets raised:


o = {};

Object

o.foo


You would need to do o.foo() to actually call the method.  That will
give you o.foo is undefined



Oops.  I feel like a tool.  Guess ruby syntax still invades my brain.




BTW, Pat - Have you still been working on integrating test spy into
rspec?


Nope, I found not_a_mock [1] and it works well.



Any plans to roll not_a_mock into rspec core?

Scott

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


Re: [rspec-users] Where is current_user?

2008-10-19 Thread Scott Taylor


On Oct 20, 2008, at 1:00 AM, Harry Bishop wrote:


Hi,
 I have a controller that uses the current_user attributes to  
determine

if a motion is showable.  I can see the motion track through from a
fixture to the show action, but not the current_user.  My rspec test  
is


describe MotionsController, handling GET /motions/1 do
 fixtures :people, :motions

 before(:each) do
   @current_user = people(:someuser)
   @request.session[:user_id] = @current_user.id
   @motion = motions(:four)
   controller.stub!(:logged_in?).and_return(true)
   controller.stub!(:retrieve_user).and_return(@current_user)
 end

 it should match motion and user do
   showable = controller.is_showable?(@current_user, @motion)
   puts ..Motion is showable = #{showable}  # is_showable? shows as
true.
 end

 def do_get
   get :show, :id = @motion.id
 end

 it should be successful do
   do_get
   response.should be_success
 end
end

In the MotionsController show action the motion is collected with the
params[:id] but the @current_user doesn't show.
The @current_user and @motion are supplied to is_showable? in the
controller for which they have attributes that are compared.
Any reason why @current_user isn't showing up in the show action?

If I take out the controller stubs in before(:each) then the redirect
from session shows as a 302 but the process doesn't proceed to the  
show

action.

A mock would require rebuilding the User model for all the checks done
in the controller and I am trying to avoid that by using a fixture
called from the database to test the true interaction between user and
motion.


Not necessarily.  Have you looked into using a null_object mock?

Scott

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