Re: [rspec-users] params are making my "should redirect_to" test fail - why??
Hi David - thanks for replying. The literal doesn't work either, because of all the params at the end, and i don't have named routes in this old, non-restful app. I see your point about the hash...is there any way to get the redirected-to url from 'response' and test against that? Then i could split it at "?" to ignore the params. (I'd rather not include the specific params in this test since i really just want to know about where it's redirected to). So, ideally i could do something like this - response.url.split("?").first.should eql(" http://test.host/admin/users/batch_saved";) I've been looking for documentation for methods for the response object, to get the url, but i can't find any in the api docs (i'm probably just looking in the wrong place). I can see the url data in the object but it's private. thanks max On 13/02/2008, David Chelimsky <[EMAIL PROTECTED]> wrote: > > On Feb 13, 2008 12:26 PM, Max Williams <[EMAIL PROTECTED]> > wrote: > > > > I'm testing a controller action that redirects to a different > action/view, > > sending through some params. In my test, i'm only specifying the > controller > > and action that it should redirect to, but the additional params are > making > > it fail! Here's my test: > > > > it "should redirect to batch_saved after completing batch_save" do > > post 'batch_save', @params > > response.should redirect_to(:controller => 'admin/users', :action => > > 'batch_saved') > > end > > > > and here's the failure report: > > > > 'Admin::UserController When logged in as an admin level user should > redirect > > to batch_saved after batch_save' FAILED > > expected redirect to {:controller=>"admin/users", > :action=>"batch_saved"}, > > got redirect to > > " > http://test.host/admin/users/batch_saved?music_service_id=1&new_users%5B%5D%5Bemail%5D=mark%40zadeup.com&new_users%5B%5D%5Bfirstname%5D=Mark&new_users%5B%5D%5Bmusic_service_id%5D=1&new_users%5B%5D%5Bschool%5D=&new_users%5B%5D%5Bsurname%5D=Madeup > " > > > > Now, i would expect that since i'm just specifying a controller and > action, > > and we redirect to them, that the test would pass. But the params are > > breaking it (I know this because i changed the controller action to not > send > > params through at all and the test passed). How do i do the test so > that it > > doesn't care about the params? > > > When you use a hash it checks the whole hash, so this is the expected > behaviour. > > You can either used a named route (if you've got one available) or a > String literal: > > response.should redirect_to(admin_users_batch_saved) > response.should redirect_to('/admin/users/batch_saved') > > Based on Jay Field's latest advice > (http://blog.jayfields.com/2008/02/testing-expect-literals.html) you > may want to consider the literal. > > HTH, > David > > > > > > > > -- > > > View this message in context: > http://www.nabble.com/params-are-making-my-%22should-redirect_to%22-test-fail---why---tp15460582p15460582.html > > 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 > ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] params are making my "should redirect_to" test fail - why??
On 2/14/08, Max Williams <[EMAIL PROTECTED]> wrote: > Hi David - thanks for replying. The literal doesn't work either, because of > all the params at the end, and i don't have named routes in this old, > non-restful app. I see your point about the hash...is there any way to get > the redirected-to url from 'response' and test against that? Then i could > split it at "?" to ignore the params. (I'd rather not include the specific > params in this test since i really just want to know about where it's > redirected to). > > So, ideally i could do something like this - > > response.url.split("?").first.should > eql("http://test.host/admin/users/batch_saved";) > > I've been looking for documentation for methods for the response object, to > get the url, but i can't find any in the api docs (i'm probably just looking > in the wrong place). I can see the url data in the object but it's private. Well the RedirectTo matcher gets it using response.redirect_url I'd probably write the check as response.should be_redirect response.redirect_url.should match(%r{^http://test.host/admin/users/batch_saved(\?|$)}) -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] params are making my "should redirect_to" test fail - why??
perfect - that's the method i was looking for. Thanks! On 14/02/2008, Rick DeNatale <[EMAIL PROTECTED]> wrote: > > On 2/14/08, Max Williams <[EMAIL PROTECTED]> wrote: > > Hi David - thanks for replying. The literal doesn't work either, > because of > > all the params at the end, and i don't have named routes in this old, > > non-restful app. I see your point about the hash...is there any way to > get > > the redirected-to url from 'response' and test against that? Then i > could > > split it at "?" to ignore the params. (I'd rather not include the > specific > > params in this test since i really just want to know about where it's > > redirected to). > > > > So, ideally i could do something like this - > > > > response.url.split("?").first.should > > eql("http://test.host/admin/users/batch_saved";) > > > > I've been looking for documentation for methods for the response > object, to > > get the url, but i can't find any in the api docs (i'm probably just > looking > > in the wrong place). I can see the url data in the object but it's > private. > > > Well the RedirectTo matcher gets it using > > response.redirect_url > > I'd probably write the check as > >response.should be_redirect >response.redirect_url.should > match(%r{^http://test.host/admin/users/batch_saved(\?|$)}) > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.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] params are making my "should redirect_to" test fail - why??
On Thu, Feb 14, 2008 at 8:22 AM, Rick DeNatale <[EMAIL PROTECTED]> wrote: > On 2/14/08, Max Williams <[EMAIL PROTECTED]> wrote: > > Hi David - thanks for replying. The literal doesn't work either, because > of > > all the params at the end, and i don't have named routes in this old, > > non-restful app. I see your point about the hash...is there any way to get > > the redirected-to url from 'response' and test against that? Then i could > > split it at "?" to ignore the params. (I'd rather not include the specific > > params in this test since i really just want to know about where it's > > redirected to). > > > > So, ideally i could do something like this - > > > > response.url.split("?").first.should > > eql("http://test.host/admin/users/batch_saved";) > > > > I've been looking for documentation for methods for the response object, > to > > get the url, but i can't find any in the api docs (i'm probably just > looking > > in the wrong place). I can see the url data in the object but it's > private. > > Well the RedirectTo matcher gets it using > > response.redirect_url > > I'd probably write the check as > >response.should be_redirect >response.redirect_url.should > match(%r{^http://test.host/admin/users/batch_saved(\?|$)}) That seems reasonable given what is offered. What do you guys think of a new matcher named redirect_with: response.should redirect_with(:controller => 'admin/users', :action => 'batch_saved') This would let you express exactly what you want and only accept a Hash and only match those present in the expectation, ignoring anything else in the Hash. I don't have the cycles to add this anytime soon, so if you like the idea, feel free to submit a patch to the tracker. Cheers, David > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.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] params are making my "should redirect_to" test fail - why??
On 2/14/08, David Chelimsky <[EMAIL PROTECTED]> wrote: > On Thu, Feb 14, 2008 at 8:22 AM, Rick DeNatale <[EMAIL PROTECTED]> wrote: > > On 2/14/08, Max Williams <[EMAIL PROTECTED]> wrote: > > > I've been looking for documentation for methods for the response > object, to > > > get the url, but i can't find any in the api docs (i'm probably just > looking > > > in the wrong place). I can see the url data in the object but it's > private. > > > > Well the RedirectTo matcher gets it using > > > > response.redirect_url > > > > I'd probably write the check as > > > >response.should be_redirect > >response.redirect_url.should > > match(%r{^http://test.host/admin/users/batch_saved(\?|$)}) > > > That seems reasonable given what is offered. > > What do you guys think of a new matcher named redirect_with: > > response.should redirect_with(:controller => 'admin/users', :action => > 'batch_saved') > > This would let you express exactly what you want and only accept a > Hash and only match those present in the expectation, ignoring > anything else in the Hash. > > I don't have the cycles to add this anytime soon, so if you like the > idea, feel free to submit a patch to the tracker. I'd be happy to do that, although I'm not entirely convinced that redirect_with is the right name, not that I've got a better alternative. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] specdoc and taskpaper
Hello there, I was wondering if anyone had looked at taskpaper? [1] They've got a vaguely yaml inspired format for todo lists. It reminded me of specdocs. I wonder how much work it would be to convert or build it in? Anyone else interested in seeing this? http:// Joseph Holsten .com [1] http://hogbaysoftware.com/products/taskpaper ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] params are making my "should redirect_to" test fail - why??
On Thu, Feb 14, 2008 at 9:48 AM, Rick DeNatale <[EMAIL PROTECTED]> wrote: > On 2/14/08, David Chelimsky <[EMAIL PROTECTED]> wrote: > > On Thu, Feb 14, 2008 at 8:22 AM, Rick DeNatale <[EMAIL PROTECTED]> wrote: > > > On 2/14/08, Max Williams <[EMAIL PROTECTED]> wrote: > > > > > > I've been looking for documentation for methods for the response > > object, to > > > > get the url, but i can't find any in the api docs (i'm probably just > looking > > > > in the wrong place). I can see the url data in the object but it's > private. > > > > > > Well the RedirectTo matcher gets it using > > > > > > response.redirect_url > > > > > > I'd probably write the check as > > > > > >response.should be_redirect > > >response.redirect_url.should > > > match(%r{^http://test.host/admin/users/batch_saved(\?|$)}) > > > > > > That seems reasonable given what is offered. > > > > What do you guys think of a new matcher named redirect_with: > > > > response.should redirect_with(:controller => 'admin/users', :action => > > 'batch_saved') > > > > This would let you express exactly what you want and only accept a > > Hash and only match those present in the expectation, ignoring > > anything else in the Hash. > > > > I don't have the cycles to add this anytime soon, so if you like the > > idea, feel free to submit a patch to the tracker. > > I'd be happy to do that, although I'm not entirely convinced that > redirect_with is the right name, not that I've got a better > alternative. redirect_with_options? How about something added to the existing call? response.should redirect_to(:controller => 'foo', :action => 'bar').ignoring_other_options Or something like that? > > -- > > > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.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] params are making my "should redirect_to" test fail - why??
On 2/14/08, David Chelimsky <[EMAIL PROTECTED]> wrote: > On Thu, Feb 14, 2008 at 9:48 AM, Rick DeNatale <[EMAIL PROTECTED]> wrote: > > On 2/14/08, David Chelimsky <[EMAIL PROTECTED]> wrote: > > > On Thu, Feb 14, 2008 at 8:22 AM, Rick DeNatale <[EMAIL PROTECTED]> > wrote: > > > I don't have the cycles to add this anytime soon, so if you like the > > > idea, feel free to submit a patch to the tracker. > > > > I'd be happy to do that, although I'm not entirely convinced that > > redirect_with is the right name, not that I've got a better > > alternative. > > > redirect_with_options? I think I like that. > How about something added to the existing call? > > response.should redirect_to(:controller => 'foo', :action => > 'bar').ignoring_other_options This seems too wordy. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] params are making my "should redirect_to" test fail - why??
I'm new to rspec (and coding in general) but would it break a lot of people's tests if redirect_to was changed to do this by default? It's what i expected it to do, personally, that is to pass if the given :action and :controller match up. If i pass a url string, and it's missing the params, then it seems fair that it should fail, but if for example i just specify a controller, and that controller is called (with any action) i'd expect it to pass as well. Like i say i'm a newb with no idea of the impact of this to existing tests :) On 14/02/2008, Rick DeNatale <[EMAIL PROTECTED]> wrote: > > On 2/14/08, David Chelimsky <[EMAIL PROTECTED]> wrote: > > On Thu, Feb 14, 2008 at 9:48 AM, Rick DeNatale <[EMAIL PROTECTED]> > wrote: > > > On 2/14/08, David Chelimsky <[EMAIL PROTECTED]> wrote: > > > > On Thu, Feb 14, 2008 at 8:22 AM, Rick DeNatale < > [EMAIL PROTECTED]> wrote: > > > > > I don't have the cycles to add this anytime soon, so if you like > the > > > > idea, feel free to submit a patch to the tracker. > > > > > > I'd be happy to do that, although I'm not entirely convinced that > > > redirect_with is the right name, not that I've got a better > > > alternative. > > > > > > redirect_with_options? > > > I think I like that. > > > > > How about something added to the existing call? > > > > response.should redirect_to(:controller => 'foo', :action => > > 'bar').ignoring_other_options > > > This seems too wordy. > > > > -- > > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.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] params are making my "should redirect_to" test fail - why??
On Thu, Feb 14, 2008 at 10:16 AM, Max Williams <[EMAIL PROTECTED]> wrote: > I'm new to rspec (and coding in general) but would it break a lot of > people's tests if redirect_to was changed to do this by default? It's what > i expected it to do, personally, that is to pass if the given :action and > :controller match up. If i pass a url string, and it's missing the params, > then it seems fair that it should fail, but if for example i just specify a > controller, and that controller is called (with any action) i'd expect it to > pass as well. > > Like i say i'm a newb with no idea of the impact of this to existing tests > :) It is conceivable that existing examples could break, but the docs do set out the same expectation that you have. Can you file a bug at http://rspec.lighthouseapp.com so we can get it in the queue? > On 14/02/2008, Rick DeNatale <[EMAIL PROTECTED]> wrote: > > On 2/14/08, David Chelimsky <[EMAIL PROTECTED]> wrote: > > > On Thu, Feb 14, 2008 at 9:48 AM, Rick DeNatale <[EMAIL PROTECTED]> > wrote: > > > > On 2/14/08, David Chelimsky <[EMAIL PROTECTED]> wrote: > > > > > On Thu, Feb 14, 2008 at 8:22 AM, Rick DeNatale > <[EMAIL PROTECTED]> wrote: > > > > > > > I don't have the cycles to add this anytime soon, so if you like > the > > > > > idea, feel free to submit a patch to the tracker. > > > > > > > > I'd be happy to do that, although I'm not entirely convinced that > > > > redirect_with is the right name, not that I've got a better > > > > alternative. > > > > > > > > > redirect_with_options? > > > > > > I think I like that. > > > > > > > > > How about something added to the existing call? > > > > > > response.should redirect_to(:controller => 'foo', :action => > > > 'bar').ignoring_other_options > > > > > > This seems too wordy. > > > > > > > > -- > > > > Rick DeNatale > > > > My blog on Ruby > > http://talklikeaduck.denhaven2.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 > ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] params are making my "should redirect_to" test fail - why??
On Thu, Feb 14, 2008 at 10:32 AM, David Chelimsky <[EMAIL PROTECTED]> wrote: > On Thu, Feb 14, 2008 at 10:16 AM, Max Williams > > <[EMAIL PROTECTED]> wrote: > > > I'm new to rspec (and coding in general) but would it break a lot of > > people's tests if redirect_to was changed to do this by default? It's what > > i expected it to do, personally, that is to pass if the given :action and > > :controller match up. If i pass a url string, and it's missing the params, > > then it seems fair that it should fail, but if for example i just specify a > > controller, and that controller is called (with any action) i'd expect it > to > > pass as well. > > > > Like i say i'm a newb with no idea of the impact of this to existing tests > > :) > > It is conceivable that existing examples could break, but the docs do > set out the same expectation that you have. > > Can you file a bug at http://rspec.lighthouseapp.com so we can get it > in the queue? I guess I'll hold off on the patch then. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] How to mock an association
I don't know exactly how you're using the code, but validates_presence_of :user_id seems redundant. If you've setup a relationship from Group to User then Active Record will be enforcing that validation for you. Just a thought ... Other than that you would probably do (without seeing any of your code): group = mock_model(Group, :to_param => 1) user = mock_model(User, :to_param => 1) group.stub!(:user).and_return(user) On Mon, Feb 11, 2008 at 8:21 AM, Edvard Majakari <[EMAIL PROTECTED]> wrote: > On Feb 11, 2008 1:43 PM, Wes Shaddix <[EMAIL PROTECTED]> wrote: > > I've got a "group" model that has a user_id attribute and a > > validates_existence_of :user and validates_presence_of :user_id > > validations. What method(s) do I need to stub on the User mock to > > intercept those validation calls? My goal is to isolate the Group model > > from the User model. > > See http://www.ruby-forum.com/topic/138342 > > and http://tersesystems.com/post/9700067.jhtml > > Obvious 'rails mocking associations' seemed to work for me, unless I > misunderstood the question. > > Of course, you could just stub 'valid?' for any AR object as well. > -- > "One day, when he was naughty, Mr Bunnsy looked over the hedge into > Farmer Fred's field and it was full of fresh green lettuces. Mr > Bunnsy, however, was not full of lettuces. This did not seem fair." > -- Terry Pratchett, Mr. Bunnsy Has An Adventure > ___ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Bryan Ray http://www.bryanray.net "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] Failed specs spike autotest
I'm getting some weird behavior. I'm currently running on trunk rspec/ rails, with 3.9.1 autotest. If a all tests succeed or are pending, autotest just sits there dutifully with the blinking cursor. If an example fails, it will take a few seconds, and pop up this line: /usr/bin/ruby1.8 -S script/spec -O spec/spec.opts script/spec Once that comes up, the cpu spikes. Autotest no longer acknowledges file changes. The only thing that can be done is to kill autotest. Here's my script/spec file if it's of any use: http://pastebin.com/m4c1d212a Please let me know if there's any more information I can provide. Thanks, Steve ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] specdoc and taskpaper
I use task paper and love it. Definitely the fastest way to throw in todo items. I wouldn't call the format yaml-ish though. Here's an example: This is a project: - This is a task @done - Another Task @context Another Project: - Task again Plain text Words followed by a colon are a project. Words following a hyphen are a task. The @context following a task sets it's context. @done means it's done. Any other words are plain text. I've been thinking of writing a todo app that had an export to taskpaper function. On 14/02/2008, at 11:44 PM, Joseph Anthony Pasquale Holsten wrote: Hello there, I was wondering if anyone had looked at taskpaper? [1] They've got a vaguely yaml inspired format for todo lists. It reminded me of specdocs. I wonder how much work it would be to convert or build it in? Anyone else interested in seeing this? http:// Joseph Holsten .com [1] http://hogbaysoftware.com/products/taskpaper ___ 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] Failed specs spike autotest
On Thu, Feb 14, 2008 at 3:37 PM, Steve <[EMAIL PROTECTED]> wrote: > I'm getting some weird behavior. I'm currently running on trunk rspec/ > rails, with 3.9.1 autotest. If a all tests succeed or are pending, > autotest just sits there dutifully with the blinking cursor. If an > example fails, it will take a few seconds, and pop up this line: > > /usr/bin/ruby1.8 -S script/spec -O spec/spec.opts script/spec > > Once that comes up, the cpu spikes. Autotest no longer acknowledges file > changes. The only thing that can be done is to kill autotest. Here's my > script/spec file if it's of any use: > > http://pastebin.com/m4c1d212a > > Please let me know if there's any more information I can provide. > > Thanks, > Steve Same thing happening here, though I didn't recognize that it's only after failures. The problem continues whether I use .autotest files or not. This is on a Rails 2.0.2 project, with rspec+rspec_on_rails r3306 in vendor/plugins, and ZenTest 3.9.1 installed as a gem. Kyle ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] Loosing params and request info in 'if' statements
Hi, I have been a bad TDD developer and developed before testing. My code is working fine, but I have been writing tests because it is the right thing to do. I am running into trouble with some controller methods that are saved in a separate lib module and included in the application.rb file. I started out specing the methods from one of the controller specs and then when all went well I moved them into a separate file and made the description shared. This seemed to be working until I started testing a completely separate set of method. Here is the code: The specs: # shared_member_restriction_spec.rb describe "MemberRestriction", :shared => true do before(:each) do params[:username] = "some_user" params[:password] = "password" request.request_uri = "members/" + controller.controller_name end describe "authenticate_if_in_members" do it "should call authenticate_if_in_members" do controller.should_receive(:authenticate_if_in_members) get :index end it "should call authenticate_member" do controller.should_receive(:authenticate_member) get :index end end end # episode_controller_spec.rb require File.dirname(__FILE__) + '/shared_member_restriction_spec' describe EpisodesController do it_should_behave_like "MemberRestriction" # ... end And the lib module: module MemberRestriction def authenticate_if_in_members if request.request_uri.include? "members/" authenticate_member bounce_if_membership_not_in_collection end end # ... end Finally the episode controller code: class EpisodesController < ApplicationController before_filter :authenticate_if_in_members # ... end The spec "should call authenticate_member" is failing like so: Spec::Mocks::MockExpectationError in 'EpisodesController authenticate_if_in_members should call authenticate_member' Mock 'EpisodesController' expected :authenticate_member with (any args) once, but received it 0 times I thought maybe the problem was that really I hadn't gotten these specs setup correctly for sharing, so I tried moving them back into the episode controller spec. No luck. Then I thought that maybe this was a bug with the version of rspec/autotest. I upgraded them both yesterday to the most recent version. I ran into a similar problem testing a different module. I had some params and a ruby statement that said something like User.authenticate(params[:user], params[:password]) if params[:user] and params[:password] The error that I got said that params was nil and therefore nil.[] wasn't a kosher ruby request. The if statement was redundant and so I took it out, at which point the params were not nil and everything worked according to plan. This was another situation where the code ran fine, but the tests were coughing on an if statement. I am honestly fuzzy about at what point rspec is setting the http head variables, and how everything works, so please let me know if I am doing something terribly or subtly wrong. I think it is my confusion about the controller setup process that makes me avoid BDD when it comes to my controllers, and delight in it when it comes to my models. Thanks ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Failed specs spike autotest
> Same thing happening here, though I didn't recognize that it's only > after failures. The problem continues whether I use .autotest files or > not. > > This is on a Rails 2.0.2 project, with rspec+rspec_on_rails r3306 in > vendor/plugins, and ZenTest 3.9.1 installed as a gem. I got this too, but didn't bother to find out where and how script/ spec would sneak into the list of files to test. I got this even if i explicitly exclude the file in my .autotest. The quick and dirty thing I did was: def make_test_cmd(files_to_test) return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.select { |i| i != 'script/spec' }.join(' ')}" end in vendor/plugins/rspec/lib/autotest/rspec.rb Regards, Kamal ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Failed specs spike autotest
On Thu, Feb 14, 2008 at 7:57 PM, Kamal Fariz <[EMAIL PROTECTED]> wrote: > > Same thing happening here, though I didn't recognize that it's only > > after failures. The problem continues whether I use .autotest files or > > not. > > > > This is on a Rails 2.0.2 project, with rspec+rspec_on_rails r3306 in > > vendor/plugins, and ZenTest 3.9.1 installed as a gem. > > > I got this too, but didn't bother to find out where and how script/ > spec would sneak into the list of files to test. I got this even if i > explicitly exclude the file in my .autotest. > > The quick and dirty thing I did was: > >def make_test_cmd(files_to_test) > return "#{ruby} -S #{spec_command} #{add_options_if_present} > #{files_to_test.keys.flatten.select { |i| i != 'script/spec' }.join(' > ')}" >end > > in vendor/plugins/rspec/lib/autotest/rspec.rb Thanks for the workaround. Looking into fixing this for real. > > Regards, > Kamal > > > > ___ > 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] Spec'ing Rails request.env params
I have an internal system that has a rails controller action that needs to behave differently based on browser type reported by request.env['HTTP_USER_AGENT'] But I can't find a way to stub! mock or set this setting from within a spec. Looked through Test::Unit and can't find a straight forward way in there either. Anyone had any luck with this? Mikel ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Spec'ing Rails request.env params
On Thu, Feb 14, 2008 at 6:45 PM, Mikel Lindsaar <[EMAIL PROTECTED]> wrote: > I have an internal system that has a rails controller action that > needs to behave differently based on browser type reported by > request.env['HTTP_USER_AGENT'] > > But I can't find a way to stub! mock or set this setting from within a spec. > > Looked through Test::Unit and can't find a straight forward way in there > either. > > Anyone had any luck with this? > > Mikel > ___ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I think you can just set it before making a request... request.env['HTTP_USER_AGENT'] = 'mozilla blah blah' get :new I've never had to do it before, but I just tried it and it seems to work. Pat ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Spec'ing Rails request.env params
On Fri, Feb 15, 2008 at 2:52 PM, Pat Maddox <[EMAIL PROTECTED]> wrote: > On Thu, Feb 14, 2008 at 6:45 PM, Mikel Lindsaar <[EMAIL PROTECTED]> wrote: > > I have an internal system that has a rails controller action that > > needs to behave differently based on browser type reported by > > request.env['HTTP_USER_AGENT'] > > > > But I can't find a way to stub! mock or set this setting from within a > spec. > I think you can just set it before making a request... > request.env['HTTP_USER_AGENT'] = 'mozilla blah blah' > get :new > I've never had to do it before, but I just tried it and it seems to work. Thanks Pat, it can't be that easy... I am _SURE_ I tried that... In fact, I think it was the first thing I tried... maybe I had a typo and thought "OK, that doesn't work, must be something else..." - don't you _hate_ that ? :D I'll try it out :) Thanks Mikel ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Failed specs spike autotest
On Fri, 15 Feb 2008 08:57:32 +0800, Kamal Fariz wrote: > > I got this too, but didn't bother to find out where and how script/ spec > would sneak into the list of files to test. I got this even if i > explicitly exclude the file in my .autotest. > > The quick and dirty thing I did was: > >def make_test_cmd(files_to_test) > return "#{ruby} -S #{spec_command} #{add_options_if_present} > #{files_to_test.keys.flatten.select { |i| i != 'script/spec' }.join(' > ')}" >end > > in vendor/plugins/rspec/lib/autotest/rspec.rb Is perhaps something else required? If I put this in autotest just keeps running all of my specs repeatedly. It doesn't wait for a file change to signal it to try running some explicit spec again. It does put out the first line minus the script/spec at the end before launching into all of that. I think it then thinks that perhaps the broken specs are fixed, so that's why it then tries to run all of the specs again. Finished in 15.703733 seconds 398 examples, 1 failure, 1 pending /usr/bin/ruby1.8 -S script/spec -O spec/spec.opts /usr/bin/ruby1.8 -S script/spec -O spec/spec.opts spec/views/users/ index.html.haml_spec.rb etc... Thanks, Steve ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
[rspec-users] Wrong ZenTest being used?
When I try to run autotest I get the following error: loading autotest/rails_rspec /usr/local/lib/site_ruby/1.8/rubygems.rb:319:in `activate': can't activate ZenTest (= 3.7.1), already activated ZenTest-3.9.1] (Gem::Exception) This is after just upgrading to the latest of everything from a previously working much earlier rev of rspec/rails, and zentest. I'm guessing something old is lingering around. Where would I be best off looking? Thanks, Steve ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Wrong ZenTest being used?
On Thu, 14 Feb 2008 17:53:42 +, Steve wrote: > When I try to run autotest I get the following error: > > loading autotest/rails_rspec > /usr/local/lib/site_ruby/1.8/rubygems.rb:319:in `activate': can't > activate ZenTest (= 3.7.1), already activated ZenTest-3.9.1] > (Gem::Exception) > > This is after just upgrading to the latest of everything from a > previously working much earlier rev of rspec/rails, and zentest. I'm > guessing something old is lingering around. Where would I be best off > looking? This was a false alarm caused by something in my ~/.autotest file that just needed updating for 3.9.1. Sorry for the interruption. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] params are making my "should redirect_to" test fail - why??
On Thu, Feb 14, 2008 at 5:15 AM, Max Williams <[EMAIL PROTECTED]> wrote: > Hi David - thanks for replying. The literal doesn't work either, because of > all the params at the end, and i don't have named routes in this old, > non-restful app. I see your point about the hash...is there any way to get > the redirected-to url from 'response' and test against that? Then i could > split it at "?" to ignore the params. (I'd rather not include the specific > params in this test since i really just want to know about where it's > redirected to). > > So, ideally i could do something like this - > > response.url.split("?").first.should > eql("http://test.host/admin/users/batch_saved";) Try response.redirect_url. > > I've been looking for documentation for methods for the response object, to > get the url, but i can't find any in the api docs (i'm probably just looking > in the wrong place). I can see the url data in the object but it's private. > > thanks > max > > > > On 13/02/2008, David Chelimsky <[EMAIL PROTECTED]> wrote: > > On Feb 13, 2008 12:26 PM, Max Williams <[EMAIL PROTECTED]> > wrote: > > > > > > I'm testing a controller action that redirects to a different > action/view, > > > sending through some params. In my test, i'm only specifying the > controller > > > and action that it should redirect to, but the additional params are > making > > > it fail! Here's my test: > > > > > > it "should redirect to batch_saved after completing batch_save" do > > > post 'batch_save', @params > > > response.should redirect_to(:controller => 'admin/users', :action => > > > 'batch_saved') > > > end > > > > > > and here's the failure report: > > > > > > 'Admin::UserController When logged in as an admin level user should > redirect > > > to batch_saved after batch_save' FAILED > > > expected redirect to {:controller=>"admin/users", > :action=>"batch_saved"}, > > > got redirect to > > > > "http://test.host/admin/users/batch_saved?music_service_id=1&new_users%5B%5D%5Bemail%5D=mark%40zadeup.com&new_users%5B%5D%5Bfirstname%5D=Mark&new_users%5B%5D%5Bmusic_service_id%5D=1&new_users%5B%5D%5Bschool%5D=&new_users%5B%5D%5Bsurname%5D=Madeup"; > > > > > > Now, i would expect that since i'm just specifying a controller and > action, > > > and we redirect to them, that the test would pass. But the params are > > > breaking it (I know this because i changed the controller action to not > send > > > params through at all and the test passed). How do i do the test so > that it > > > doesn't care about the params? > > > > > > When you use a hash it checks the whole hash, so this is the expected > behaviour. > > > > You can either used a named route (if you've got one available) or a > > String literal: > > > > response.should redirect_to(admin_users_batch_saved) > > response.should redirect_to('/admin/users/batch_saved') > > > > Based on Jay Field's latest advice > > (http://blog.jayfields.com/2008/02/testing-expect-literals.html) you > > may want to consider the literal. > > > > HTH, > > David > > > > > > > > > > > > > -- > > > > > View this message in context: > http://www.nabble.com/params-are-making-my-%22should-redirect_to%22-test-fail---why---tp15460582p15460582.html > > > 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 > > > > > ___ > 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] params are making my "should redirect_to" test fail - why??
Done, thanks everyone. On 14/02/2008, David Chelimsky <[EMAIL PROTECTED]> wrote: > > On Thu, Feb 14, 2008 at 10:16 AM, Max Williams > > <[EMAIL PROTECTED]> wrote: > > > I'm new to rspec (and coding in general) but would it break a lot of > > people's tests if redirect_to was changed to do this by default? It's > what > > i expected it to do, personally, that is to pass if the given :action > and > > :controller match up. If i pass a url string, and it's missing the > params, > > then it seems fair that it should fail, but if for example i just > specify a > > controller, and that controller is called (with any action) i'd expect > it to > > pass as well. > > > > Like i say i'm a newb with no idea of the impact of this to existing > tests > > :) > > > It is conceivable that existing examples could break, but the docs do > set out the same expectation that you have. > > Can you file a bug at http://rspec.lighthouseapp.com so we can get it > in the queue? > > > > > On 14/02/2008, Rick DeNatale <[EMAIL PROTECTED]> wrote: > > > On 2/14/08, David Chelimsky <[EMAIL PROTECTED]> wrote: > > > > On Thu, Feb 14, 2008 at 9:48 AM, Rick DeNatale < > [EMAIL PROTECTED]> > > wrote: > > > > > On 2/14/08, David Chelimsky <[EMAIL PROTECTED]> wrote: > > > > > > On Thu, Feb 14, 2008 at 8:22 AM, Rick DeNatale > > <[EMAIL PROTECTED]> wrote: > > > > > > > > > I don't have the cycles to add this anytime soon, so if you > like > > the > > > > > > idea, feel free to submit a patch to the tracker. > > > > > > > > > > I'd be happy to do that, although I'm not entirely convinced > that > > > > > redirect_with is the right name, not that I've got a better > > > > > alternative. > > > > > > > > > > > > redirect_with_options? > > > > > > > > > I think I like that. > > > > > > > > > > > > > How about something added to the existing call? > > > > > > > > response.should redirect_to(:controller => 'foo', :action => > > > > 'bar').ignoring_other_options > > > > > > > > > This seems too wordy. > > > > > > > > > > > > -- > > > > > > Rick DeNatale > > > > > > My blog on Ruby > > > http://talklikeaduck.denhaven2.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 > > > ___ > 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] Failed specs spike autotest
I found the source of the problem and I'm working on a fix. On Thu, Feb 14, 2008 at 11:16 PM, Steve <[EMAIL PROTECTED]> wrote: > On Fri, 15 Feb 2008 08:57:32 +0800, Kamal Fariz wrote: > > > > I got this too, but didn't bother to find out where and how script/ spec > > would sneak into the list of files to test. I got this even if i > > explicitly exclude the file in my .autotest. > > > > The quick and dirty thing I did was: > > > >def make_test_cmd(files_to_test) > > return "#{ruby} -S #{spec_command} #{add_options_if_present} > > #{files_to_test.keys.flatten.select { |i| i != 'script/spec' }.join(' > > ')}" > >end > > > > in vendor/plugins/rspec/lib/autotest/rspec.rb > > Is perhaps something else required? If I put this in autotest just keeps > running all of my specs repeatedly. It doesn't wait for a file change to > signal it to try running some explicit spec again. It does put out the > first line minus the script/spec at the end before launching into all of > that. I think it then thinks that perhaps the broken specs are fixed, so > that's why it then tries to run all of the specs again. > > Finished in 15.703733 seconds > > 398 examples, 1 failure, 1 pending > > /usr/bin/ruby1.8 -S script/spec -O spec/spec.opts > /usr/bin/ruby1.8 -S script/spec -O spec/spec.opts spec/views/users/ > index.html.haml_spec.rb etc... > > Thanks, > Steve > > > > ___ > 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] specdoc and taskpaper
On Thu, Feb 14, 2008 at 2:09 PM, Colin Campbell-McPherson <[EMAIL PROTECTED]> wrote: > I use task paper and love it. Definitely the fastest way to throw in todo > items. I wouldn't call the format yaml-ish though. Here's an example: > I use Toodledo myself. Works from anywhere, including iPhone, and there's even a command line client in Ruby for it. (I wrote it myself, but it's still pretty cool.) Will. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] Failed specs spike autotest
The source of the bug was a patch that we applied a while back. This was after the 1.1.3 release, so if you're using 1.1.3 you're fine. If you're using trunk, go ahead and update and you should be fine now. On Fri, Feb 15, 2008 at 12:31 AM, David Chelimsky <[EMAIL PROTECTED]> wrote: > I found the source of the problem and I'm working on a fix. > > > > On Thu, Feb 14, 2008 at 11:16 PM, Steve <[EMAIL PROTECTED]> wrote: > > On Fri, 15 Feb 2008 08:57:32 +0800, Kamal Fariz wrote: > > > > > > I got this too, but didn't bother to find out where and how script/ spec > > > would sneak into the list of files to test. I got this even if i > > > explicitly exclude the file in my .autotest. > > > > > > The quick and dirty thing I did was: > > > > > >def make_test_cmd(files_to_test) > > > return "#{ruby} -S #{spec_command} #{add_options_if_present} > > > #{files_to_test.keys.flatten.select { |i| i != 'script/spec' }.join(' > > > ')}" > > >end > > > > > > in vendor/plugins/rspec/lib/autotest/rspec.rb > > > > Is perhaps something else required? If I put this in autotest just keeps > > running all of my specs repeatedly. It doesn't wait for a file change to > > signal it to try running some explicit spec again. It does put out the > > first line minus the script/spec at the end before launching into all of > > that. I think it then thinks that perhaps the broken specs are fixed, so > > that's why it then tries to run all of the specs again. > > > > Finished in 15.703733 seconds > > > > 398 examples, 1 failure, 1 pending > > > > /usr/bin/ruby1.8 -S script/spec -O spec/spec.opts > > /usr/bin/ruby1.8 -S script/spec -O spec/spec.opts spec/views/users/ > > index.html.haml_spec.rb etc... > > > > Thanks, > > Steve > > > > > > > > ___ > > 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] Autotest setup to run Story Runner?
Has anyone looked at hooking up the Story Runner to Autotest? Currently, the autotest hooks that rspec uses explicitly runs ./script/ spec, which when pointed to a story runner file doesn't do anything. (In fact, the generated spec.opts has an incompatible --format option - changing progress to just p works as it maps to plain in story runner) Here's how I think it can be mapped. I have a fairly simple convention: 1. Match stories/stories/(.*), rerun stories/stories/basename($1).rb (i name my story files with .story extension) 2. Match stories/(helper|all).rb, rerun stories/all.rb 3. Match stories/steps/(.*)_step.rb, rerun stories/stories/ basename($1).rb You can be fancier for steps if you like to break them up, like looking into which Story Runner uses those steps. Can Story Runner run a specific scenario in a story? Like how Spec Runner can just execute a particular example. Regards, Kamal p/s: I'm using rstakeout currently to run my stories and autotest to run my specs. It'll be great if they can context-switch in the same autotest instance. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users