From nick at ekenosen.net Fri Jun 1 00:06:09 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Fri, 1 Jun 2007 00:06:09 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <57c63afe0705311456p716f9c8mf564f3cd4cbfd40b@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <57c63afe0705311456p716f9c8mf564f3cd4cbfd40b@mail.gmail.com> Message-ID: <276ff9870705312106u1dd74b9fj1eb3d1e9dec7eeee@mail.gmail.com> On 5/31/07, David Chelimsky wrote: > On 5/31/07, nicholas a. evans wrote: > > So here's my latest thought-experiment: http://pastie.caboo.se/66478 > > And also, a simpler multi-field version: http://pastie.caboo.se/66510 > I took at a shot at something that feels more like the rest of RSpec. > It's admittedly more verbose than your examples, but I also think it > speaks well and aligns with everything else in rspec. WDYT? > > http://pastie.caboo.se/66679 Oh! I like it a *lot*. Yes, it's more verbose on each example than I prefer (8 characters plus two indentation levels plus the length of the block variable). But it does read more fluidly, and in many ways it looks much simpler. My "default_params" is simply your input to "given". My "columns" or "field_to_validate", is simply the argument(s) to "it_should_require_that". Likewise, "as" reads more naturally than :msg (although I had been thinking of using "with_message", which feels a bit more readable). I have only one real objection/concern: "given User.new" would pass in an object that would get reused for each accept/reject line in the block. I prefer the approach of creating a new/fresh object for each example. Perhaps it could accept a Proc or a symbol representing a method name, searching first for an instance method in the behavior, and then a class method on the class being described. "given :new" would get a different object from User.new before each example. "given User.new" would reuse the same new User object for all of the examples. "given :user_with_full_access" would call "user_with_full_access" (defined in that behavior or on User) before each example. "given user_with_full_access" would reuse the same object for all examples. What do you think? Is there a better way? A few more thoughts and questions: How about "it_should_validate_that" rather than "it_should_require_that"? That feels more explicit and to-the-point, to me. At that point, the ":behavior_type => :validation" becomes redundant. "it_should_validate_that" could simply be available to all model behaviors. What else could "given" be used for? It seems like this could become a pattern/approach that could extend beyond model validations... Have you thought about using it for anything else yet? How could we specify a *default* rejection message (or error count, etc)? Does "user.default_rejection_message = /the message/" (and so on) look reasonable? I did like that the each example/assertion got its own entry in the specdoc with my approach... Do you think that it is best to sum it up to the rule? Either way, I presume that a failure should still run all of examples to give a full report, rather than stop at the first wrong one. My approach assumed that if you were only working with one field, we should only check for errors on that one field (it's okay if the object is otherwise invalid). But if you are working with multiple fields, you should check to see if the entire object is valid, and check against all error messages. Do you think that is a safe and reasonable convention? Thanks for your thoughts... and your improvements on my thoughts. :-) -- Nick From daniel at danielfischer.com Fri Jun 1 00:09:21 2007 From: daniel at danielfischer.com (Fischer, Daniel) Date: Thu, 31 May 2007 21:09:21 -0700 Subject: [rspec-users] Could anyone please help with rspec/nested resource behavior checking? In-Reply-To: <7e565b5c0705310503l6af1f834n5d0363633787b59a@mail.gmail.com> References: <7e565b5c0705301703w334c3e2dg3f05d734ed76cd5a@mail.gmail.com> <1D95C70C-B551-43D3-AE07-5E7FFD9C5B74@parkerhill.com> <7e565b5c0705301807o42711e51w555ace5e8c037c84@mail.gmail.com> <7e565b5c0705302317s6a4ae3b7raa72f362a7f063d9@mail.gmail.com> <7e565b5c0705310131l441129dfif4441e2759d26afb@mail.gmail.com> <57c63afe0705310342h42ab6f51x77c3576c9f77f69c@mail.gmail.com> <7e565b5c0705310417u1d1fef0fv8a152b938c672966@mail.gmail.com> <57c63afe0705310428x57847426gaef8bc3d2733cfc1@mail.gmail.com> <7e565b5c0705310503l6af1f834n5d0363633787b59a@mail.gmail.com> Message-ID: <7e565b5c0705312109j107a524cmed721984b91538a2@mail.gmail.com> Alright so I removed the 'nested' resources, but I still have another problem. Most of my failures are gone, but I still have three left: 1) Spec::Mocks::MockExpectationError in 'PostsController handling GET /posts/1;edit should find the posts requested' Post expected :find with (any args) once, but received it twice ./spec/controllers/posts_controller_spec.rb:217: 2) Spec::Mocks::MockExpectationError in 'PostsController handling POST /posts should create a new posts' Mock 'Post_1027' received unexpected message :user_id= with (202018) /Users/sparta/Projects/work/idastudios/podff_machine/config/../app/controllers/posts_controller.rb:36:in `create' /Users/sparta/Projects/work/idastudios/podff_machine/config/../vendor/plugins/haml/lib/sass/plugin.rb:116:in `process_without_test' ./spec/controllers/posts_controller_spec.rb:250:in `do_post' ./spec/controllers/posts_controller_spec.rb:256: 3) Spec::Mocks::MockExpectationError in 'PostsController handling POST /posts should redirect to the new posts' Mock 'Post_1028' received unexpected message :user_id= with (202018) /Users/sparta/Projects/work/idastudios/podff_machine/config/../app/controllers/posts_controller.rb:36:in `create' /Users/sparta/Projects/work/idastudios/podff_machine/config/../vendor/plugins/haml/lib/sass/plugin.rb:116:in `process_without_test' ./spec/controllers/posts_controller_spec.rb:250:in `do_post' ./spec/controllers/posts_controller_spec.rb:260: Finished in 0.697209 seconds 38 examples, 3 failures I don't understand the first one, but I do have an idea on the second/third one. I am setting the @post.user_id to the current user in the controller, I'm trying to mock that behavior but whatever I try doesn't work. What would be the proper way? Right now I am doing this: it "should create a new posts" do Post.should_receive(:user_id).and_return(1) Post.should_receive(:new).with({'name' => 'Post'}).and_return(@post) do_post end still fails with that message though :( On 5/31/07, Fischer, Daniel wrote: > David, > > Awesome - well at least it's telling me something isn't working "that well" > anymore. > > Instead of the previous "expected success? to return true, got false" > > It's now "Couldn't find User with ID=1" > > But I swore that same code worked before, it looks proper in my pastie > doesn't it? > > *scratches head* - it certainly works when it's "live". > > On 5/31/07, David Chelimsky wrote: > > On 5/31/07, Fischer, Daniel wrote: > > > 1) > > > 'PostsController handling GET /users/1/posts should be successful' > FAILED > > > expected success? to return true, got false > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/expectations.rb:52:in > > > `fail_with' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/expectations/handler.rb:16:in > > > `handle_matcher' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/expectations/extensions/object.rb:32:in > > > `should' > > > ./spec/controllers/posts_controller_spec.rb:46: > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > 1.0.2/lib/spec/dsl/example.rb:73:in > > > `instance_eval' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/example.rb:73:in > > > `run_example' > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > 1.0.2/lib/spec/dsl/example.rb:23:in > > > `run' > > > /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/example.rb:21:in > > > `run' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/behaviour.rb:72:in > > > `run' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/behaviour.rb:69:in > > > `each' > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > > > 1.0.2/lib/spec/dsl/behaviour.rb:69:in `run' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/runner/behaviour_runner.rb:45:in > > > `run_behaviours' > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > 1.0.2/lib/spec/runner/behaviour_runner.rb:44:in > > > `each' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/runner/behaviour_runner.rb:44:in > > > `run_behaviours' > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > 1.0.2/lib/spec/runner/behaviour_runner.rb:27:in > > > `run' > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > > > 1.0.2/lib/spec/runner/command_line.rb:17:in `run' > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > 1.0.2/bin/spec:3: > > > /usr/local/bin/spec:18:in `load' > > > /usr/local/bin/spec:18: > > > > > > Doesn't really tell me anything, how about you? > > > > Nope. Thanks for playing ;) > > > > One thing - controller examples used to implicitly re-raise controller > > errors. We removed this in response to a bug report, which had the > > insidious side-effect of hiding errors without you knowing. If you > > upgrade to 1.0.4, you'll see a call in spec_helper.rb to > > raise_controller_errors. This is a new method that lets you do so > > explicitly, and is included in spec_helper.rb by default. > > > > I'm thinking this might help expose the problem. > > > > > > > > > > > On 5/31/07, David Chelimsky wrote: > > > > On 5/31/07, Fischer, Daniel wrote: > > > > > Oh my... > > > > > > > > > > I don't know what happened... but my entire posts_controller_spec > > > > > completely exploded and i'm having 31 failures, before I was having > > > > > like 8. I'm not sure what is going on, I could REALLY use the help. > > > > > > > > > > http://pastie.caboo.se/66440 for a list of everything that is going > > > > > on, and the code. > > > > > > > > Try running the one file with the -b switch to get a full backtrace. > > > > > > > > script/spec spec/controllers/posts_controller_spec.rb > -b > > > > > > > > > > > > > > I really appreciate the help guys, once I get over the mountain I'm > > > > > sure I'll understand it :) > > > > > > > > > > On 5/30/07, Fischer, Daniel < daniel at danielfischer.com> wrote: > > > > > > Okay that failed. > > > > > > > > > > > > I could really use a full blown example with this, just mocking > isn't > > > going > > > > > > to "give me insight" anymore I don't think. If anyone can post a > basic > > > crud > > > > > > behavior check, w/ nested routes - I'd really appreciate it. > > > > > > > > > > > > Thanks, > > > > > > Daniel > > > > > > > > > > > > On 5/30/07, Chris Anderson wrote: > > > > > > > I usually do something like this in my before(:each) section: > > > > > > > > > > > > > > User.stub!(:find).and_return(@u = mock_model(User, :posts => @pc > = > > > > > > > mock('posts collection'))) > > > > > > > @pc.stub(:find).and_return([@p = mock_model(Post)]) > > > > > > > > > > > > > > with the corresponding should_receives in my various examples... > the > > > > > > > trick is to mock the user's posts collection as its own object. > > > > > > > > > > > > > > On 5/30/07, Fischer, Daniel < daniel at danielfischer.com> wrote: > > > > > > > > Jonathan, > > > > > > > > > > > > > > > > Yeah something like that. I have no idea how to put it > together > > > > > > > > properly. I'm beyond confused at this point, that's why I > could > > > really > > > > > > > > use some help. > > > > > > > > > > > > > > > > I figured out my "response" error, but now Im trying to "find > all > > > posts" > > > > > > > > > > > > > > > > Right now I got something like: > > > > > > > > > > > > > > > > > > > > > > > > > > User.should_receive(:posts).with(:all).and_return([@posts]) > > > > > > > > > > > > > > > > But I know it should be User.posts.find(:all) - i'm not sure > how > > > to > > > > > > > > make this a proper behavior check. > > > > > > > > > > > > > > > > How do I setup my mocks to correspond with this? > > > > > > > > > > > > > > > > Thanks. > > > > > > > > > > > > > > > > On 5/30/07, Jonathan Linowes < jonathan at parkerhill.com> wrote: > > > > > > > > > Don't you need to stub the User model :find too? (needed in > your > > > > > > > > > private get_user call) > > > > > > > > > > > > > > > > > > private > > > > > > > > > def get_user > > > > > > > > > @user = User.find(params[:user_id]) > > > > > > > > > @post = @user.posts.find(params[:id]) if params[:id] > > > > > > > > > end > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On May 30, 2007, at 8:03 PM, Fischer, Daniel wrote: > > > > > > > > > > > > > > > > > > > My problem has been listed here: > > > > > > > > > > > > > > > > > http://railsforum.com/viewtopic.php?pid=25439#p25439 > > > > > > > > > > > > > > > > > > > > Don't think it would be required to completely re-type it > here > > > :) > > > > > > > > > > > > > > > > > > > > Thanks! > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > -Daniel Fischer > > > > > > > > > > > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > > > > > > http://abigfisch.com - Portfolio > > > > > > > > > > http://writersbeat.com - Writing Community > > > > > > > > > > > > > _______________________________________________ > > > > > > > > > > rspec-users mailing list > > > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > > rspec-users mailing list > > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > -Daniel Fischer > > > > > > > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > > > > http://abigfisch.com - Portfolio > > > > > > > > http://writersbeat.com - Writing Community > > > > > > > > > _______________________________________________ > > > > > > > > rspec-users mailing list > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > Chris Anderson > > > > > > > http://jchris.mfdz.com > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > -Daniel Fischer > > > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > > http://abigfisch.com - Portfolio > > > > > > http://writersbeat.com - Writing Community > > > > > > > > > > > > > > > -- > > > > > -Daniel Fischer > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > http://abigfisch.com - Portfolio > > > > > http://writersbeat.com - Writing Community > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > -- > > > > > > -Daniel Fischer > > > > > > http://danielfischer.com - Geek Blog > > > http://abigfisch.com - Portfolio > > > http://writersbeat.com - Writing Community > > > > > > -- > > -Daniel Fischer > > http://danielfischer.com - Geek Blog > http://abigfisch.com - Portfolio > http://writersbeat.com - Writing Community -- -Daniel Fischer http://danielfischer.com - Geek Blog http://abigfisch.com - Portfolio http://writersbeat.com - Writing Community From dchelimsky at gmail.com Fri Jun 1 01:00:29 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 1 Jun 2007 01:00:29 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <276ff9870705312106u1dd74b9fj1eb3d1e9dec7eeee@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <57c63afe0705311456p716f9c8mf564f3cd4cbfd40b@mail.gmail.com> <276ff9870705312106u1dd74b9fj1eb3d1e9dec7eeee@mail.gmail.com> Message-ID: <57c63afe0705312200y274a4f43x966600bce6885d5a@mail.gmail.com> On 6/1/07, nicholas a. evans wrote: > On 5/31/07, David Chelimsky wrote: > > On 5/31/07, nicholas a. evans wrote: > > > So here's my latest thought-experiment: http://pastie.caboo.se/66478 > > > And also, a simpler multi-field version: http://pastie.caboo.se/66510 > > > I took at a shot at something that feels more like the rest of RSpec. > > It's admittedly more verbose than your examples, but I also think it > > speaks well and aligns with everything else in rspec. WDYT? > > > > http://pastie.caboo.se/66679 > > Oh! I like it a *lot*. Yes, it's more verbose on each example than I > prefer (8 characters plus two indentation levels plus the length of > the block variable). But it does read more fluidly, and in many ways > it looks much simpler. My "default_params" is simply your input to > "given". My "columns" or "field_to_validate", is simply the > argument(s) to "it_should_require_that". Likewise, "as" reads more > naturally than :msg (although I had been thinking of using > "with_message", which feels a bit more readable). > > I have only one real objection/concern: > > "given User.new" would pass in an object that would get reused for > each accept/reject line in the block. I prefer the approach of > creating a new/fresh object for each example. Perhaps it could accept > a Proc or a symbol representing a method name, searching first for an > instance method in the behavior, and then a class method on the class > being described. > > "given :new" would get a different object from User.new before each example. > "given User.new" would reuse the same new User object for all of the examples. > "given :user_with_full_access" would call "user_with_full_access" > (defined in that behavior or on User) before each example. > "given user_with_full_access" would reuse the same object for all examples. > > What do you think? Is there a better way? I put up a third version: http://pastie.caboo.se/66776 WDYT? > A few more thoughts and questions: > > How about "it_should_validate_that" rather than > "it_should_require_that"? "validate" is fine. > That feels more explicit and to-the-point, > to me. At that point, the ":behavior_type => :validation" becomes > redundant. "it_should_validate_that" could simply be available to all > model behaviors. Why not just stick it in a module and let the user decide where to make it available? If you, as a user of this extension, wanted it available to all model examples, you could do this: Spec::Runner.configure do |config| config.include(ModelValidations, :behaviour_type => :model) end > What else could "given" be used for? It seems like this could become > a pattern/approach that could extend beyond model validations... Have > you thought about using it for anything else yet? Not yet. I was just bouncing off your proposal. Let's see how this works in practice before we start creating conventions :) > How could we specify a *default* rejection message (or error count, > etc)? Does "user.default_rejection_message = /the message/" (and so > on) look reasonable? That seems like you're telling the user to use a specific message rather than generally expecting it, which is what I *think* you mean. Am I missing it? > > I did like that the each example/assertion got its own entry in the > specdoc with my approach... Do you think that it is best to sum it up > to the rule? Either way, I presume that a failure should still run > all of examples to give a full report, rather than stop at the first > wrong one. I think you can get all that. The #given method has a handle on the object before it yields to the block, the should_reject and should_accept methods can be configured to create examples at run time. Make sense? > > My approach assumed that if you were only working with one field, we > should only check for errors on that one field (it's okay if the > object is otherwise invalid). But if you are working with multiple > fields, you should check to see if the entire object is valid, and > check against all error messages. Do you think that is a safe and > reasonable convention? This could get quite complicated. Which is probably why nobody has tackled this in a generic way yet - at least that I've seen. > > Thanks for your thoughts... and your improvements on my thoughts. :-) My pleasure. I'm looking forward to seeing how this turns out. Cheers, David > > -- > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From justnothing at tiscali.co.uk Fri Jun 1 05:00:53 2007 From: justnothing at tiscali.co.uk (David Green) Date: Fri, 1 Jun 2007 02:00:53 -0700 (PDT) Subject: [rspec-users] rspec_on_rails, could someone provide an example of using mocks/stubs? Message-ID: <10909256.post@talk.nabble.com> hi all I'm still a little uncertain on how to use mocks/stubs with rspec when dealing with associations. I know the point is to isolate the code being tested and remove external dependencies, but I'm not sure how to implement it. Can someone suggest how they would spec the code below: I have a Book model and Review model class Book < ActiveRecord::Base has_many :reviews def update_rating new_rating = 0.0 unless reviews.empty? reviews.each {|r| new_rating += r.rating} new_rating /= review.size end update_attribute(:rating, new_rating) end end The review class is just a standard model with a :rating attribute. Here's the (empty) spec i came up with: describe Book, ".update_rating" do it "should set rating to 0.0 when there are no reviews" do end it "should set :rating to the average rating when there are reviews" do end end I know I'm supposed to implement the specs first but I wrote the update_attribute() method here to show the kinds of method calls it would be making. Here's what I think I need to do: - stub @book.reviews to return a mock object e.g. mock_reviews - stub mock_reviews.each to return another mock e.g. mock_r - stub mock_r.rating to return some value am I on the right track? it seems like a lot of preparation for such a simple test. Is there a better way? thanks dave -- View this message in context: http://www.nabble.com/rspec_on_rails%2C-could-someone-provide-an-example-of-using-mocks-stubs--tf3851161.html#a10909256 Sent from the rspec-users mailing list archive at Nabble.com. From nick at ekenosen.net Fri Jun 1 10:34:23 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Fri, 1 Jun 2007 10:34:23 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <57c63afe0705312200y274a4f43x966600bce6885d5a@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <57c63afe0705311456p716f9c8mf564f3cd4cbfd40b@mail.gmail.com> <276ff9870705312106u1dd74b9fj1eb3d1e9dec7eeee@mail.gmail.com> <57c63afe0705312200y274a4f43x966600bce6885d5a@mail.gmail.com> Message-ID: <276ff9870706010734q601c018bvc82dc1196d9da00c@mail.gmail.com> On 6/1/07, David Chelimsky wrote: > I put up a third version: http://pastie.caboo.se/66776 I looks like you lost the ability to know which field was being validated, so I changed it back to it_should_validate_that :field, "satisfies rule" > Why not just stick it in a module and let the user decide where to > make it available? That makes sense. > Not yet. I was just bouncing off your proposal. Let's see how this > works in practice before we start creating conventions :) Good point. :-) > That seems like you're telling the user to use a specific message > rather than generally expecting it, which is what I *think* you mean. > Am I missing it? You're right... I'll worry about that feature later, then. :-) > I think you can get all that. The #given method has a handle on the > object before it yields to the block, the should_reject and > should_accept methods can be configured to create examples at run > time. Make sense? Yeah, but we've also added a string via "it_should_validate_that"... What would the specdoc look like? We don't have a mechanism for nesting 3 levels deep, do we? > > My approach assumed that if you were only working with one field, we > > should only check for errors on that one field (it's okay if the > > object is otherwise invalid). But if you are working with multiple > > fields, you should check to see if the entire object is valid, and > > check against all error messages. Do you think that is a safe and > > reasonable convention? > > This could get quite complicated. Which is probably why nobody has > tackled this in a generic way yet - at least that I've seen. True... but it feels like we're getting close to something that is very good and simple. It doesn't need to solve 100% of the world's validation needs... just 85% of my rails validation needs. For anything more complicated, I can always fall back on vanilla rspec (still pretty tasty!). For my tastes and intuition, I prefer that validation specs against a single field check only that single field's validity, and validations specs against multiple fields check the model's validity. But I would be fine if it were simplified to normally check only the fields under inspection, but could be easily changed to check for any errors on the object. Here are my next several attempts: Playing off of your approach and including a number of proposed specdoc outputs: http://pastie.caboo.se/66855 But here's my current favorite approach: http://pastie.caboo.se/66862 -- Nick From nick at ekenosen.net Fri Jun 1 11:11:31 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Fri, 1 Jun 2007 11:11:31 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <276ff9870706010734q601c018bvc82dc1196d9da00c@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <57c63afe0705311456p716f9c8mf564f3cd4cbfd40b@mail.gmail.com> <276ff9870705312106u1dd74b9fj1eb3d1e9dec7eeee@mail.gmail.com> <57c63afe0705312200y274a4f43x966600bce6885d5a@mail.gmail.com> <276ff9870706010734q601c018bvc82dc1196d9da00c@mail.gmail.com> Message-ID: <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> On 6/1/07, nicholas a. evans wrote: > But here's my current favorite approach: http://pastie.caboo.se/66862 Ack! I had some silly/bad ruby syntax in that last pastie. Let's try that again; now with improved (valid) ruby syntax! http://pastie.caboo.se/66896 -- Nick From tristil at gmail.com Fri Jun 1 12:17:31 2007 From: tristil at gmail.com (Joseph Method) Date: Fri, 1 Jun 2007 12:17:31 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <57c63afe0705311456p716f9c8mf564f3cd4cbfd40b@mail.gmail.com> <276ff9870705312106u1dd74b9fj1eb3d1e9dec7eeee@mail.gmail.com> <57c63afe0705312200y274a4f43x966600bce6885d5a@mail.gmail.com> <276ff9870706010734q601c018bvc82dc1196d9da00c@mail.gmail.com> <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> Message-ID: <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> What about 'this' as a reserved name for what's given? given { User.new } this.should_reject (nil) given { User.new(:name => 'Bob' } this.should_reject(nil) On 6/1/07, nicholas a. evans wrote: > On 6/1/07, nicholas a. evans wrote: > > But here's my current favorite approach: http://pastie.caboo.se/66862 > > Ack! I had some silly/bad ruby syntax in that last pastie. > > Let's try that again; now with improved (valid) ruby syntax! > > http://pastie.caboo.se/66896 > > -- > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- -J. Method From nick at ekenosen.net Fri Jun 1 13:02:24 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Fri, 1 Jun 2007 13:02:24 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <57c63afe0705311456p716f9c8mf564f3cd4cbfd40b@mail.gmail.com> <276ff9870705312106u1dd74b9fj1eb3d1e9dec7eeee@mail.gmail.com> <57c63afe0705312200y274a4f43x966600bce6885d5a@mail.gmail.com> <276ff9870706010734q601c018bvc82dc1196d9da00c@mail.gmail.com> <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> Message-ID: <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> On 6/1/07, Joseph Method wrote: > What about 'this' as a reserved name for what's given? I thought about trying something like that, and thus try to get back to the "normal" rspec syntax but it seems to me that "it" better fulfills that role. Here's my thought on a syntax like that: http://pastie.caboo.se/66937 How close does that compare to what you were thinking of, Joseph? (I prefer to use "specify" rather than "it", when I'm using the generated example string.) Now that I look at it, I actually think this is a rather nice syntax. But it's a lot more verbose than I'd like... perhaps "it_should_reject(foo)" could simply be shorthand for "specify { it.should reject(foo) }". This also makes it obvious how to override the generated example string. Thoughts? Is it an evil or difficult thing to repurpose "it" to my own dubious ends inside the examples? I really like the idea of "it" simply returning the result of the block that was previously passed to "given" -- Nick > given { User.new } > this.should_reject (nil) > > given { User.new(:name => 'Bob' } > this.should_reject(nil) From tristil at gmail.com Fri Jun 1 13:19:28 2007 From: tristil at gmail.com (Joseph Method) Date: Fri, 1 Jun 2007 13:19:28 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <57c63afe0705311456p716f9c8mf564f3cd4cbfd40b@mail.gmail.com> <276ff9870705312106u1dd74b9fj1eb3d1e9dec7eeee@mail.gmail.com> <57c63afe0705312200y274a4f43x966600bce6885d5a@mail.gmail.com> <276ff9870706010734q601c018bvc82dc1196d9da00c@mail.gmail.com> <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> Message-ID: <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> Well, this is what I was thinking: http://pastie.caboo.se/66940 > Thoughts? Honestly, the extra depth is a big turn-off for me. > Is it an evil or difficult thing to repurpose "it" to my > own dubious ends inside the examples? I really like the idea of "it" > simply returning the result of the block that was previously passed to > "given" > > -- > Nick It's not evil, but I don't know how difficult it is. If it's not difficult at all, I don't see why it can't be it.should_validate :password do -- -J. Method From nick at ekenosen.net Fri Jun 1 14:16:46 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Fri, 1 Jun 2007 14:16:46 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <57c63afe0705311456p716f9c8mf564f3cd4cbfd40b@mail.gmail.com> <276ff9870705312106u1dd74b9fj1eb3d1e9dec7eeee@mail.gmail.com> <57c63afe0705312200y274a4f43x966600bce6885d5a@mail.gmail.com> <276ff9870706010734q601c018bvc82dc1196d9da00c@mail.gmail.com> <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> Message-ID: <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> On 6/1/07, Joseph Method wrote: > Well, this is what I was thinking: http://pastie.caboo.se/66940 I think that I still prefer dedicating the entire behavior to validation of a particular field (that's what I do in my current specs anyway, albeit with far more lines of code). > > Thoughts? > > Honestly, the extra depth is a big turn-off for me. Strongly agreed in that regard. 10 extra characters on the front (and two on the back), repeated over every example. The whole point of this is to clean up the syntactic noise to highlight the examples themselves. The reasons I see to use that approach: it matches *very* well with the standard rspec way of doing things. At that point, it's really just the new given/it syntax, and a matcher that looks at some of the behavior options (to see which fields are being spec'd). And it gives an obvious interface for overriding/ignoring the generated example string. Likewise, it gives a nice syntax if I want to do some more advanced assertions on the model with that example. But I think I would use the shorthand version for 95% of my validation examples. And the shorthand could effectively generate the proposed longhand code. > > Is it an evil or difficult thing to repurpose "it" to my > > own dubious ends inside the examples? I really like the idea of "it" > > simply returning the result of the block that was previously passed to > > "given" > > It's not evil, but I don't know how difficult it is. If it's not > difficult at all, I don't see why it can't be > > it.should_validate :password do I don't think it would be right to have the behavior method "it" running double-duty (it is already used to create the examples). Also, I don't really see much benefit of "it.should_validate" over "it_should_validate". But I do like the idea of the example method "it" getting the results of the "given", and that should be easy (I think). -- Nick From jonathan at parkerhill.com Fri Jun 1 14:31:15 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Fri, 1 Jun 2007 14:31:15 -0400 Subject: [rspec-users] Could anyone please help with rspec/nested resource behavior checking? In-Reply-To: References: <7e565b5c0705301703w334c3e2dg3f05d734ed76cd5a@mail.gmail.com> <1D95C70C-B551-43D3-AE07-5E7FFD9C5B74@parkerhill.com> <7e565b5c0705301807o42711e51w555ace5e8c037c84@mail.gmail.com> Message-ID: <84AC7EEA-6A4E-44B8-B2AD-D41CE5FF4488@parkerhill.com> I haven't thought it through (no pun intended) but maybe this could be simplified and generalized , like add a ".through" to the stub and/ or should_receive ?? On May 31, 2007, at 1:01 AM, Chris Anderson wrote: > I usually do something like this in my before(:each) section: > > User.stub!(:find).and_return(@u = mock_model(User, :posts => @pc = > mock('posts collection'))) > @pc.stub(:find).and_return([@p = mock_model(Post)]) > > with the corresponding should_receives in my various examples... the > trick is to mock the user's posts collection as its own object. > From tristil at gmail.com Fri Jun 1 14:47:04 2007 From: tristil at gmail.com (Joseph Method) Date: Fri, 1 Jun 2007 14:47:04 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <57c63afe0705311456p716f9c8mf564f3cd4cbfd40b@mail.gmail.com> <276ff9870705312106u1dd74b9fj1eb3d1e9dec7eeee@mail.gmail.com> <57c63afe0705312200y274a4f43x966600bce6885d5a@mail.gmail.com> <276ff9870706010734q601c018bvc82dc1196d9da00c@mail.gmail.com> <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> Message-ID: <167b6aa00706011147q3e4449e0rcdf5ba06cff7c007@mail.gmail.com> How about this? http://pastie.caboo.se/66977 The strategy is to check if the string argument is :validations (so this would become reserved). If it is, then include ModelValidations. 'it' without the block returns an object that contains a should method. The block it opens is related to but different from the one that 'it' opens. given doesn't seem strictly necessary, since we know what's being described, but it reads well and is explicit. > I think that I still prefer dedicating the entire behavior to > validation of a particular field (that's what I do in my current specs > anyway, albeit with far more lines of code). I'm sure we won't be able to agree on this, but it seems like overkill to me. What if in this proposal there was an option for :validation_of_password, etc.? > I don't think it would be right to have the behavior method "it" > running double-duty (it is already used to create the examples). > Also, I don't really see much benefit of "it.should_validate" over > "it_should_validate". But I do like the idea of the example method > "it" getting the results of the "given", and that should be easy (I > think). Yeah, what's described here might be too evil. In its defense, though, the new 1.0 syntax seems to emphasize subject.should predicate over subject.should_predicate, which is what I've tried to preserve. > -- > Nick -- -J. Method From dchelimsky at gmail.com Fri Jun 1 18:01:09 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 1 Jun 2007 18:01:09 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <167b6aa00706011147q3e4449e0rcdf5ba06cff7c007@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <276ff9870705312106u1dd74b9fj1eb3d1e9dec7eeee@mail.gmail.com> <57c63afe0705312200y274a4f43x966600bce6885d5a@mail.gmail.com> <276ff9870706010734q601c018bvc82dc1196d9da00c@mail.gmail.com> <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> <167b6aa00706011147q3e4449e0rcdf5ba06cff7c007@mail.gmail.com> Message-ID: <57c63afe0706011501w6b48892ej654223495d956344@mail.gmail.com> On 6/1/07, Joseph Method wrote: > How about this? > > http://pastie.caboo.se/66977 > > The strategy is to check if the string argument is :validations (so > this would become reserved). If it is, then include ModelValidations. > 'it' without the block returns an object that contains a should > method. The block it opens is related to but different from the one > that 'it' opens. > > given doesn't seem strictly necessary, since we know what's being > described, but it reads well and is explicit. > > > I think that I still prefer dedicating the entire behavior to > > validation of a particular field (that's what I do in my current specs > > anyway, albeit with far more lines of code). > > I'm sure we won't be able to agree on this, but it seems like overkill > to me. What if in this proposal there was an option for > :validation_of_password, etc.? > > > I don't think it would be right to have the behavior method "it" > > running double-duty (it is already used to create the examples). > > Also, I don't really see much benefit of "it.should_validate" over > > "it_should_validate". But I do like the idea of the example method > > "it" getting the results of the "given", and that should be easy (I > > think). > > Yeah, what's described here might be too evil. In its defense, though, > the new 1.0 syntax seems to emphasize subject.should predicate over > subject.should_predicate, which is what I've tried to preserve. Well now we're getting much simpler. Instead of a whole new structure, why not just use a custom matcher? http://pastie.caboo.se/67069 > > > -- > > Nick > > -- > -J. Method > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From anthony at digitalphenom.com Fri Jun 1 18:20:32 2007 From: anthony at digitalphenom.com (Anthony Carlos) Date: Fri, 1 Jun 2007 18:20:32 -0400 Subject: [rspec-users] Specs for ApplicationController, where to put them? In-Reply-To: <57c63afe0705291652r2bb1ea05o29ed4b4ec96e29ed@mail.gmail.com> References: <2D69A175-3C2A-4E38-A006-68695DF3E359@wincent.com> <050EF0F7-7EE3-4995-AFE3-0FD735F98167@digitalphenom.com> <583D179D-743C-49BB-9CFA-B31AF11C71E2@digitalphenom.com> <57c63afe0705291652r2bb1ea05o29ed4b4ec96e29ed@mail.gmail.com> Message-ID: On May 29, 2007, at 7:52 PM, David Chelimsky wrote: >> My problem now, is that I get a nil object error. Specifically, in >> application.rb, I'm trying to call request.parameters and request is >> nil. It seems that request is not part of the context anymore since I >> moved the behavior out to a separate file. How do I regain access to >> request, response, assigns, flash, and session? > > The fact that the shared examples are in another file should have no > bearing on whether they have runtime access to whatever is in the > behaviours that include them. This all sounds odd to me. Can you post > a backtrace please? David: Here's the output from rake spec:autotest: : QuestionnairesController - should flash notice when session[:current_user_id] does not exist (ERROR - 1) - should return true when session[:current_user_id] exists - should respond to current_user - should respond to authenticate 1) NoMethodError in 'QuestionnairesController should flash notice when session[:current_user_id] does not exist' You have a nil object when you didn't expect it! The error occurred while evaluating nil.parameters /Users/aec/ror/aca/aca_trunk/config/../app/controllers/application.rb: 11:in `authenticate' ./spec/controllers/application_controller_spec.rb:24: ===== Here's application_controller_spec.rb: require File.dirname(__FILE__) + '/../spec_helper' unless Spec::DSL::Behaviour.find_shared_behaviour("All controllers") describe "All controllers", :shared => true do it "should respond to authenticate" do controller.should respond_to(:authenticate) end it "should respond to current_user" do controller.should respond_to(:current_user) end it "should return true when session[:current_user_id] exists" do session[:current_user_id] = 12345 controller.authenticate.should == true end it "should flash notice when session[:current_user_id] does not exist" do session[:current_user_id] = nil controller.authenticate # <===== This is line 24 where the error occurs! flash[:notice].should == 'Please login.' end end end ===== Here's application.rb: class ApplicationController < ActionController::Base # Pick a unique cookie name to distinguish our session data from others' session :session_key => '_unique_session_id' def authenticate unless session[:current_user_id] flash[:notice] = 'Please login.' session[:jumpto] = request.parameters # <===== This is line 11 where nil.parameters is called! redirect_to(:controller => 'ums', :action => 'login') end true end def current_user @current_user = User.find(session[:current_user_id]) end end ===== Finally, here's questionnaires_controller_spec.rb: require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/application_controller_spec' unless Spec::DSL::Behaviour.find_shared_behaviour("All controllers") describe QuestionnairesController do it_should_behave_like "All controllers" end : ===== So as far as I can tell, my QuestionnairesController should behave like "All controllers" which puts us at application_controller_spec.rb. The first 3 examples pass, but the fourth, which calls ApplicationController.authenticate, gives me the nil object. But, isn't request an object that is always available to controllers? Wait a second... There's no get or post command here! Maybe thats why request is nil? I think so. Never mind! Sorry about the false alarm. I don't want to be the boy who cried wolf. On the other hand, I think I avoided using get or post because this is an abstract action that gets called by other concrete classes. So how does one test logic in an abstract class? Smells like a job for a mock, of course?!? I'll look over the list archive-- I think other people have asked this question before. Thanks for helping out the slow learners, -Anthony From aslak.hellesoy at gmail.com Fri Jun 1 18:59:23 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 2 Jun 2007 00:59:23 +0200 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <57c63afe0706011501w6b48892ej654223495d956344@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <57c63afe0705312200y274a4f43x966600bce6885d5a@mail.gmail.com> <276ff9870706010734q601c018bvc82dc1196d9da00c@mail.gmail.com> <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> <167b6aa00706011147q3e4449e0rcdf5ba06cff7c007@mail.gmail.com> <57c63afe0706011501w6b48892ej654223495d956344@mail.gmail.com> Message-ID: <8d961d900706011559s1056a929i2a64758e2aa577e8@mail.gmail.com> On 6/2/07, David Chelimsky wrote: > On 6/1/07, Joseph Method wrote: > > How about this? > > > > http://pastie.caboo.se/66977 > > > > The strategy is to check if the string argument is :validations (so > > this would become reserved). If it is, then include ModelValidations. > > 'it' without the block returns an object that contains a should > > method. The block it opens is related to but different from the one > > that 'it' opens. > > > > given doesn't seem strictly necessary, since we know what's being > > described, but it reads well and is explicit. > > > > > I think that I still prefer dedicating the entire behavior to > > > validation of a particular field (that's what I do in my current specs > > > anyway, albeit with far more lines of code). > > > > I'm sure we won't be able to agree on this, but it seems like overkill > > to me. What if in this proposal there was an option for > > :validation_of_password, etc.? > > > > > I don't think it would be right to have the behavior method "it" > > > running double-duty (it is already used to create the examples). > > > Also, I don't really see much benefit of "it.should_validate" over > > > "it_should_validate". But I do like the idea of the example method > > > "it" getting the results of the "given", and that should be easy (I > > > think). > > > > Yeah, what's described here might be too evil. In its defense, though, > > the new 1.0 syntax seems to emphasize subject.should predicate over > > subject.should_predicate, which is what I've tried to preserve. > > Well now we're getting much simpler. Instead of a whole new structure, > why not just use a custom matcher? > > http://pastie.caboo.se/67069 > Brilliant! Aslak > > > > > -- > > > Nick > > > > -- > > -J. Method > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From luislavena at gmail.com Fri Jun 1 19:40:59 2007 From: luislavena at gmail.com (Luis Lavena) Date: Fri, 1 Jun 2007 20:40:59 -0300 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <8d961d900706011559s1056a929i2a64758e2aa577e8@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <276ff9870706010734q601c018bvc82dc1196d9da00c@mail.gmail.com> <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> <167b6aa00706011147q3e4449e0rcdf5ba06cff7c007@mail.gmail.com> <57c63afe0706011501w6b48892ej654223495d956344@mail.gmail.com> <8d961d900706011559s1056a929i2a64758e2aa577e8@mail.gmail.com> Message-ID: <71166b3b0706011640i4c731402td3f180b83952b24f@mail.gmail.com> On 6/1/07, aslak hellesoy wrote: > > On 6/1/07, Joseph Method wrote: > > > > Well now we're getting much simpler. Instead of a whole new structure, > > why not just use a custom matcher? > > > > http://pastie.caboo.se/67069 > > > > Brilliant! > I agree with aslak on this! Is descriptive, but not too verbose, is simple but not too cryptic. Translation: Looks good, are you willing to share it? ;-) (David and Aslak, I didn't found a example on how to implemente a custom matcher like Jospeh did, guess I missed a lot of RDocs :-P -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi From dchelimsky at gmail.com Fri Jun 1 19:48:59 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 1 Jun 2007 19:48:59 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <71166b3b0706011640i4c731402td3f180b83952b24f@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> <167b6aa00706011147q3e4449e0rcdf5ba06cff7c007@mail.gmail.com> <57c63afe0706011501w6b48892ej654223495d956344@mail.gmail.com> <8d961d900706011559s1056a929i2a64758e2aa577e8@mail.gmail.com> <71166b3b0706011640i4c731402td3f180b83952b24f@mail.gmail.com> Message-ID: <57c63afe0706011648l7b96493cv6cabb962e0b21d0a@mail.gmail.com> On 6/1/07, Luis Lavena wrote: > On 6/1/07, aslak hellesoy wrote: > > > On 6/1/07, Joseph Method wrote: > > > > > > Well now we're getting much simpler. Instead of a whole new structure, > > > why not just use a custom matcher? > > > > > > http://pastie.caboo.se/67069 > > > > > > > Brilliant! > > > > I agree with aslak on this! > > Is descriptive, but not too verbose, is simple but not too cryptic. > > Translation: Looks good, are you willing to share it? ;-) > > (David and Aslak, I didn't found a example on how to implemente a > custom matcher like Jospeh did, guess I missed a lot of RDocs :-P Check this out - I think it's what you're looking for. http://blog.davidchelimsky.net/articles/2007/02/18/custom-expectation-matchers Cheers, David > > -- > Luis Lavena > Multimedia systems > - > Leaders are made, they are not born. They are made by hard effort, > which is the price which all of us must pay to achieve any goal that > is worthwhile. > Vince Lombardi > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From luislavena at gmail.com Fri Jun 1 19:54:32 2007 From: luislavena at gmail.com (Luis Lavena) Date: Fri, 1 Jun 2007 20:54:32 -0300 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <57c63afe0706011648l7b96493cv6cabb962e0b21d0a@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> <167b6aa00706011147q3e4449e0rcdf5ba06cff7c007@mail.gmail.com> <57c63afe0706011501w6b48892ej654223495d956344@mail.gmail.com> <8d961d900706011559s1056a929i2a64758e2aa577e8@mail.gmail.com> <71166b3b0706011640i4c731402td3f180b83952b24f@mail.gmail.com> <57c63afe0706011648l7b96493cv6cabb962e0b21d0a@mail.gmail.com> Message-ID: <71166b3b0706011654h48e3b72ft2709a3c12441da9e@mail.gmail.com> On 6/1/07, David Chelimsky wrote: [...] > > > > (David and Aslak, I didn't found a example on how to implemente a > > custom matcher like Jospeh did, guess I missed a lot of RDocs :-P > > Check this out - I think it's what you're looking for. > > http://blog.davidchelimsky.net/articles/2007/02/18/custom-expectation-matchers > Thanks David, but I'm already a subscriber of your blog ;-) What I really meant to say is the .as(:attribute).because("message") part of the custom matcher I didn't fully understand :-P Are examples of that in the repository? -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi From dchelimsky at gmail.com Sat Jun 2 00:19:20 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 2 Jun 2007 00:19:20 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <71166b3b0706011654h48e3b72ft2709a3c12441da9e@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> <167b6aa00706011147q3e4449e0rcdf5ba06cff7c007@mail.gmail.com> <57c63afe0706011501w6b48892ej654223495d956344@mail.gmail.com> <8d961d900706011559s1056a929i2a64758e2aa577e8@mail.gmail.com> <71166b3b0706011640i4c731402td3f180b83952b24f@mail.gmail.com> <57c63afe0706011648l7b96493cv6cabb962e0b21d0a@mail.gmail.com> <71166b3b0706011654h48e3b72ft2709a3c12441da9e@mail.gmail.com> Message-ID: <57c63afe0706012119v6195e4f4y112fe157e9797dfc@mail.gmail.com> On 6/1/07, Luis Lavena wrote: > On 6/1/07, David Chelimsky wrote: > [...] > > > > > > (David and Aslak, I didn't found a example on how to implemente a > > > custom matcher like Jospeh did, guess I missed a lot of RDocs :-P > > > > Check this out - I think it's what you're looking for. > > > > http://blog.davidchelimsky.net/articles/2007/02/18/custom-expectation-matchers > > > > Thanks David, but I'm already a subscriber of your blog ;-) > > What I really meant to say is the .as(:attribute).because("message") > part of the custom matcher I didn't fully understand :-P > > Are examples of that in the repository? Take a look at lib/spec/matchers/change.rb. That should give you some direction. > > -- > Luis Lavena > Multimedia systems > - > Leaders are made, they are not born. They are made by hard effort, > which is the price which all of us must pay to achieve any goal that > is worthwhile. > Vince Lombardi > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From daniel at danielfischer.com Sat Jun 2 04:27:32 2007 From: daniel at danielfischer.com (Fischer, Daniel) Date: Sat, 2 Jun 2007 01:27:32 -0700 Subject: [rspec-users] I'm really bad at controllers, help please. Message-ID: <7e565b5c0706020127m121fc734o10dc9b6cd763e635@mail.gmail.com> Hey, Sorry for so many questions - I'm really bad at this right now. I'm trying to cover the following code w/ rspec def index if params[:user_id] @user = User.find(params[:user_id]) @messages = @user.messages end end So basically what I'm doing is listing all the messages for a user, provided there is an id parameter. describe MessagesController, " handling GET /messages for a user" do before do @message = mock_model(Message) @message.stub!(:user_id).and_return(1) @user = mock_model(User) @user.stub!(:id).and_return(1) User.stub!(:messages).and_return([@message]) User.stub!(:find).and_return([@user]) end def do_get get :index, :user_id => 1 end it "should be successful" do do_get response.should be_success end it "should render index template" do do_get response.should render_template('index') end it "should find all messages" do User.should_receive(:messages).and_return([@message]) do_get end it "should assign the found messages for the view" do do_get assigns[:messages].should == [@message] end end I'm trying to use the basic scaffold spec, but I'm absolutely clueless on what the proper way to handle this is, I'm not even sure the proper way I should mock the messages method, so it'll return a "stub?" of a collection, or whatever the proper term is. I'm sorry you have to deal with a newb, but if you could really help me out I'd appreciate it a ton, thanks! -- -Daniel Fischer From arachnd at gmail.com Sat Jun 2 04:29:47 2007 From: arachnd at gmail.com (Fischer, Daniel) Date: Sat, 2 Jun 2007 01:29:47 -0700 Subject: [rspec-users] I'm really bad at controllers, help please. Message-ID: <7e565b5c0706020129k594e1be3r9b6230e70ec4c911@mail.gmail.com> Hey, Sorry for so many questions - I'm really bad at this right now. I'm trying to cover the following code w/ rspec def index if params[:user_id] @user = User.find(params[:user_id]) @messages = @user.messages end end So basically what I'm doing is listing all the messages for a user, provided there is an id parameter. describe MessagesController, " handling GET /messages for a user" do before do @message = mock_model(Message) @message.stub!(:user_id).and_return(1) @user = mock_model(User) @user.stub!(:id).and_return(1) User.stub!(:messages).and_return([@message]) User.stub!(:find).and_return([@user]) end def do_get get :index, :user_id => 1 end it "should be successful" do do_get response.should be_success end it "should render index template" do do_get response.should render_template('index') end it "should find all messages" do User.should_receive(:messages).and_return([@message]) do_get end it "should assign the found messages for the view" do do_get assigns[:messages].should == [@message] end end I'm trying to use the basic scaffold spec, but I'm absolutely clueless on what the proper way to handle this is, I'm not even sure the proper way I should mock the messages method, so it'll return a "stub?" of a collection, or whatever the proper term is. I'm sorry you have to deal with a newb, but if you could really help me out I'd appreciate it a ton, thanks! -Daniel Fischer http://www.danielfischer.com From daniel at danielfischer.com Sat Jun 2 04:31:21 2007 From: daniel at danielfischer.com (Fischer, Daniel) Date: Sat, 2 Jun 2007 01:31:21 -0700 Subject: [rspec-users] Could anyone please help with rspec/nested resource behavior checking? In-Reply-To: <84AC7EEA-6A4E-44B8-B2AD-D41CE5FF4488@parkerhill.com> References: <7e565b5c0705301703w334c3e2dg3f05d734ed76cd5a@mail.gmail.com> <1D95C70C-B551-43D3-AE07-5E7FFD9C5B74@parkerhill.com> <7e565b5c0705301807o42711e51w555ace5e8c037c84@mail.gmail.com> <84AC7EEA-6A4E-44B8-B2AD-D41CE5FF4488@parkerhill.com> Message-ID: <7e565b5c0706020131p11d0390didc67fb1eacf1d0ee@mail.gmail.com> Jonathon, Not sure - I don't really know what to do at this point, but I have a new problem again lol. Anyway, I can't seem to create new mailing messages? I guess I ask to many... Well, forgive me - but I'll just attach it here since I can't make a new one. Hey, Sorry for so many questions - I'm really bad at this right now. I'm trying to cover the following code w/ rspec def index if params[:user_id] @user = User.find(params[:user_id]) @messages = @user.messages end end So basically what I'm doing is listing all the messages for a user, provided there is an id parameter. describe MessagesController, " handling GET /messages for a user" do before do @message = mock_model(Message) @message.stub!(:user_id).and_return(1) @user = mock_model(User) @user.stub!(:id).and_return(1) User.stub!(:messages).and_return([@message]) User.stub!(:find).and_return([@user]) end def do_get get :index, :user_id => 1 end it "should be successful" do do_get response.should be_success end it "should render index template" do do_get response.should render_template('index') end it "should find all messages" do User.should_receive(:messages).and_return([@message]) do_get end it "should assign the found messages for the view" do do_get assigns[:messages].should == [@message] end end I'm trying to use the basic scaffold spec, but I'm absolutely clueless on what the proper way to handle this is, I'm not even sure the proper way I should mock the messages method, so it'll return a "stub?" of a collection, or whatever the proper term is. I'm sorry you have to deal with a newb, but if you could really help me out I'd appreciate it a ton, thanks! On 6/1/07, Jonathan Linowes wrote: > > I haven't thought it through (no pun intended) but maybe this could > be simplified and generalized , like add a ".through" to the stub and/ > or should_receive > ?? > > > On May 31, 2007, at 1:01 AM, Chris Anderson wrote: > > > I usually do something like this in my before(:each) section: > > > > User.stub!(:find).and_return(@u = mock_model(User, :posts => @pc = > > mock('posts collection'))) > > @pc.stub(:find).and_return([@p = mock_model(Post)]) > > > > with the corresponding should_receives in my various examples... the > > trick is to mock the user's posts collection as its own object. > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- -Daniel Fischer http://danielfischer.com - Geek Blog http://abigfisch.com - Portfolio http://writersbeat.com - Writing Community From dylans at gmail.com Fri Jun 1 19:30:19 2007 From: dylans at gmail.com (Dylan Stamat) Date: Fri, 1 Jun 2007 16:30:19 -0700 Subject: [rspec-users] redirect_to a relative path Message-ID: In a controller spec, doing something like: response.redirect_url.should == omglolsrofls_path ... fails, as so: expected "/omglolrofls", got "http://test.host/omglolrofls" (using ==) You can see that the http://test.host is prepended to the path. My controller is indeed redirecting to the omglolrofls path, and not the url. Is this expected ? Oh... and that's an arbitrary controller name if you were wondering ;) Thanks ! == Dylan From dchelimsky at gmail.com Sat Jun 2 09:25:19 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 2 Jun 2007 09:25:19 -0400 Subject: [rspec-users] redirect_to a relative path In-Reply-To: References: Message-ID: <57c63afe0706020625j355c2fe5gb78466c672948e46@mail.gmail.com> On 6/1/07, Dylan Stamat wrote: > In a controller spec, doing something like: > response.redirect_url.should == omglolsrofls_path > > ... fails, as so: > expected "/omglolrofls", got "http://test.host/omglolrofls" (using ==) > > You can see that the http://test.host is prepended to the path. > My controller is indeed redirecting to the omglolrofls path, and not > the url. > Is this expected ? That's how it's doc'd (http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Matchers.html#M000014). You can use omglolsrofls_url instead. If you think this should behave differently, feel free to submit a feature request: http://rubyforge.org/tracker/?group_id=797 Cheers (and welcome), David > > Oh... and that's an arbitrary controller name if you were wondering ;) > Thanks ! > == > Dylan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nick at ekenosen.net Sat Jun 2 10:32:51 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Sat, 2 Jun 2007 10:32:51 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <57c63afe0706011501w6b48892ej654223495d956344@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <57c63afe0705312200y274a4f43x966600bce6885d5a@mail.gmail.com> <276ff9870706010734q601c018bvc82dc1196d9da00c@mail.gmail.com> <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> <167b6aa00706011147q3e4449e0rcdf5ba06cff7c007@mail.gmail.com> <57c63afe0706011501w6b48892ej654223495d956344@mail.gmail.com> Message-ID: <276ff9870706020732y511e93aahd50b0fad62969fda@mail.gmail.com> On 6/1/07, David Chelimsky wrote: > Well now we're getting much simpler. Instead of a whole new structure, > why not just use a custom matcher? > > http://pastie.caboo.se/67069 I agree, simpler is better. I intend to start off with just the matcher, and then move towards a shortcut syntax. My nitpick with only doing a matcher and not doing some extras as well: it's still too verbose for my taste. For example, I'll be saying "as(:foo)" for every single example within a behavior, or wrapping it inside some examples_array.each loops will feel a bit clunky. The whole point was to cut away as much of the noise as possible, and focus only on the examples (and occasionally, the error messages). At any rate, I just put together my first draft implementation (developed spec-first). It still doesn't check the error messages yet, and it's only handling single fields at the moment, but I'll do those after I get home from the market. After that I'll figure out how to get it working with my desired "shortcut" syntax. Then I'll package it up all nicely for anyone to use... it's all in one file at the moment, so if you are looking to see the syntax that it enables, you'll have to scroll down to line 109. ;-) http://pastie.caboo.se/67222 I've included the output from "spec -f s" in the pastie. -- Nick From jonathan at parkerhill.com Sat Jun 2 15:09:31 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Sat, 2 Jun 2007 15:09:31 -0400 Subject: [rspec-users] I'm really bad at controllers, help please. In-Reply-To: <7e565b5c0706020127m121fc734o10dc9b6cd763e635@mail.gmail.com> References: <7e565b5c0706020127m121fc734o10dc9b6cd763e635@mail.gmail.com> Message-ID: <1BA71784-13D3-4086-9D71-0E46D43D8AE9@parkerhill.com> I'm nearly as new at this as you are I'm I'm just figuring things out myself too. I think your problem is method :messages is being called on an instance of User, not the class, so you need @user.stub!(:messages).and_return([@message]) here's some clues to how I've gotten similar things working To diagnose problems with my examples, I - watch the test.log file. You could use 'tail' or on mac use the 'console' utility - use the -e option in spec to run one example at a time. I copy/ paste the test name from the terminal window to avoid a lot of typing - sometimes I comment out code in my app methods to limit what its actually doing and then add one line at a time to "re-develop" the method - similarly I may create an extra test method in my controller or model to isolate things I dont understand between the spec and the code. I also tend to use should_receive rather than stubs, it provides more details (although seems to make the tests more brittle) thus, # separate for reuse with multiple describe cases def setup_messages do @user = mock_model(User) @message = mock_model(Message) @messages = [@message] end def before(:each) do setup_messages User.should_receive(:find).with("1").and_return(@user) @user.should_receive(:messages).and_return(@messages) end def do_get get :index, :user_id => 1 end it "should find all messages" do do_get assigns[:messages].should == @messages end I think this is right. Please let me know :) On Jun 2, 2007, at 4:27 AM, Fischer, Daniel wrote: > Hey, > > Sorry for so many questions - I'm really bad at this right now. > > I'm trying to cover the following code w/ rspec > > def index > if params[:user_id] > @user = User.find(params[:user_id]) > @messages = @user.messages > end > end > > So basically what I'm doing is listing all the messages for a user, > provided there is an id parameter. > > describe MessagesController, " handling GET /messages for a user" do > > before do > @message = mock_model(Message) > @message.stub!(:user_id).and_return(1) > @user = mock_model(User) > @user.stub!(:id).and_return(1) > User.stub!(:messages).and_return([@message]) > User.stub!(:find).and_return([@user]) > end > > def do_get > get :index, :user_id => 1 > end > > it "should be successful" do > do_get > response.should be_success > end > > it "should render index template" do > do_get > response.should render_template('index') > end > > it "should find all messages" do > User.should_receive(:messages).and_return([@message]) > do_get > end > > it "should assign the found messages for the view" do > do_get > assigns[:messages].should == [@message] > end > end > > > I'm trying to use the basic scaffold spec, but I'm absolutely clueless > on what the proper way to handle this is, I'm not even sure the proper > way I should mock the messages method, so it'll return a "stub?" of a > collection, or whatever the proper term is. > > I'm sorry you have to deal with a newb, but if you could really help > me out I'd appreciate it a ton, thanks! > -- > -Daniel Fischer > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jonathan at parkerhill.com Sat Jun 2 23:17:01 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Sat, 2 Jun 2007 23:17:01 -0400 Subject: [rspec-users] should_receive.again Message-ID: <9E413F4D-CAB0-445C-9A9C-28B11EAE3343@parkerhill.com> Hi, It appears that if I have 2 should_receives in a row, the latest one overrides the previous one(s). If there isn't one, could we add a way to accumulate them, such as @thing.should_receive(:method).and_return(@value) @thing.should_receive(:method).again.and_return(@value) @thing.should_receive(:method).again.and_return(@value) would be equivalent to @thing.should_receive(:method).times(3).and_return(@value) This would be helpful because I have a setup method that sets up the should_receive once, and then some specific actions may use that method one or more additional times. thanks linoj From jonathan at parkerhill.com Sat Jun 2 23:48:11 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Sat, 2 Jun 2007 23:48:11 -0400 Subject: [rspec-users] I'm really bad at controllers, help please. In-Reply-To: <1BA71784-13D3-4086-9D71-0E46D43D8AE9@parkerhill.com> References: <7e565b5c0706020127m121fc734o10dc9b6cd763e635@mail.gmail.com> <1BA71784-13D3-4086-9D71-0E46D43D8AE9@parkerhill.com> Message-ID: <581CFB5F-3C4A-4383-9E3E-74D609D1B177@parkerhill.com> fyi, i'm finding the should_receive(:messages) to be too brittle because any time I add a call like @user.messages.find or whatever it breaks my spec (requiring I do .twice or .times(N) . IMO the spec shouldn't be so sensitive to implementation of the behavior, so i'm now stubbing the association replaced @user.should_receive(:messages).and_return(@messages) with @user.stub!(:messages).and_return(@messages) On Jun 2, 2007, at 3:09 PM, Jonathan Linowes wrote: > I'm nearly as new at this as you are I'm I'm just figuring things out > myself too. > > I think your problem is method :messages is being called on an > instance of User, not the class, so you need > > @user.stub!(:messages).and_return([@message]) > > here's some clues to how I've gotten similar things working > To diagnose problems with my examples, I > - watch the test.log file. You could use 'tail' or on mac use the > 'console' utility > - use the -e option in spec to run one example at a time. I copy/ > paste the test name from the terminal window to avoid a lot of typing > - sometimes I comment out code in my app methods to limit what its > actually doing and then add one line at a time to "re-develop" the > method > - similarly I may create an extra test method in my controller or > model to isolate things I dont understand between the spec and the > code. > > I also tend to use should_receive rather than stubs, it provides more > details (although seems to make the tests more brittle) > > thus, > > # separate for reuse with multiple describe cases > def setup_messages do > @user = mock_model(User) > @message = mock_model(Message) > @messages = [@message] > end > > def before(:each) do > setup_messages > User.should_receive(:find).with("1").and_return(@user) > @user.should_receive(:messages).and_return(@messages) > end > > def do_get > get :index, :user_id => 1 > end > > it "should find all messages" do > do_get > assigns[:messages].should == @messages > end > > I think this is right. Please let me know > :) > > > On Jun 2, 2007, at 4:27 AM, Fischer, Daniel wrote: > >> Hey, >> >> Sorry for so many questions - I'm really bad at this right now. >> >> I'm trying to cover the following code w/ rspec >> >> def index >> if params[:user_id] >> @user = User.find(params[:user_id]) >> @messages = @user.messages >> end >> end >> >> So basically what I'm doing is listing all the messages for a user, >> provided there is an id parameter. >> >> describe MessagesController, " handling GET /messages for a user" do >> >> before do >> @message = mock_model(Message) >> @message.stub!(:user_id).and_return(1) >> @user = mock_model(User) >> @user.stub!(:id).and_return(1) >> User.stub!(:messages).and_return([@message]) >> User.stub!(:find).and_return([@user]) >> end >> >> def do_get >> get :index, :user_id => 1 >> end >> >> it "should be successful" do >> do_get >> response.should be_success >> end >> >> it "should render index template" do >> do_get >> response.should render_template('index') >> end >> >> it "should find all messages" do >> User.should_receive(:messages).and_return([@message]) >> do_get >> end >> >> it "should assign the found messages for the view" do >> do_get >> assigns[:messages].should == [@message] >> end >> end >> >> >> I'm trying to use the basic scaffold spec, but I'm absolutely >> clueless >> on what the proper way to handle this is, I'm not even sure the >> proper >> way I should mock the messages method, so it'll return a "stub?" of a >> collection, or whatever the proper term is. >> >> I'm sorry you have to deal with a newb, but if you could really help >> me out I'd appreciate it a ton, thanks! >> -- >> -Daniel Fischer >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Sun Jun 3 06:21:18 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sun, 3 Jun 2007 12:21:18 +0200 Subject: [rspec-users] should_receive.again In-Reply-To: <9E413F4D-CAB0-445C-9A9C-28B11EAE3343@parkerhill.com> References: <9E413F4D-CAB0-445C-9A9C-28B11EAE3343@parkerhill.com> Message-ID: <8d961d900706030321l2d5e1d5an953b06ddb40cd721@mail.gmail.com> On 6/3/07, Jonathan Linowes wrote: > Hi, > > It appears that if I have 2 should_receives in a row, the latest one > overrides the previous one(s). > > If there isn't one, could we add a way to accumulate them, such as > > @thing.should_receive(:method).and_return(@value) > @thing.should_receive(:method).again.and_return(@value) > @thing.should_receive(:method).again.and_return(@value) > > would be equivalent to > > @thing.should_receive(:method).times(3).and_return(@value) > > This would be helpful because I have a setup method that sets up the > should_receive once, and then some specific actions may use that > method one or more additional times. > @thing.should_receive(:method).exactly(3).times.and_return(@value) http://rspec.rubyforge.org/rdoc/classes/Spec/Mocks.html Aslak > thanks > linoj > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Jun 3 09:02:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 3 Jun 2007 08:02:37 -0500 Subject: [rspec-users] I'm really bad at controllers, help please. In-Reply-To: <581CFB5F-3C4A-4383-9E3E-74D609D1B177@parkerhill.com> References: <7e565b5c0706020127m121fc734o10dc9b6cd763e635@mail.gmail.com> <1BA71784-13D3-4086-9D71-0E46D43D8AE9@parkerhill.com> <581CFB5F-3C4A-4383-9E3E-74D609D1B177@parkerhill.com> Message-ID: <57c63afe0706030602k69f41fe3t910475947884762d@mail.gmail.com> On 6/2/07, Jonathan Linowes wrote: > fyi, i'm finding the should_receive(:messages) to be too brittle > because any time I add a call like @user.messages.find or whatever it > breaks my spec (requiring I do .twice or .times(N) . IMO the spec > shouldn't be so sensitive to implementation of the behavior, so i'm > now stubbing the association > > replaced > @user.should_receive(:messages).and_return(@messages) > with > @user.stub!(:messages).and_return(@messages) FYI - this: @user.stub!(:messages).and_return(@messages) functions in the same way as this: @user.should_receive(:messages).any_number_of_times.and_return(@messages) So you can alleviate the brittleness using should_receive. It's more verbose, BUT, the important thing is your intention. Stubs and mocks mean different things. http://blog.davidchelimsky.net/articles/2006/11/09/tutorial-rspec-stubs-and-mocks Cheers, David > > > > On Jun 2, 2007, at 3:09 PM, Jonathan Linowes wrote: > > > I'm nearly as new at this as you are I'm I'm just figuring things out > > myself too. > > > > I think your problem is method :messages is being called on an > > instance of User, not the class, so you need > > > > @user.stub!(:messages).and_return([@message]) > > > > here's some clues to how I've gotten similar things working > > To diagnose problems with my examples, I > > - watch the test.log file. You could use 'tail' or on mac use the > > 'console' utility > > - use the -e option in spec to run one example at a time. I copy/ > > paste the test name from the terminal window to avoid a lot of typing > > - sometimes I comment out code in my app methods to limit what its > > actually doing and then add one line at a time to "re-develop" the > > method > > - similarly I may create an extra test method in my controller or > > model to isolate things I dont understand between the spec and the > > code. > > > > I also tend to use should_receive rather than stubs, it provides more > > details (although seems to make the tests more brittle) > > > > thus, > > > > # separate for reuse with multiple describe cases > > def setup_messages do > > @user = mock_model(User) > > @message = mock_model(Message) > > @messages = [@message] > > end > > > > def before(:each) do > > setup_messages > > User.should_receive(:find).with("1").and_return(@user) > > @user.should_receive(:messages).and_return(@messages) > > end > > > > def do_get > > get :index, :user_id => 1 > > end > > > > it "should find all messages" do > > do_get > > assigns[:messages].should == @messages > > end > > > > I think this is right. Please let me know > > :) > > > > > > On Jun 2, 2007, at 4:27 AM, Fischer, Daniel wrote: > > > >> Hey, > >> > >> Sorry for so many questions - I'm really bad at this right now. > >> > >> I'm trying to cover the following code w/ rspec > >> > >> def index > >> if params[:user_id] > >> @user = User.find(params[:user_id]) > >> @messages = @user.messages > >> end > >> end > >> > >> So basically what I'm doing is listing all the messages for a user, > >> provided there is an id parameter. > >> > >> describe MessagesController, " handling GET /messages for a user" do > >> > >> before do > >> @message = mock_model(Message) > >> @message.stub!(:user_id).and_return(1) > >> @user = mock_model(User) > >> @user.stub!(:id).and_return(1) > >> User.stub!(:messages).and_return([@message]) > >> User.stub!(:find).and_return([@user]) > >> end > >> > >> def do_get > >> get :index, :user_id => 1 > >> end > >> > >> it "should be successful" do > >> do_get > >> response.should be_success > >> end > >> > >> it "should render index template" do > >> do_get > >> response.should render_template('index') > >> end > >> > >> it "should find all messages" do > >> User.should_receive(:messages).and_return([@message]) > >> do_get > >> end > >> > >> it "should assign the found messages for the view" do > >> do_get > >> assigns[:messages].should == [@message] > >> end > >> end > >> > >> > >> I'm trying to use the basic scaffold spec, but I'm absolutely > >> clueless > >> on what the proper way to handle this is, I'm not even sure the > >> proper > >> way I should mock the messages method, so it'll return a "stub?" of a > >> collection, or whatever the proper term is. > >> > >> I'm sorry you have to deal with a newb, but if you could really help > >> me out I'd appreciate it a ton, thanks! > >> -- > >> -Daniel Fischer > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From martin.emde at gmail.com Sun Jun 3 15:07:21 2007 From: martin.emde at gmail.com (Martin Emde) Date: Sun, 3 Jun 2007 13:07:21 -0600 Subject: [rspec-users] Could anyone please help with rspec/nested resource behavior checking? In-Reply-To: <7e565b5c0706020131p11d0390didc67fb1eacf1d0ee@mail.gmail.com> References: <7e565b5c0705301703w334c3e2dg3f05d734ed76cd5a@mail.gmail.com> <1D95C70C-B551-43D3-AE07-5E7FFD9C5B74@parkerhill.com> <7e565b5c0705301807o42711e51w555ace5e8c037c84@mail.gmail.com> <84AC7EEA-6A4E-44B8-B2AD-D41CE5FF4488@parkerhill.com> <7e565b5c0706020131p11d0390didc67fb1eacf1d0ee@mail.gmail.com> Message-ID: <145359ad0706031207w1e0ba44ajd77d6b3bc54070d2@mail.gmail.com> Here is the correct spec for this index action: def index if params[:user_id] @user = User.find(params[:user_id]) @messages = @user.messages end end describe MessagesController, " handling GET /messages for a user" do before do @user = mock_model(User) @messages = mock("messages") @user.stub!(:messages).and_return(@messages) User.stub!(:find).and_return(@user) end def do_get get :index, :user_id => 1 end it "should render index template" do do_get response.should render_template('index') end it "should find user with params[:user_id]" do User.should_receive(:find).with(1).and_return(@user) do_get end it "should get user's messages" do @user.should_receive(:messages).and_return(@messages) do_get end it "should assign the found messages for the view" do do_get assigns[:messages].should be(@messages) end end Hope that helps you out. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070603/011115a7/attachment.html From dchelimsky at gmail.com Sun Jun 3 15:55:50 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 3 Jun 2007 14:55:50 -0500 Subject: [rspec-users] Specs for ApplicationController, where to put them? In-Reply-To: References: <2D69A175-3C2A-4E38-A006-68695DF3E359@wincent.com> <050EF0F7-7EE3-4995-AFE3-0FD735F98167@digitalphenom.com> <583D179D-743C-49BB-9CFA-B31AF11C71E2@digitalphenom.com> <57c63afe0705291652r2bb1ea05o29ed4b4ec96e29ed@mail.gmail.com> Message-ID: <57c63afe0706031255g4f96cf7h1263e4b067167b26@mail.gmail.com> On 6/1/07, Anthony Carlos wrote: > > On May 29, 2007, at 7:52 PM, David Chelimsky wrote: > > >> My problem now, is that I get a nil object error. Specifically, in > >> application.rb, I'm trying to call request.parameters and request is > >> nil. It seems that request is not part of the context anymore since I > >> moved the behavior out to a separate file. How do I regain access to > >> request, response, assigns, flash, and session? > > > > The fact that the shared examples are in another file should have no > > bearing on whether they have runtime access to whatever is in the > > behaviours that include them. This all sounds odd to me. Can you post > > a backtrace please? > > David: > > Here's the output from rake spec:autotest: > > : > QuestionnairesController > - should flash notice when session[:current_user_id] does not exist > (ERROR - 1) > - should return true when session[:current_user_id] exists > - should respond to current_user > - should respond to authenticate > > 1) > NoMethodError in 'QuestionnairesController should flash notice when > session[:current_user_id] does not exist' > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.parameters > /Users/aec/ror/aca/aca_trunk/config/../app/controllers/application.rb: > 11:in `authenticate' > ./spec/controllers/application_controller_spec.rb:24: > > ===== > Here's application_controller_spec.rb: > require File.dirname(__FILE__) + '/../spec_helper' > > unless Spec::DSL::Behaviour.find_shared_behaviour("All controllers") > describe "All controllers", :shared => true do > it "should respond to authenticate" do > controller.should respond_to(:authenticate) > end > it "should respond to current_user" do > controller.should respond_to(:current_user) > end > it "should return true when session[:current_user_id] exists" do > session[:current_user_id] = 12345 > controller.authenticate.should == true > end > it "should flash notice when session[:current_user_id] does not > exist" do > session[:current_user_id] = nil > controller.authenticate # <===== This is line 24 where the > error occurs! > flash[:notice].should == 'Please login.' > end > end > end > > ===== > Here's application.rb: > class ApplicationController < ActionController::Base > # Pick a unique cookie name to distinguish our session data from > others' > session :session_key => '_unique_session_id' > > def authenticate > unless session[:current_user_id] > flash[:notice] = 'Please login.' > session[:jumpto] = request.parameters # <===== This is line 11 > where nil.parameters is called! > redirect_to(:controller => 'ums', :action => 'login') > end > true > end > > def current_user > @current_user = User.find(session[:current_user_id]) > end > end > > ===== > Finally, here's questionnaires_controller_spec.rb: > require File.dirname(__FILE__) + '/../spec_helper' > require File.dirname(__FILE__) + '/application_controller_spec' > unless Spec::DSL::Behaviour.find_shared_behaviour("All controllers") > > describe QuestionnairesController do > it_should_behave_like "All controllers" > end > : > > ===== > So as far as I can tell, my QuestionnairesController should behave > like "All controllers" which puts us at > application_controller_spec.rb. The first 3 examples pass, but the > fourth, which calls ApplicationController.authenticate, gives me the > nil object. But, isn't request an object that is always available to > controllers? > > Wait a second... > > There's no get or post command here! Maybe thats why request is nil? > I think so. Never mind! Sorry about the false alarm. I don't want to > be the boy who cried wolf. > > On the other hand, I think I avoided using get or post because this > is an abstract action that gets called by other concrete classes. So > how does one test logic in an abstract class? This question inspired me to write this blog post: http://blog.davidchelimsky.net/articles/2007/06/03/oxymoron-testing-behaviour-of-abstractions Feel free to comment directly on the blog. Cheers, David > Smells like a job for a > mock, of course?!? I'll look over the list archive-- I think other > people have asked this question before. > > Thanks for helping out the slow learners, > > -Anthony > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nick at ekenosen.net Sun Jun 3 22:19:54 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Sun, 3 Jun 2007 22:19:54 -0400 Subject: [rspec-users] should_receive.again In-Reply-To: <8d961d900706030321l2d5e1d5an953b06ddb40cd721@mail.gmail.com> References: <9E413F4D-CAB0-445C-9A9C-28B11EAE3343@parkerhill.com> <8d961d900706030321l2d5e1d5an953b06ddb40cd721@mail.gmail.com> Message-ID: <276ff9870706031919g76913dbdm4a0676b1fd714148@mail.gmail.com> On 6/3/07, aslak hellesoy wrote: > On 6/3/07, Jonathan Linowes wrote: > > This would be helpful because I have a setup method that sets up the > > should_receive once, and then some specific actions may use that > > method one or more additional times. > > @thing.should_receive(:method).exactly(3).times.and_return(@value) > http://rspec.rubyforge.org/rdoc/classes/Spec/Mocks.html You might also consider simply stubbing the method in your setup, and only specifying a number of times called in specific examples. Whenever reasonable, I try to follow the advice given by David Chelimsky and aim for no mock expectations in the setup and only one per example: http://blog.davidchelimsky.net/articles/2006/11/09/tutorial-rspec-stubs-and-mocks Also, you might want to think about whether or not you really should be locking down your specification to exactly three (or however many) calls. Without knowing your details I can't say for certain if this applies to you, but often the exact number of calls is an implementation detail that your spec doesn't need to worry about. If that's the case, I might loosen up the mock expectation a little bit by simply saying @thing.should_receive(:method).at_least(:once).and_return(@value) -- Nick From nick at ekenosen.net Sun Jun 3 22:52:04 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Sun, 3 Jun 2007 22:52:04 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <276ff9870706020732y511e93aahd50b0fad62969fda@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <276ff9870706010734q601c018bvc82dc1196d9da00c@mail.gmail.com> <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> <167b6aa00706011147q3e4449e0rcdf5ba06cff7c007@mail.gmail.com> <57c63afe0706011501w6b48892ej654223495d956344@mail.gmail.com> <276ff9870706020732y511e93aahd50b0fad62969fda@mail.gmail.com> Message-ID: <276ff9870706031952n67e5507clb22837e1da1cc3bb@mail.gmail.com> On 6/2/07, nicholas a. evans wrote: > At any rate, I just put together my first draft implementation > (developed spec-first). It still doesn't check the error messages > yet, and it's only handling single fields at the moment, but I'll do > those after I get home from the market. After that I'll figure out > how to get it working with my desired "shortcut" syntax. So I haven't gotten around to my preferred shortcut syntax yet, but I did add support to check for error messages and handle multiple fields, so it should be quite usable now. I took the approach that when specifying single field validations it only checks for errors on that field, but when specifying multi-field validations it checks for any errors on the object. That felt like simplest and least surprising solution to me. My specs assume that you can use sqlite3 (to do an in-memory DB). http://svn.ekenosen.net/public/rspec_validation_matcher/ http://pastie.caboo.se/67509 shows what it currently can do, as well as my current thoughts on how I would *really* like to be doing this. I'm eager to hear any comments on it. :-) -- Nick From anthony at digitalphenom.com Sun Jun 3 23:44:54 2007 From: anthony at digitalphenom.com (Anthony Carlos) Date: Sun, 3 Jun 2007 23:44:54 -0400 Subject: [rspec-users] Could anyone please help with rspec/nested resource behavior checking? In-Reply-To: <7e565b5c0706020131p11d0390didc67fb1eacf1d0ee@mail.gmail.com> References: <7e565b5c0705301703w334c3e2dg3f05d734ed76cd5a@mail.gmail.com> <1D95C70C-B551-43D3-AE07-5E7FFD9C5B74@parkerhill.com> <7e565b5c0705301807o42711e51w555ace5e8c037c84@mail.gmail.com> <84AC7EEA-6A4E-44B8-B2AD-D41CE5FF4488@parkerhill.com> <7e565b5c0706020131p11d0390didc67fb1eacf1d0ee@mail.gmail.com> Message-ID: <56384D1F-D586-4126-B7CE-50E36F79434E@digitalphenom.com> Daniel, Which of these examples is failing? Or, are you asking a more general question about how to use a mock or a stub? I'm going through my own pains trying to learn this stuff, so my perspective might be close to yours! Please scroll down; I have a couple of in-line questions for ya! On Jun 2, 2007, at 4:31 AM, Fischer, Daniel wrote: > Jonathon, > > Not sure - I don't really know what to do at this point, but I have a > new problem again lol. > > Anyway, I can't seem to create new mailing messages? I guess I ask > to many... > > Well, forgive me - but I'll just attach it here since I can't make > a new one. > > Hey, > > Sorry for so many questions - I'm really bad at this right now. > > I'm trying to cover the following code w/ rspec > > def index > if params[:user_id] > @user = User.find(params[:user_id]) > @messages = @user.messages > end > end > > So basically what I'm doing is listing all the messages for a user, > provided there is an id parameter. > > describe MessagesController, " handling GET /messages for a user" do > > before do > @message = mock_model(Message) > @message.stub!(:user_id).and_return(1) > @user = mock_model(User) > @user.stub!(:id).and_return(1) > User.stub!(:messages).and_return([@message]) > User.stub!(:find).and_return([@user]) > end > > def do_get > get :index, :user_id => 1 > end > > it "should be successful" do > do_get > response.should be_success > end > > it "should render index template" do > do_get > response.should render_template('index') > end > > it "should find all messages" do > User.should_receive(:messages).and_return([@message]) > do_get > end > > it "should assign the found messages for the view" do > do_get > assigns[:messages].should == [@message] > end > end > > > I'm trying to use the basic scaffold spec, but I'm absolutely clueless > on what the proper way to handle this is, I'm not even sure the proper > way I should mock the messages method, so it'll return a "stub?" of a > collection, or whatever the proper term is. > Can you tell me where you found the basic scaffold spec? I haven't seen it yet. I've been learning by studying the docs from the rspec site. Are you having a problem ensuring that the @messages variable in your controller has an array of messages after a GET? I think I can explain the use of a stub or mock if this is really your question. Thanks, -Anthony From jonathan at parkerhill.com Sun Jun 3 23:47:59 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Sun, 3 Jun 2007 23:47:59 -0400 Subject: [rspec-users] should_receive.again In-Reply-To: <276ff9870706031919g76913dbdm4a0676b1fd714148@mail.gmail.com> References: <9E413F4D-CAB0-445C-9A9C-28B11EAE3343@parkerhill.com> <8d961d900706030321l2d5e1d5an953b06ddb40cd721@mail.gmail.com> <276ff9870706031919g76913dbdm4a0676b1fd714148@mail.gmail.com> Message-ID: <260A5104-9CE8-4A2A-B155-1E20919FB733@parkerhill.com> The issue was the number of calls. I really only want to count the number of calls by the specific action. But there's a before filter which calls the same method. I couldn't stub out the before filter itself because it sets an instance variable used by the action. Does that make sense? So my example has to know more about the implementation than I would like. On Jun 3, 2007, at 10:19 PM, nicholas a. evans wrote: > On 6/3/07, aslak hellesoy wrote: >> On 6/3/07, Jonathan Linowes wrote: >>> This would be helpful because I have a setup method that sets up the >>> should_receive once, and then some specific actions may use that >>> method one or more additional times. >> >> @thing.should_receive(:method).exactly(3).times.and_return(@value) >> http://rspec.rubyforge.org/rdoc/classes/Spec/Mocks.html > > You might also consider simply stubbing the method in your setup, and > only specifying a number of times called in specific examples. > Whenever reasonable, I try to follow the advice given by David > Chelimsky and aim for no mock expectations in the setup and only one > per example: http://blog.davidchelimsky.net/articles/2006/11/09/ > tutorial-rspec-stubs-and-mocks > > Also, you might want to think about whether or not you really should > be locking down your specification to exactly three (or however many) > calls. Without knowing your details I can't say for certain if this > applies to you, but often the exact number of calls is an > implementation detail that your spec doesn't need to worry about. If > that's the case, I might loosen up the mock expectation a little bit > by simply saying > @thing.should_receive(:method).at_least(:once).and_return(@value) > > -- > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From anthony at digitalphenom.com Mon Jun 4 00:10:06 2007 From: anthony at digitalphenom.com (Anthony Carlos) Date: Mon, 4 Jun 2007 00:10:06 -0400 Subject: [rspec-users] Specs for ApplicationController, where to put them? In-Reply-To: <57c63afe0706031255g4f96cf7h1263e4b067167b26@mail.gmail.com> References: <2D69A175-3C2A-4E38-A006-68695DF3E359@wincent.com> <050EF0F7-7EE3-4995-AFE3-0FD735F98167@digitalphenom.com> <583D179D-743C-49BB-9CFA-B31AF11C71E2@digitalphenom.com> <57c63afe0705291652r2bb1ea05o29ed4b4ec96e29ed@mail.gmail.com> <57c63afe0706031255g4f96cf7h1263e4b067167b26@mail.gmail.com> Message-ID: <646A1FE4-73D2-42D4-B853-DEAEA8528D70@digitalphenom.com> David: I could have had a V8?!?! (For the young, that's a reference to the commercial for V8 fruit and vegetable juice where the actor slaps himself in the forehead wishing he drank the delicious and nutritious beverage instead of some other more stupid beverage choice). Thanks for the unbelievably clear explanation. I will comment on your blog. -Anthony On Jun 3, 2007, at 3:55 PM, David Chelimsky wrote: > On 6/1/07, Anthony Carlos wrote: >> >> On May 29, 2007, at 7:52 PM, David Chelimsky wrote: >> >>>> My problem now, is that I get a nil object error. Specifically, in >>>> application.rb, I'm trying to call request.parameters and >>>> request is >>>> nil. It seems that request is not part of the context anymore >>>> since I >>>> moved the behavior out to a separate file. How do I regain >>>> access to >>>> request, response, assigns, flash, and session? >>> >>> The fact that the shared examples are in another file should have no >>> bearing on whether they have runtime access to whatever is in the >>> behaviours that include them. This all sounds odd to me. Can you >>> post >>> a backtrace please? >> >> David: >> >> Here's the output from rake spec:autotest: >> >> : >> QuestionnairesController >> - should flash notice when session[:current_user_id] does not exist >> (ERROR - 1) >> - should return true when session[:current_user_id] exists >> - should respond to current_user >> - should respond to authenticate >> >> 1) >> NoMethodError in 'QuestionnairesController should flash notice when >> session[:current_user_id] does not exist' >> You have a nil object when you didn't expect it! >> The error occurred while evaluating nil.parameters >> /Users/aec/ror/aca/aca_trunk/config/../app/controllers/ >> application.rb: >> 11:in `authenticate' >> ./spec/controllers/application_controller_spec.rb:24: >> >> ===== >> Here's application_controller_spec.rb: >> require File.dirname(__FILE__) + '/../spec_helper' >> >> unless Spec::DSL::Behaviour.find_shared_behaviour("All controllers") >> describe "All controllers", :shared => true do >> it "should respond to authenticate" do >> controller.should respond_to(:authenticate) >> end >> it "should respond to current_user" do >> controller.should respond_to(:current_user) >> end >> it "should return true when session[:current_user_id] exists" do >> session[:current_user_id] = 12345 >> controller.authenticate.should == true >> end >> it "should flash notice when session[:current_user_id] does not >> exist" do >> session[:current_user_id] = nil >> controller.authenticate # <===== This is line 24 where the >> error occurs! >> flash[:notice].should == 'Please login.' >> end >> end >> end >> >> ===== >> Here's application.rb: >> class ApplicationController < ActionController::Base >> # Pick a unique cookie name to distinguish our session data from >> others' >> session :session_key => '_unique_session_id' >> >> def authenticate >> unless session[:current_user_id] >> flash[:notice] = 'Please login.' >> session[:jumpto] = request.parameters # <===== This is line 11 >> where nil.parameters is called! >> redirect_to(:controller => 'ums', :action => 'login') >> end >> true >> end >> >> def current_user >> @current_user = User.find(session[:current_user_id]) >> end >> end >> >> ===== >> Finally, here's questionnaires_controller_spec.rb: >> require File.dirname(__FILE__) + '/../spec_helper' >> require File.dirname(__FILE__) + '/application_controller_spec' >> unless Spec::DSL::Behaviour.find_shared_behaviour("All controllers") >> >> describe QuestionnairesController do >> it_should_behave_like "All controllers" >> end >> : >> >> ===== >> So as far as I can tell, my QuestionnairesController should behave >> like "All controllers" which puts us at >> application_controller_spec.rb. The first 3 examples pass, but the >> fourth, which calls ApplicationController.authenticate, gives me the >> nil object. But, isn't request an object that is always available to >> controllers? >> >> Wait a second... >> >> There's no get or post command here! Maybe thats why request is nil? >> I think so. Never mind! Sorry about the false alarm. I don't want to >> be the boy who cried wolf. >> >> On the other hand, I think I avoided using get or post because this >> is an abstract action that gets called by other concrete classes. So >> how does one test logic in an abstract class? > > This question inspired me to write this blog post: > > http://blog.davidchelimsky.net/articles/2007/06/03/oxymoron-testing- > behaviour-of-abstractions > > Feel free to comment directly on the blog. > > Cheers, > David > >> Smells like a job for a >> mock, of course?!? I'll look over the list archive-- I think other >> people have asked this question before. >> >> Thanks for helping out the slow learners, >> >> -Anthony >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Jun 4 00:36:10 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 3 Jun 2007 23:36:10 -0500 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <276ff9870706031952n67e5507clb22837e1da1cc3bb@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <276ff9870706010811s58a95c54x642296c18837fbee@mail.gmail.com> <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> <167b6aa00706011147q3e4449e0rcdf5ba06cff7c007@mail.gmail.com> <57c63afe0706011501w6b48892ej654223495d956344@mail.gmail.com> <276ff9870706020732y511e93aahd50b0fad62969fda@mail.gmail.com> <276ff9870706031952n67e5507clb22837e1da1cc3bb@mail.gmail.com> Message-ID: <57c63afe0706032136s1af39b1bq619714f7ef33bbe9@mail.gmail.com> On 6/3/07, nicholas a. evans wrote: > On 6/2/07, nicholas a. evans wrote: > > At any rate, I just put together my first draft implementation > > (developed spec-first). It still doesn't check the error messages > > yet, and it's only handling single fields at the moment, but I'll do > > those after I get home from the market. After that I'll figure out > > how to get it working with my desired "shortcut" syntax. > > So I haven't gotten around to my preferred shortcut syntax yet, but I > did add support to check for error messages and handle multiple > fields, so it should be quite usable now. I took the approach that > when specifying single field validations it only checks for errors on > that field, but when specifying multi-field validations it checks for > any errors on the object. That felt like simplest and least > surprising solution to me. My specs assume that you can use sqlite3 > (to do an in-memory DB). > > http://svn.ekenosen.net/public/rspec_validation_matcher/ > > http://pastie.caboo.se/67509 shows what it currently can do, as well > as my current thoughts on how I would *really* like to be doing this. > I'm eager to hear any comments on it. :-) Personally, I think @person.should accept("Danny", "Elfman") ;) > > -- > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From daniel at danielfischer.com Mon Jun 4 04:16:45 2007 From: daniel at danielfischer.com (Fischer, Daniel) Date: Mon, 4 Jun 2007 01:16:45 -0700 Subject: [rspec-users] I'm really bad at controllers, help please. In-Reply-To: <581CFB5F-3C4A-4383-9E3E-74D609D1B177@parkerhill.com> References: <7e565b5c0706020127m121fc734o10dc9b6cd763e635@mail.gmail.com> <1BA71784-13D3-4086-9D71-0E46D43D8AE9@parkerhill.com> <581CFB5F-3C4A-4383-9E3E-74D609D1B177@parkerhill.com> Message-ID: <7e565b5c0706040116q73948fccr488c89f3a6068122@mail.gmail.com> Jonathan, Thanks a lot - that accomplished what I wanted to do, and provided me with insight. I'm still having some sort of misunderstanding though, because I'm having an error like this now (in a different section though; this time regarding post: 2) Spec::Mocks::MockExpectationError in 'MessagesController handling POST /messages should create a new message' Mock 'Message_1026' received unexpected message :author_id= with (202018) /Users/sparta/Projects/work/idastudios/podff_machine/config/../app/controllers/messages_controller.rb:31:in `create' /Users/sparta/Projects/work/idastudios/podff_machine/config/../vendor/plugins/haml/lib/sass/plugin.rb:116:in `process_without_test' ./spec/controllers/messages_controller_spec.rb:206:in `do_post' ./spec/controllers/messages_controller_spec.rb:211: yet I've tried both Message.stub!(:author_id).and_return(1) and @ message.stub!(:author_id).and_return(1) why would it still fail after stubbing both possibilities? In my controller i'm calling @message.author_id = current_user.id Thanks! On 6/2/07, Jonathan Linowes wrote: > > fyi, i'm finding the should_receive(:messages) to be too brittle > because any time I add a call like @user.messages.find or whatever it > breaks my spec (requiring I do .twice or .times(N) . IMO the spec > shouldn't be so sensitive to implementation of the behavior, so i'm > now stubbing the association > > replaced > @user.should_receive(:messages).and_return(@messages) > with > @user.stub!(:messages).and_return(@messages) > > > > On Jun 2, 2007, at 3:09 PM, Jonathan Linowes wrote: > > > I'm nearly as new at this as you are I'm I'm just figuring things out > > myself too. > > > > I think your problem is method :messages is being called on an > > instance of User, not the class, so you need > > > > @user.stub!(:messages).and_return([@message]) > > > > here's some clues to how I've gotten similar things working > > To diagnose problems with my examples, I > > - watch the test.log file. You could use 'tail' or on mac use the > > 'console' utility > > - use the -e option in spec to run one example at a time. I copy/ > > paste the test name from the terminal window to avoid a lot of typing > > - sometimes I comment out code in my app methods to limit what its > > actually doing and then add one line at a time to "re-develop" the > > method > > - similarly I may create an extra test method in my controller or > > model to isolate things I dont understand between the spec and the > > code. > > > > I also tend to use should_receive rather than stubs, it provides more > > details (although seems to make the tests more brittle) > > > > thus, > > > > # separate for reuse with multiple describe cases > > def setup_messages do > > @user = mock_model(User) > > @message = mock_model(Message) > > @messages = [@message] > > end > > > > def before(:each) do > > setup_messages > > User.should_receive(:find).with("1").and_return(@user) > > @user.should_receive(:messages).and_return(@messages) > > end > > > > def do_get > > get :index, :user_id => 1 > > end > > > > it "should find all messages" do > > do_get > > assigns[:messages].should == @messages > > end > > > > I think this is right. Please let me know > > :) > > > > > > On Jun 2, 2007, at 4:27 AM, Fischer, Daniel wrote: > > > >> Hey, > >> > >> Sorry for so many questions - I'm really bad at this right now. > >> > >> I'm trying to cover the following code w/ rspec > >> > >> def index > >> if params[:user_id] > >> @user = User.find(params[:user_id]) > >> @messages = @user.messages > >> end > >> end > >> > >> So basically what I'm doing is listing all the messages for a user, > >> provided there is an id parameter. > >> > >> describe MessagesController, " handling GET /messages for a user" do > >> > >> before do > >> @message = mock_model(Message) > >> @message.stub!(:user_id).and_return(1) > >> @user = mock_model(User) > >> @user.stub!(:id).and_return(1) > >> User.stub!(:messages).and_return([@message]) > >> User.stub!(:find).and_return([@user]) > >> end > >> > >> def do_get > >> get :index, :user_id => 1 > >> end > >> > >> it "should be successful" do > >> do_get > >> response.should be_success > >> end > >> > >> it "should render index template" do > >> do_get > >> response.should render_template('index') > >> end > >> > >> it "should find all messages" do > >> User.should_receive(:messages).and_return([@message]) > >> do_get > >> end > >> > >> it "should assign the found messages for the view" do > >> do_get > >> assigns[:messages].should == [@message] > >> end > >> end > >> > >> > >> I'm trying to use the basic scaffold spec, but I'm absolutely > >> clueless > >> on what the proper way to handle this is, I'm not even sure the > >> proper > >> way I should mock the messages method, so it'll return a "stub?" of a > >> collection, or whatever the proper term is. > >> > >> I'm sorry you have to deal with a newb, but if you could really help > >> me out I'd appreciate it a ton, thanks! > >> -- > >> -Daniel Fischer > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- -Daniel Fischer http://danielfischer.com - Geek Blog http://abigfisch.com - Portfolio http://writersbeat.com - Writing Community -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070604/876c5339/attachment-0001.html From aslak.hellesoy at gmail.com Mon Jun 4 04:58:04 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 4 Jun 2007 10:58:04 +0200 Subject: [rspec-users] I'm really bad at controllers, help please. In-Reply-To: <7e565b5c0706040116q73948fccr488c89f3a6068122@mail.gmail.com> References: <7e565b5c0706020127m121fc734o10dc9b6cd763e635@mail.gmail.com> <1BA71784-13D3-4086-9D71-0E46D43D8AE9@parkerhill.com> <581CFB5F-3C4A-4383-9E3E-74D609D1B177@parkerhill.com> <7e565b5c0706040116q73948fccr488c89f3a6068122@mail.gmail.com> Message-ID: <8d961d900706040158u46a7e8a4jf8bd80be5f4c609f@mail.gmail.com> On 6/4/07, Fischer, Daniel wrote: > Jonathan, > > Thanks a lot - that accomplished what I wanted to do, and provided me with > insight. > > I'm still having some sort of misunderstanding though, because I'm having an > error like this now (in a different section though; this time regarding > post: > > 2) > Spec::Mocks::MockExpectationError in 'MessagesController > handling POST /messages should create a new message' > Mock 'Message_1026' received unexpected message :author_id= with (202018) > /Users/sparta/Projects/work/idastudios/podff_machine/config/../app/controllers/messages_controller.rb:31:in > `create' > /Users/sparta/Projects/work/idastudios/podff_machine/config/../vendor/plugins/haml/lib/sass/plugin.rb:116:in > `process_without_test' > ./spec/controllers/messages_controller_spec.rb:206:in > `do_post' > ./spec/controllers/messages_controller_spec.rb:211: > > yet I've tried both Message.stub!(:author_id).and_return(1) and > @message.stub!(:author_id).and_return(1) why would it still fail after > stubbing both possibilities? > You're stubbing the accessor (:author_id) instead of the accessor (:author_id=) Aslak > In my controller i'm calling @message.author_id = current_user.id > > Thanks! > > On 6/2/07, Jonathan Linowes wrote: > > fyi, i'm finding the should_receive(:messages) to be too brittle > > because any time I add a call like @ user.messages.find or whatever it > > breaks my spec (requiring I do .twice or .times(N) . IMO the spec > > shouldn't be so sensitive to implementation of the behavior, so i'm > > now stubbing the association > > > > replaced > > > @user.should_receive(:messages).and_return(@messages) > > with > > @user.stub!(:messages).and_return(@messages) > > > > > > > > On Jun 2, 2007, at 3:09 PM, Jonathan Linowes wrote: > > > > > I'm nearly as new at this as you are I'm I'm just figuring things out > > > myself too. > > > > > > I think your problem is method :messages is being called on an > > > instance of User, not the class, so you need > > > > > > @user.stub!(:messages).and_return([@message]) > > > > > > here's some clues to how I've gotten similar things working > > > To diagnose problems with my examples, I > > > - watch the test.log file. You could use 'tail' or on mac use the > > > 'console' utility > > > - use the -e option in spec to run one example at a time. I copy/ > > > paste the test name from the terminal window to avoid a lot of typing > > > - sometimes I comment out code in my app methods to limit what its > > > actually doing and then add one line at a time to "re-develop" the > > > method > > > - similarly I may create an extra test method in my controller or > > > model to isolate things I dont understand between the spec and the > > > code. > > > > > > I also tend to use should_receive rather than stubs, it provides more > > > details (although seems to make the tests more brittle) > > > > > > thus, > > > > > > # separate for reuse with multiple describe cases > > > def setup_messages do > > > @user = mock_model(User) > > > @message = mock_model(Message) > > > @messages = [@message] > > > end > > > > > > def before(:each) do > > > setup_messages > > > > User.should_receive(:find).with("1").and_return(@user) > > > > @user.should_receive(:messages).and_return(@messages) > > > end > > > > > > def do_get > > > get :index, :user_id => 1 > > > end > > > > > > it "should find all messages" do > > > do_get > > > assigns[:messages].should == @messages > > > end > > > > > > I think this is right. Please let me know > > > :) > > > > > > > > > On Jun 2, 2007, at 4:27 AM, Fischer, Daniel wrote: > > > > > >> Hey, > > >> > > >> Sorry for so many questions - I'm really bad at this right now. > > >> > > >> I'm trying to cover the following code w/ rspec > > >> > > >> def index > > >> if params[:user_id] > > >> @user = User.find(params[:user_id]) > > >> @messages = @user.messages > > >> end > > >> end > > >> > > >> So basically what I'm doing is listing all the messages for a user, > > >> provided there is an id parameter. > > >> > > >> describe MessagesController, " handling GET /messages for a user" do > > >> > > >> before do > > >> @message = mock_model(Message) > > >> @message.stub!(:user_id).and_return(1) > > >> @user = mock_model(User) > > >> @user.stub!(:id).and_return(1) > > >> User.stub!(:messages).and_return([@message]) > > >> User.stub!(:find).and_return([@user]) > > >> end > > >> > > >> def do_get > > >> get :index, :user_id => 1 > > >> end > > >> > > >> it "should be successful" do > > >> do_get > > >> response.should be_success > > >> end > > >> > > >> it "should render index template" do > > >> do_get > > >> response.should render_template('index') > > >> end > > >> > > >> it "should find all messages" do > > >> > User.should_receive(:messages).and_return([@message]) > > >> do_get > > >> end > > >> > > >> it "should assign the found messages for the view" do > > >> do_get > > >> assigns[:messages].should == [@message] > > >> end > > >> end > > >> > > >> > > >> I'm trying to use the basic scaffold spec, but I'm absolutely > > >> clueless > > >> on what the proper way to handle this is, I'm not even sure the > > >> proper > > >> way I should mock the messages method, so it'll return a "stub?" of a > > >> collection, or whatever the proper term is. > > >> > > >> I'm sorry you have to deal with a newb, but if you could really help > > >> me out I'd appreciate it a ton, thanks! > > >> -- > > >> -Daniel Fischer > > >> _______________________________________________ > > >> rspec-users mailing list > > >> rspec-users at rubyforge.org > > >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > -Daniel Fischer > > http://danielfischer.com - Geek Blog > http://abigfisch.com - Portfolio > http://writersbeat.com - Writing Community > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Mon Jun 4 04:59:01 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 4 Jun 2007 10:59:01 +0200 Subject: [rspec-users] I'm really bad at controllers, help please. In-Reply-To: <8d961d900706040158u46a7e8a4jf8bd80be5f4c609f@mail.gmail.com> References: <7e565b5c0706020127m121fc734o10dc9b6cd763e635@mail.gmail.com> <1BA71784-13D3-4086-9D71-0E46D43D8AE9@parkerhill.com> <581CFB5F-3C4A-4383-9E3E-74D609D1B177@parkerhill.com> <7e565b5c0706040116q73948fccr488c89f3a6068122@mail.gmail.com> <8d961d900706040158u46a7e8a4jf8bd80be5f4c609f@mail.gmail.com> Message-ID: <8d961d900706040159v7ed99935rc81f660f6b5114dd@mail.gmail.com> On 6/4/07, aslak hellesoy wrote: > On 6/4/07, Fischer, Daniel wrote: > > Jonathan, > > > > Thanks a lot - that accomplished what I wanted to do, and provided me with > > insight. > > > > I'm still having some sort of misunderstanding though, because I'm having an > > error like this now (in a different section though; this time regarding > > post: > > > > 2) > > Spec::Mocks::MockExpectationError in 'MessagesController > > handling POST /messages should create a new message' > > Mock 'Message_1026' received unexpected message :author_id= with (202018) > > /Users/sparta/Projects/work/idastudios/podff_machine/config/../app/controllers/messages_controller.rb:31:in > > `create' > > /Users/sparta/Projects/work/idastudios/podff_machine/config/../vendor/plugins/haml/lib/sass/plugin.rb:116:in > > `process_without_test' > > ./spec/controllers/messages_controller_spec.rb:206:in > > `do_post' > > ./spec/controllers/messages_controller_spec.rb:211: > > > > yet I've tried both Message.stub!(:author_id).and_return(1) and > > @message.stub!(:author_id).and_return(1) why would it still fail after > > stubbing both possibilities? > > > > You're stubbing the accessor (:author_id) instead of the accessor (:author_id=) I meant: You're stubbing the accessor (:author_id) instead of the mutator (:author_id=) Accessor == getter, mutator == setter. Aslak > > Aslak > > > In my controller i'm calling @message.author_id = current_user.id > > > > Thanks! > > > > On 6/2/07, Jonathan Linowes wrote: > > > fyi, i'm finding the should_receive(:messages) to be too brittle > > > because any time I add a call like @ user.messages.find or whatever it > > > breaks my spec (requiring I do .twice or .times(N) . IMO the spec > > > shouldn't be so sensitive to implementation of the behavior, so i'm > > > now stubbing the association > > > > > > replaced > > > > > @user.should_receive(:messages).and_return(@messages) > > > with > > > @user.stub!(:messages).and_return(@messages) > > > > > > > > > > > > On Jun 2, 2007, at 3:09 PM, Jonathan Linowes wrote: > > > > > > > I'm nearly as new at this as you are I'm I'm just figuring things out > > > > myself too. > > > > > > > > I think your problem is method :messages is being called on an > > > > instance of User, not the class, so you need > > > > > > > > @user.stub!(:messages).and_return([@message]) > > > > > > > > here's some clues to how I've gotten similar things working > > > > To diagnose problems with my examples, I > > > > - watch the test.log file. You could use 'tail' or on mac use the > > > > 'console' utility > > > > - use the -e option in spec to run one example at a time. I copy/ > > > > paste the test name from the terminal window to avoid a lot of typing > > > > - sometimes I comment out code in my app methods to limit what its > > > > actually doing and then add one line at a time to "re-develop" the > > > > method > > > > - similarly I may create an extra test method in my controller or > > > > model to isolate things I dont understand between the spec and the > > > > code. > > > > > > > > I also tend to use should_receive rather than stubs, it provides more > > > > details (although seems to make the tests more brittle) > > > > > > > > thus, > > > > > > > > # separate for reuse with multiple describe cases > > > > def setup_messages do > > > > @user = mock_model(User) > > > > @message = mock_model(Message) > > > > @messages = [@message] > > > > end > > > > > > > > def before(:each) do > > > > setup_messages > > > > > > User.should_receive(:find).with("1").and_return(@user) > > > > > > @user.should_receive(:messages).and_return(@messages) > > > > end > > > > > > > > def do_get > > > > get :index, :user_id => 1 > > > > end > > > > > > > > it "should find all messages" do > > > > do_get > > > > assigns[:messages].should == @messages > > > > end > > > > > > > > I think this is right. Please let me know > > > > :) > > > > > > > > > > > > On Jun 2, 2007, at 4:27 AM, Fischer, Daniel wrote: > > > > > > > >> Hey, > > > >> > > > >> Sorry for so many questions - I'm really bad at this right now. > > > >> > > > >> I'm trying to cover the following code w/ rspec > > > >> > > > >> def index > > > >> if params[:user_id] > > > >> @user = User.find(params[:user_id]) > > > >> @messages = @user.messages > > > >> end > > > >> end > > > >> > > > >> So basically what I'm doing is listing all the messages for a user, > > > >> provided there is an id parameter. > > > >> > > > >> describe MessagesController, " handling GET /messages for a user" do > > > >> > > > >> before do > > > >> @message = mock_model(Message) > > > >> @message.stub!(:user_id).and_return(1) > > > >> @user = mock_model(User) > > > >> @user.stub!(:id).and_return(1) > > > >> User.stub!(:messages).and_return([@message]) > > > >> User.stub!(:find).and_return([@user]) > > > >> end > > > >> > > > >> def do_get > > > >> get :index, :user_id => 1 > > > >> end > > > >> > > > >> it "should be successful" do > > > >> do_get > > > >> response.should be_success > > > >> end > > > >> > > > >> it "should render index template" do > > > >> do_get > > > >> response.should render_template('index') > > > >> end > > > >> > > > >> it "should find all messages" do > > > >> > > User.should_receive(:messages).and_return([@message]) > > > >> do_get > > > >> end > > > >> > > > >> it "should assign the found messages for the view" do > > > >> do_get > > > >> assigns[:messages].should == [@message] > > > >> end > > > >> end > > > >> > > > >> > > > >> I'm trying to use the basic scaffold spec, but I'm absolutely > > > >> clueless > > > >> on what the proper way to handle this is, I'm not even sure the > > > >> proper > > > >> way I should mock the messages method, so it'll return a "stub?" of a > > > >> collection, or whatever the proper term is. > > > >> > > > >> I'm sorry you have to deal with a newb, but if you could really help > > > >> me out I'd appreciate it a ton, thanks! > > > >> -- > > > >> -Daniel Fischer > > > >> _______________________________________________ > > > >> rspec-users mailing list > > > >> rspec-users at rubyforge.org > > > >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > -Daniel Fischer > > > > http://danielfischer.com - Geek Blog > > http://abigfisch.com - Portfolio > > http://writersbeat.com - Writing Community > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From nick at ekenosen.net Mon Jun 4 06:50:56 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Mon, 4 Jun 2007 06:50:56 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <57c63afe0706032136s1af39b1bq619714f7ef33bbe9@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <167b6aa00706010917h740ca9d4k20d543d7c11da8f8@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> <167b6aa00706011147q3e4449e0rcdf5ba06cff7c007@mail.gmail.com> <57c63afe0706011501w6b48892ej654223495d956344@mail.gmail.com> <276ff9870706020732y511e93aahd50b0fad62969fda@mail.gmail.com> <276ff9870706031952n67e5507clb22837e1da1cc3bb@mail.gmail.com> <57c63afe0706032136s1af39b1bq619714f7ef33bbe9@mail.gmail.com> Message-ID: <276ff9870706040350p59986988l9cf45b982fd6511b@mail.gmail.com> On 6/4/07, David Chelimsky wrote: > Personally, I think @person.should accept("Danny", "Elfman") > > ;) I totally agree, but arbitrary examples aren't my forte. Perhaps I should have stuck with "foo bar", but I had Oingo Boingo on the brain. ;-) -- Nick From dchelimsky at gmail.com Mon Jun 4 07:19:05 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 4 Jun 2007 06:19:05 -0500 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <276ff9870706040350p59986988l9cf45b982fd6511b@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <276ff9870706011002m37cdd8edof459546602c8a3cd@mail.gmail.com> <167b6aa00706011019n46e3471dy6c0a526de1e31318@mail.gmail.com> <276ff9870706011116o714208f4yc8e7243af7b774bb@mail.gmail.com> <167b6aa00706011147q3e4449e0rcdf5ba06cff7c007@mail.gmail.com> <57c63afe0706011501w6b48892ej654223495d956344@mail.gmail.com> <276ff9870706020732y511e93aahd50b0fad62969fda@mail.gmail.com> <276ff9870706031952n67e5507clb22837e1da1cc3bb@mail.gmail.com> <57c63afe0706032136s1af39b1bq619714f7ef33bbe9@mail.gmail.com> <276ff9870706040350p59986988l9cf45b982fd6511b@mail.gmail.com> Message-ID: <57c63afe0706040419y5884f007jc8ea809a9de2e26a@mail.gmail.com> On 6/4/07, nicholas a. evans wrote: > On 6/4/07, David Chelimsky wrote: > > Personally, I think @person.should accept("Danny", "Elfman") > > > > ;) > > I totally agree, but arbitrary examples aren't my forte. Perhaps I > should have stuck with "foo bar", but I had Oingo Boingo on the brain. > ;-) I'm with you re: arbitrary examples. I always have to imagine that "foo" is the "foo" bird from an old joke and "bar" is the local watering hole in order to understand such examples. I've you're going to pick things to reject, maybe they should be stuff we can all agree on: @developer.should reject("Service", "Locator") WDYT? > > -- > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From martindemello at gmail.com Mon Jun 4 09:05:45 2007 From: martindemello at gmail.com (Martin DeMello) Date: Mon, 4 Jun 2007 18:35:45 +0530 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> Message-ID: On 6/1/07, nicholas a. evans wrote: > > So here's my latest thought-experiment: http://pastie.caboo.se/66478 > And also, a simpler multi-field version: http://pastie.caboo.se/66510 > > Notice how checking all three sides of each boundary is so simple and > succinct that there is almost no excuse not to do so. Also, after > noticing how similar the multi-field validation is to a fit-table or > some of Brian Marick and zenspider's recent blog entries, I decided > that further simplification was necessary/desirable. :-) I really like the second one, far more than any of the proposed alternatives (I think succinctness beats out rspecishness in this case). I'd propose one modification: http://pastie.caboo.se/67596 What say? martin From kihlbom at gmail.com Mon Jun 4 09:18:22 2007 From: kihlbom at gmail.com (Carl-Johan Kihlbom) Date: Mon, 4 Jun 2007 15:18:22 +0200 Subject: [rspec-users] content_for In-Reply-To: <60f3810c0705230800t68a92739j8c4d2ec9b993b5ed@mail.gmail.com> References: <60f3810c0705230800t68a92739j8c4d2ec9b993b5ed@mail.gmail.com> Message-ID: On 5/23/07, Kyle Hargraves wrote: > Any ideas how I would go about writing specs for views which make use > of content_for? > > I'd like, for example, to be able to specify that ABC view places XYZ > in the sidebar, which I do using content_for(:sidebar). > > Am I missing something obvious? > > Kyle I have the same problem, several of my views use content_for to populate a sidebar. How can I write examples for them? / CJ From moses.hohman at gmail.com Mon Jun 4 10:50:27 2007 From: moses.hohman at gmail.com (Moses Hohman) Date: Mon, 4 Jun 2007 07:50:27 -0700 Subject: [rspec-users] content_for In-Reply-To: References: <60f3810c0705230800t68a92739j8c4d2ec9b993b5ed@mail.gmail.com> Message-ID: <425146b90706040750p7993df52l71dbcccb0b6053c5@mail.gmail.com> What we usually do in this case is render the view with the layout and then check the contents of the sidebar div. However, this does lead to having to stub out additional things you don't care about in your example. If anyone has a better plan I'd like to know, too. Moses On 6/4/07, Carl-Johan Kihlbom wrote: > > On 5/23/07, Kyle Hargraves wrote: > > Any ideas how I would go about writing specs for views which make use > > of content_for? > > > > I'd like, for example, to be able to specify that ABC view places XYZ > > in the sidebar, which I do using content_for(:sidebar). > > > > Am I missing something obvious? > > > > Kyle > > I have the same problem, several of my views use content_for to > populate a sidebar. How can I write examples for them? > > / CJ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070604/4a88e440/attachment-0001.html From francois.beausoleil at gmail.com Mon Jun 4 11:55:57 2007 From: francois.beausoleil at gmail.com (=?UTF-8?Q?Fran=C3=A7ois_Beausoleil?=) Date: Mon, 4 Jun 2007 11:55:57 -0400 Subject: [rspec-users] shared descriptions -- a couple of issues In-Reply-To: <7075BF68-D674-47C1-A8DA-FC6EC339431E@mydigitallife.com> References: <57c63afe0705101027y5b91054cwbfcd18619f8b003b@mail.gmail.com> <7075BF68-D674-47C1-A8DA-FC6EC339431E@mydigitallife.com> Message-ID: <41d5fadf0706040855t7a6663ddwe3893b5208d38f87@mail.gmail.com> Hi ! 2007/5/10, Greg Spurrier : > > > > You've got it right. Shared descriptions are brand new, so yes, still > > rough around the edges. Please submit RFEs for both issues (separate > > please). > > Perfectly understandable. Will do. Greg, did you end up creating the RFEs ? I can't find them, and I just got hit by the duplicate shared behaviour problem. Thanks ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From dchelimsky at gmail.com Mon Jun 4 12:04:16 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 4 Jun 2007 11:04:16 -0500 Subject: [rspec-users] shared descriptions -- a couple of issues In-Reply-To: <41d5fadf0706040855t7a6663ddwe3893b5208d38f87@mail.gmail.com> References: <57c63afe0705101027y5b91054cwbfcd18619f8b003b@mail.gmail.com> <7075BF68-D674-47C1-A8DA-FC6EC339431E@mydigitallife.com> <41d5fadf0706040855t7a6663ddwe3893b5208d38f87@mail.gmail.com> Message-ID: <57c63afe0706040904x1987f941t7ce8efc816f40835@mail.gmail.com> On 6/4/07, Fran?ois Beausoleil wrote: > Hi ! > > 2007/5/10, Greg Spurrier : > > > > > > You've got it right. Shared descriptions are brand new, so yes, still > > > rough around the edges. Please submit RFEs for both issues (separate > > > please). > > > > Perfectly understandable. Will do. > > Greg, did you end up creating the RFEs ? I can't find them, and I > just got hit by the duplicate shared behaviour problem. This is all resolved in the current trunk. > > Thanks ! > -- > Fran?ois Beausoleil > http://blog.teksol.info/ > http://piston.rubyforge.org/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From tristil at gmail.com Mon Jun 4 12:13:03 2007 From: tristil at gmail.com (Joseph Method) Date: Mon, 4 Jun 2007 12:13:03 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> Message-ID: <167b6aa00706040913q431af40bu2f919e1b4eb1bcdb@mail.gmail.com> I think Nicholas has moved on to a different approach, but I agree that this approach deserves looking at again, in part because it avoids the opinion about whether a single validation should be a context or a specification. But lo, rspecishness can be preserved: http://pastie.caboo.se/67649 IMO, not doing this makes it look declarative and unit/test-y. It's the difference between obey!(:me) and you.should obey(:me) > I really like the second one, far more than any of the proposed > alternatives (I think succinctness beats out rspecishness in this > case). I'd propose one modification: > > http://pastie.caboo.se/67596 > > What say? > > martin -- -J. Method From nick at ekenosen.net Mon Jun 4 14:03:21 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Mon, 4 Jun 2007 14:03:21 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <167b6aa00706040913q431af40bu2f919e1b4eb1bcdb@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <167b6aa00706040913q431af40bu2f919e1b4eb1bcdb@mail.gmail.com> Message-ID: <276ff9870706041103y3936734fj65d1cd052ff75fd2@mail.gmail.com> On 6/4/07, Joseph Method wrote: > I think Nicholas has moved on to a different approach, but I agree > that this approach deserves looking at again, Not yet... I'm just jumping about from one to the other, trying each on for size. ;-) After all of this typing, I wanted to get *something* implemented though. And going with a normal rspec matcher is really the correct starting point. It's useful even if/when we have an additional shortcut syntax, it should be used to implement the shortcut syntax, and there seemed to be some level of consensus finally settling on what it might look like. I wrote this up several hours ago, but never posted it: http://pastie.caboo.se/67605 It looks a lot like your example (and Martin's, which prompted me to write it). I'm still avoiding the dot and space notation, because that relies on code that works in the example binding, but I don't want to mess with in the behavior binding. I'm also avoiding sending a variable into the block because it feels to me like extra verbosity with no extra readability or useful flexibility. I haven't decided whether I like "should_accept" more than "it_should_accept"... the saved three characters are probably not be worth the delta from the rspec way. > in part because it > avoids the opinion about whether a single validation should be a > context or a specification. That is a good point. > But lo, rspecishness can be preserved: > > http://pastie.caboo.se/67649 > > IMO, not doing this makes it look declarative and unit/test-y. It's > the difference between > > obey!(:me) > > and > > you.should obey(:me) I strongly agree. I will gladly sacrifice a little bit of concision in order to stay in the rspec readability/behavior/specification paradigm. But I do want to (as much as is possible) remain in The Rspec Way with as little verbosity and noise distracting from the examples as is reasonable. David, Aslak, oh wise guardians and mentors of The Rspec Way, what do you think of my latest pastie? http://pastie.caboo.se/67605 :-) -- Nick From francois.beausoleil at gmail.com Mon Jun 4 15:09:10 2007 From: francois.beausoleil at gmail.com (=?UTF-8?Q?Fran=C3=A7ois_Beausoleil?=) Date: Mon, 4 Jun 2007 15:09:10 -0400 Subject: [rspec-users] shared descriptions -- a couple of issues In-Reply-To: <57c63afe0706040904x1987f941t7ce8efc816f40835@mail.gmail.com> References: <57c63afe0705101027y5b91054cwbfcd18619f8b003b@mail.gmail.com> <7075BF68-D674-47C1-A8DA-FC6EC339431E@mydigitallife.com> <41d5fadf0706040855t7a6663ddwe3893b5208d38f87@mail.gmail.com> <57c63afe0706040904x1987f941t7ce8efc816f40835@mail.gmail.com> Message-ID: <41d5fadf0706041209p36000edbr36d439b6e8547eaf@mail.gmail.com> Hello David, 2007/6/4, David Chelimsky : > This is all resolved in the current trunk. Was 1.0.4 cut from the current trunk ? Because I get the same errors as Greg: $ rake spec (in /home/francois/src/xlsuite.com) /home/francois/src/xlsuite.com/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:10:in `add_shared_behaviour': Shared Behaviour 'All controllers' already exists (ArgumentError) from /home/francois/src/xlsuite.com/vendor/plugins/rspec/lib/spec/runner/extensions/kernel.rb:36:in `register_behaviour' from /home/francois/src/xlsuite.com/vendor/plugins/rspec/lib/spec/runner/extensions/kernel.rb:24:in `describe' from ./spec/controllers/../xl_suite/spec_helpers.rb:94 from /home/francois/src/xlsuite.com/vendor/plugins/plugin_dependencies/lib/plugin_dependencies/extensions/kernel.rb:14:in `gem_original_require_without_plugins' from /home/francois/src/xlsuite.com/vendor/plugins/plugin_dependencies/lib/plugin_dependencies/extensions/kernel.rb:14:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' from /home/francois/src/xlsuite.com/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:495:in `require' from /home/francois/src/xlsuite.com/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in' ... 29 levels... from /home/francois/src/xlsuite.com/vendor/plugins/rspec/lib/spec/runner/option_parser.rb:154:in `parse' from /home/francois/src/xlsuite.com/vendor/plugins/rspec/lib/spec/runner/option_parser.rb:88:in `create_behaviour_runner' from /home/francois/src/xlsuite.com/vendor/plugins/rspec/lib/spec/runner/command_line.rb:14:in `run' from /home/francois/src/xlsuite.com/vendor/plugins/rspec/bin/spec:3 rake aborted! Command ruby -I"/home/francois/src/xlsuite.com/vendor/plugins/rspec/lib" "/home/francois/src/xlsuite.com/vendor/plugins/rspec/bin/spec" "spec/views/futures/show_spec.rb" "spec/views/rets/index_view_spec.rb" "spec/views/rets/import_view_spec.rb" "spec/views/rets/search_view_spec.rb" "spec/views/rets/results_view_spec.rb" "spec/views/rets/done_view_spec.rb" "spec/views/forum_categories/index_spec.rb" "spec/controllers/forum_categories_spec.rb" "spec/controllers/posts_controller_spec.rb" "spec/controllers/listings_controller_spec.rb" "spec/controllers/futures_controller_spec.rb" "spec/controllers/rets_controller_spec.rb" "spec/models/future_spec.rb" "spec/models/recurring_future_spec.rb" "spec/helpers/futures_helper_spec.rb" "spec/helpers/rets_helper_spec.rb" --options "/home/francois/src/xlsuite.com/config/../spec/spec.opts" failed (See full trace by running task with --trace) $ spec spec/ /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.4/lib/spec/dsl/behaviour.rb:10:in `add_shared_behaviour': Shared Behaviour 'All controllers' already exists (ArgumentError) from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.4/lib/spec/runner/extensions/kernel.rb:36:in `register_behaviour' from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.4/lib/spec/runner/extensions/kernel.rb:24:in `describe' from ./spec//controllers/../xl_suite/spec_helpers.rb:94 from /home/francois/src/xlsuite.com/vendor/plugins/plugin_dependencies/lib/plugin_dependencies/extensions/kernel.rb:14:in `gem_original_require_without_plugins' from /home/francois/src/xlsuite.com/vendor/plugins/plugin_dependencies/lib/plugin_dependencies/extensions/kernel.rb:14:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' from /home/francois/src/xlsuite.com/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:495:in `require' from /home/francois/src/xlsuite.com/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in' ... 31 levels... from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.4/lib/spec/runner/command_line.rb:14:in `run' from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.4/bin/spec:3 from /usr/local/bin/spec:16:in `load' from /usr/local/bin/spec:16 $ spec spec/models/ .................................. Finished in 1.899439 seconds 34 examples, 0 failures My shared behaviors are specified in file spec/xl_suite/spec_helpers.rb, module XlSuite::SpecHelpers. Thanks ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From tristil at gmail.com Mon Jun 4 15:37:23 2007 From: tristil at gmail.com (Joseph Method) Date: Mon, 4 Jun 2007 15:37:23 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <276ff9870706041103y3936734fj65d1cd052ff75fd2@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <167b6aa00706040913q431af40bu2f919e1b4eb1bcdb@mail.gmail.com> <276ff9870706041103y3936734fj65d1cd052ff75fd2@mail.gmail.com> Message-ID: <167b6aa00706041237ka7ea283g82676c73da2849c0@mail.gmail.com> This looks right. One thing: I think validation_for inserts behaviors into the example. I mean, that's how I think it should be implemented. The question is, how many are there in the first example? How about 3? That is: - Person validates :firstname (not nil, "foo" okay, not "bar") - Person validates :firstname should reject "" with 'can't be blank' message - Person "should reject a super long firstname" The .because("should reject a super long firstname") syntax in my example would be equivalent to the third example. > I strongly agree. I will gladly sacrifice a little bit of concision > in order to stay in the rspec readability/behavior/specification > paradigm. But I do want to (as much as is possible) remain in The > Rspec Way with as little verbosity and noise distracting from the > examples as is reasonable. David, Aslak, oh wise guardians and > mentors of The Rspec Way, what do you think of my latest pastie? > http://pastie.caboo.se/67605 :-) > > -- > Nick -- -J. Method From linojon at gmail.com Mon Jun 4 16:01:31 2007 From: linojon at gmail.com (Jonathan Linowes) Date: Mon, 4 Jun 2007 16:01:31 -0400 Subject: [rspec-users] rspec In-Reply-To: <1180961450.419229.191440@o5g2000hsb.googlegroups.com> References: <1180961450.419229.191440@o5g2000hsb.googlegroups.com> Message-ID: <6026E3DA-743E-41B6-A38B-84EB338E7C97@gmail.com> I have it working, in part, on a couple of my controllers, included a nested resource one. Then I decided to try and make a spec for the make_resourceful test included with the plugin. I started with the people_controller_spec.rb . There are some questions (see source), especially the xml. To get the test going I installed rspec, run script/generate rspec To begin with a default spec, i ran $ script/generate rspec_scaffold person and do not overwrite files I'll keep working on this a bit at a time. I really want to get the nested resource controllers going too. But if anyone has answers to the issues I've run into so far, please let me know. I've attached a copy of the people_controller_spec.rb , and for reference the people_controller.rb file too (I'm also cross-posting this on the rspec list) linoj -------------- next part -------------- A non-text attachment was scrubbed... Name: people_controller.rb Type: text/x-ruby-script Size: 870 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20070604/cbebb73d/attachment-0002.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: people_controller_spec.rb Type: text/x-ruby-script Size: 8345 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20070604/cbebb73d/attachment-0003.bin -------------- next part -------------- On Jun 4, 2007, at 8:50 AM, Robert Dempsey wrote: > > Jonathan, > > I am in the same boat as you are. Hopefully someone has it working :) > > Rob > > On Jun 4, 4:44 am, Jonathan Linowes wrote: >> Anyone here using rspec with make_resourceful? >> I could really use some sample specs, >> I've been having trouble mocking and stubbing the controller actions. >> >> Thanks. >> linoj > > > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google > Groups "make_resourceful" group. > To post to this group, send email to make_resourceful at googlegroups.com > To unsubscribe from this group, send email to make_resourceful- > unsubscribe at googlegroups.com > For more options, visit this group at http://groups.google.com/ > group/make_resourceful?hl=en > -~----------~----~----~----~------~----~------~--~--- > From nick at ekenosen.net Mon Jun 4 18:45:43 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Mon, 4 Jun 2007 18:45:43 -0400 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <167b6aa00706041237ka7ea283g82676c73da2849c0@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <167b6aa00706040913q431af40bu2f919e1b4eb1bcdb@mail.gmail.com> <276ff9870706041103y3936734fj65d1cd052ff75fd2@mail.gmail.com> <167b6aa00706041237ka7ea283g82676c73da2849c0@mail.gmail.com> Message-ID: <276ff9870706041545u15a5e10erb3bf90fc48aa1865@mail.gmail.com> On 6/4/07, Joseph Method wrote: > This looks right. One thing: I think validation_for inserts behaviors > into the example. I mean, that's how I think it should be implemented. > The question is, how many are there in the first example? How about 3? > That is: > > - Person validates :firstname (not nil, "foo" okay, not "bar") > - Person validates :firstname should reject "" with 'can't be blank' message > - Person "should reject a super long firstname" As I intended it each "it_should_reject" or "it_should_accept" generates a new example (and returns the matcher used in that example, so that the matcher can be modified via "with", etc). If you want to have multiple expectations per example string, then you are free to do so, using the normal rspec matchers. For example: validation_for(:firstname) do it "should validate :firstname (not nil, "foo" okay, not "bar")" do @it.should reject nil @it.should accept "foo" @it.should reject "bar" end end I *strongly* prefer the one assertion/expectation per test/spec/example style, so I really don't intend to ever do that or have need for something to simplify it. And I recommend against it. Also, I believe that the generated spec strings should be simpler and smaller when using this syntax. I don't need to or want to mention which fields are being validated on each line (I can do that in the behavior string if necessary). For example, http://pastie.caboo.se/67605 should generate the following specdoc: Person firstname - should reject nil - should reject "" with "can't be blank" - should accept "foo" - should accept "bar" - should reject a super long firstname Person validation to ensure that Oingo Boingo isn't used - should accept "Nicholas", "Evans" - should accept "David", "Chelimsky" - should reject "Oingo", "Boingo" - should reject "Danny", "Elfman" FWIW, these names are rejected out of *respect*. Our humble Person model is not deserving of them. They are represented with the MusicalGenius model. ;-) > The .because("should reject a super long firstname") syntax in my > example would be equivalent to the third example. My thought: I don't like the "because" syntax as you stated it above because it goes outside of the rspec syntax, but it is actually a character longer than doing it the rspec way: it "should fooooo" { @it.should reject(foo) } it_should_reject(foo).because("should fooooo") We might use it instead to append an explanation to the generated example string: 'should reject foo with "bar" because blatz'. But then I have to wonder, why not just have a more descriptive error message that could do the job? If your error message isn't enough to make sense to your developers and analysts reading the specs, then it must be *really* confusing to the users! So consider me opposed to the "because" syntax. But if you want it, it should be *very* easy for you to add. ;-) -- Nick From dchelimsky at gmail.com Mon Jun 4 18:48:49 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 4 Jun 2007 17:48:49 -0500 Subject: [rspec-users] Another attempt for a succinct model validation DSL In-Reply-To: <276ff9870706041545u15a5e10erb3bf90fc48aa1865@mail.gmail.com> References: <276ff9870705311334t7dd388c8mf79fc6e7fa5aa695@mail.gmail.com> <167b6aa00706040913q431af40bu2f919e1b4eb1bcdb@mail.gmail.com> <276ff9870706041103y3936734fj65d1cd052ff75fd2@mail.gmail.com> <167b6aa00706041237ka7ea283g82676c73da2849c0@mail.gmail.com> <276ff9870706041545u15a5e10erb3bf90fc48aa1865@mail.gmail.com> Message-ID: <57c63afe0706041548m1b5b297cs969b125e7e46e1a3@mail.gmail.com> On 6/4/07, nicholas a. evans wrote: > Person validation to ensure that Oingo Boingo isn't used > - should accept "Nicholas", "Evans" > - should accept "David", "Chelimsky" > - should reject "Oingo", "Boingo" > - should reject "Danny", "Elfman" > > FWIW, these names are rejected out of *respect*. Our humble Person > model is not deserving of them. They are represented with the > MusicalGenius model. ;-) Hmmmm. Genius, perhaps not, but musical I am. Is there a model somewhere between humble Person and MusicalGenius? From linojon at gmail.com Mon Jun 4 21:29:21 2007 From: linojon at gmail.com (Jonathan Linowes) Date: Mon, 4 Jun 2007 21:29:21 -0400 Subject: [rspec-users] Fwd: testing - test/spec and rspec References: <1181003724.673218.32330@q19g2000prn.googlegroups.com> Message-ID: <1DBB72B9-622B-4D15-9BA3-34A2B8275979@gmail.com> are you guys aware of this?? :) Begin forwarded message: > From: topfunky > Date: June 4, 2007 8:35:24 PM EDT > To: PeepCode > Subject: Re: testing - test/spec and rspec > Reply-To: peepcode at googlegroups.com > > > On 5/28/07, Neil wrote: >> Just finished watching the testing episode. It was very helpful, but >> it has been a while since it was produced, and I am wondering whether >> some of the tools that have come out (or been updated) in the interim >> (like test/spec and rspec) would be worth using. > > I sent a 2 hour, 45 minute screencast on rSpec out to my technical > reviewer last Thursday. I hope to release it next week. > > I was initially quite skeptical about rSpec, but I'm converting all my > projects to use it now. The style, speed, and utilities are well worth > the effort of learning it. Test::Unit still has its place, but if > you're on a small team that isn't tied down to existing code, I highly > recommend checking it out. > > -- > Geoffrey Grosenbach > ........................ > Screencast | http://peepcode.com > > > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google > Groups "PeepCode" group. > To post to this group, send email to peepcode at googlegroups.com > To unsubscribe from this group, send email to peepcode- > unsubscribe at googlegroups.com > For more options, visit this group at http://groups.google.com/ > group/peepcode?hl=en > -~----------~----~----~----~------~----~------~--~--- > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070604/1422e5c0/attachment.html From kihlbom at gmail.com Tue Jun 5 03:37:15 2007 From: kihlbom at gmail.com (Carl-Johan Kihlbom) Date: Tue, 5 Jun 2007 09:37:15 +0200 Subject: [rspec-users] content_for In-Reply-To: <425146b90706040750p7993df52l71dbcccb0b6053c5@mail.gmail.com> References: <60f3810c0705230800t68a92739j8c4d2ec9b993b5ed@mail.gmail.com> <425146b90706040750p7993df52l71dbcccb0b6053c5@mail.gmail.com> Message-ID: On 6/4/07, Moses Hohman wrote: > What we usually do in this case is render the view with the layout and then > check the contents of the sidebar div. However, this does lead to having to > stub out additional things you don't care about in your example. If anyone > has a better plan I'd like to know, too. > > Moses Moses, this doesn't work for me. I tried the following: response.should have_tag("div#sidebar") That didn't work (no matching tag found). I also tried similar approaches to matching tags within the sidebar, without any luck. Any ideas? From kihlbom at gmail.com Tue Jun 5 06:42:52 2007 From: kihlbom at gmail.com (Carl-Johan Kihlbom) Date: Tue, 5 Jun 2007 12:42:52 +0200 Subject: [rspec-users] content_for In-Reply-To: References: <60f3810c0705230800t68a92739j8c4d2ec9b993b5ed@mail.gmail.com> <425146b90706040750p7993df52l71dbcccb0b6053c5@mail.gmail.com> Message-ID: Okey, here's how I solved it: In spec_helper.rb I defined the following method: def content_for(name) response.template.instance_variable_get("@content_for_#{name}") end Then in my examples I can just use this: content_for(:sidebar).should have_tag('ul.people li.person', 2) If anyone has a cleaner solution, please let me know. / CJ From tom at experthuman.com Tue Jun 5 06:59:18 2007 From: tom at experthuman.com (Tom Stuart) Date: Tue, 5 Jun 2007 11:59:18 +0100 Subject: [rspec-users] autotest and rspec_on_rails not happy In-Reply-To: References: <57c63afe0705301352i10c9ed5dk9a262c69d8220343@mail.gmail.com> <57c63afe0705301413s68004f9bjd4e5dc8a896beadb@mail.gmail.com> <00E3CF8B-89D5-4311-9D78-4ADB0491AD02@experthuman.com> <294AEDEF-6323-4EA3-8C4B-43CC33A84CCE@experthuman.com> <57c63afe0705310441g730e2b27q5c1600e46c2081f6@mail.gmail.com> Message-ID: On 31 May 2007, at 15:11, Tom Stuart wrote: > On 31 May 2007, at 12:41, David Chelimsky wrote: >> I've not heard of this before and can't reproduce it. > Below is how I can reproduce on a fresh Rails project. Was anyone (e.g. David) able to reproduce this, let alone fix it? autotest is integral to my workflow so this bug (if that's what it is) is essentially preventing me from using RSpec. If anybody has any vague ideas or suggestions about where to start investigating then I'll do so, but I don't know anything about RSpec/ZenTest internals so I don't want to go in completely blind. Cheers, -Tom From dchelimsky at gmail.com Tue Jun 5 07:33:53 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jun 2007 06:33:53 -0500 Subject: [rspec-users] autotest and rspec_on_rails not happy In-Reply-To: References: <57c63afe0705301352i10c9ed5dk9a262c69d8220343@mail.gmail.com> <57c63afe0705301413s68004f9bjd4e5dc8a896beadb@mail.gmail.com> <00E3CF8B-89D5-4311-9D78-4ADB0491AD02@experthuman.com> <294AEDEF-6323-4EA3-8C4B-43CC33A84CCE@experthuman.com> <57c63afe0705310441g730e2b27q5c1600e46c2081f6@mail.gmail.com> Message-ID: <57c63afe0706050433q15173ab8ye7db89d62837f816@mail.gmail.com> On 6/5/07, Tom Stuart wrote: > On 31 May 2007, at 15:11, Tom Stuart wrote: > > On 31 May 2007, at 12:41, David Chelimsky wrote: > >> I've not heard of this before and can't reproduce it. > > Below is how I can reproduce on a fresh Rails project. > > Was anyone (e.g. David) able to reproduce this, let alone fix it? If I understand the problem correctly, this is fixed in trunk: http://rubyforge.org/tracker/index.php?func=detail&aid=11337&group_id=797&atid=3149 > > autotest is integral to my workflow so this bug (if that's what it > is) is essentially preventing me from using RSpec. If anybody has any > vague ideas or suggestions about where to start investigating then > I'll do so, but I don't know anything about RSpec/ZenTest internals > so I don't want to go in completely blind. > > Cheers, > -Tom > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tom at experthuman.com Tue Jun 5 07:39:11 2007 From: tom at experthuman.com (Tom Stuart) Date: Tue, 5 Jun 2007 12:39:11 +0100 Subject: [rspec-users] autotest and rspec_on_rails not happy In-Reply-To: <57c63afe0706050433q15173ab8ye7db89d62837f816@mail.gmail.com> References: <57c63afe0705301352i10c9ed5dk9a262c69d8220343@mail.gmail.com> <57c63afe0705301413s68004f9bjd4e5dc8a896beadb@mail.gmail.com> <00E3CF8B-89D5-4311-9D78-4ADB0491AD02@experthuman.com> <294AEDEF-6323-4EA3-8C4B-43CC33A84CCE@experthuman.com> <57c63afe0705310441g730e2b27q5c1600e46c2081f6@mail.gmail.com> <57c63afe0706050433q15173ab8ye7db89d62837f816@mail.gmail.com> Message-ID: <35A337E5-CDD8-4D7C-94A8-1E834FF1E39D@experthuman.com> On 5 Jun 2007, at 12:33, David Chelimsky wrote: >> Was anyone (e.g. David) able to reproduce this, let alone fix it? > If I understand the problem correctly, this is fixed in trunk: Magical. This is indeed fixed since r2076. Thank you! From dchelimsky at gmail.com Tue Jun 5 07:42:18 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jun 2007 06:42:18 -0500 Subject: [rspec-users] shared descriptions -- a couple of issues In-Reply-To: <41d5fadf0706041209p36000edbr36d439b6e8547eaf@mail.gmail.com> References: <57c63afe0705101027y5b91054cwbfcd18619f8b003b@mail.gmail.com> <7075BF68-D674-47C1-A8DA-FC6EC339431E@mydigitallife.com> <41d5fadf0706040855t7a6663ddwe3893b5208d38f87@mail.gmail.com> <57c63afe0706040904x1987f941t7ce8efc816f40835@mail.gmail.com> <41d5fadf0706041209p36000edbr36d439b6e8547eaf@mail.gmail.com> Message-ID: <57c63afe0706050442m7b2be917u380d7ce969355c7f@mail.gmail.com> On 6/4/07, Fran?ois Beausoleil wrote: > Hello David, > > 2007/6/4, David Chelimsky : > > This is all resolved in the current trunk. > > Was 1.0.4 cut from the current trunk? Nope. 1.0.4 was tagged at 2054 on 5/29. We're up to 2077 now. Grab the trunk and you should be OK. If you don't like using trunk, you'll have to wait for 1.0.5, but that will be coming soon. From win at wincent.com Tue Jun 5 07:50:32 2007 From: win at wincent.com (Wincent Colaiuta) Date: Tue, 5 Jun 2007 13:50:32 +0200 Subject: [rspec-users] autotest and rspec_on_rails not happy In-Reply-To: References: <57c63afe0705301352i10c9ed5dk9a262c69d8220343@mail.gmail.com> <57c63afe0705301413s68004f9bjd4e5dc8a896beadb@mail.gmail.com> <00E3CF8B-89D5-4311-9D78-4ADB0491AD02@experthuman.com> <294AEDEF-6323-4EA3-8C4B-43CC33A84CCE@experthuman.com> <57c63afe0705310441g730e2b27q5c1600e46c2081f6@mail.gmail.com> Message-ID: <756767AA-B591-41B8-9306-5E6D7A27D1A1@wincent.com> El 5/6/2007, a las 12:59, Tom Stuart escribi?: > On 31 May 2007, at 15:11, Tom Stuart wrote: >> On 31 May 2007, at 12:41, David Chelimsky wrote: >>> I've not heard of this before and can't reproduce it. >> Below is how I can reproduce on a fresh Rails project. > > Was anyone (e.g. David) able to reproduce this, let alone fix it? > > autotest is integral to my workflow so this bug (if that's what it > is) is essentially preventing me from using RSpec. If anybody has any > vague ideas or suggestions about where to start investigating then > I'll do so, but I don't know anything about RSpec/ZenTest internals > so I don't want to go in completely blind. I've seen this as well, although not lately. If I see it again I'll try to distill it down to a reproducible case. Cheers, Wincent From francois.beausoleil at gmail.com Tue Jun 5 10:38:04 2007 From: francois.beausoleil at gmail.com (=?UTF-8?Q?Fran=C3=A7ois_Beausoleil?=) Date: Tue, 5 Jun 2007 10:38:04 -0400 Subject: [rspec-users] shared descriptions -- a couple of issues In-Reply-To: <57c63afe0706050442m7b2be917u380d7ce969355c7f@mail.gmail.com> References: <57c63afe0705101027y5b91054cwbfcd18619f8b003b@mail.gmail.com> <7075BF68-D674-47C1-A8DA-FC6EC339431E@mydigitallife.com> <41d5fadf0706040855t7a6663ddwe3893b5208d38f87@mail.gmail.com> <57c63afe0706040904x1987f941t7ce8efc816f40835@mail.gmail.com> <41d5fadf0706041209p36000edbr36d439b6e8547eaf@mail.gmail.com> <57c63afe0706050442m7b2be917u380d7ce969355c7f@mail.gmail.com> Message-ID: <41d5fadf0706050738n8e3cf13m93adeb79644c7ca9@mail.gmail.com> 2007/6/5, David Chelimsky : > > Was 1.0.4 cut from the current trunk? > > Nope. 1.0.4 was tagged at 2054 on 5/29. We're up to 2077 now. > > Grab the trunk and you should be OK. If you don't like using trunk, > you'll have to wait for 1.0.5, but that will be coming soon. Thank you, David. I'll wait for 1.0.5. Thanks ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From edward.og at gmail.com Tue Jun 5 11:34:41 2007 From: edward.og at gmail.com (Edward Ocampo-gooding) Date: Tue, 5 Jun 2007 11:34:41 -0400 Subject: [rspec-users] slow execution times using spec_server Message-ID: I can confirm this problem occurring on my setup too. Ruby 1.8.5 on OS 10.4.9 RSpec and RSpec on Rails 1.0.5 From gramos at rectorado.unl.edu.ar Tue Jun 5 11:56:30 2007 From: gramos at rectorado.unl.edu.ar (Gaston Ramos) Date: Tue, 5 Jun 2007 12:56:30 -0300 Subject: [rspec-users] Help with spec controller Message-ID: <20070605155630.GA20082@marlasina> Hello, I haven't been able to create a controller spec. You can see the code here: http://pastie.caboo.se/67980 The error message I'm getting is: Spec::Mocks::MockExpectationError in 'PersonController should tell the Person model to create a new person on POST to create' Mock 'person' received unexpected message :save with (no args) /home/gramos/src/rails/dental/config/../app/controllers/person_controller.rb:26:in `create' ./spec/controllers/person_controller_spec.rb I can't find what I am doing wrong. I would appreciate any help. thanks in advance. -- Gast?n Ramos "I always thought Smalltalk would beat Java, I just didn't know it would be called 'Ruby' when it did." -- Kent Beck From dchelimsky at gmail.com Tue Jun 5 11:59:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jun 2007 10:59:15 -0500 Subject: [rspec-users] Help with spec controller In-Reply-To: <20070605155630.GA20082@marlasina> References: <20070605155630.GA20082@marlasina> Message-ID: <57c63afe0706050859t268f43e8i88108ba3cc634b3a@mail.gmail.com> On 6/5/07, Gaston Ramos wrote: > Hello, > > I haven't been able to create a controller spec. > You can see the code here: > > http://pastie.caboo.se/67980 Instead of this: Person.stub!(:save).and_return( @person ) do this: person.stub!(:save).and_return(true) Please let us know if that fixes it. > > The error message I'm getting is: > > Spec::Mocks::MockExpectationError in 'PersonController should tell the Person > model to create a new person on POST to create' > Mock 'person' received unexpected message :save with (no args) > /home/gramos/src/rails/dental/config/../app/controllers/person_controller.rb:26:in > `create' > ./spec/controllers/person_controller_spec.rb > > I can't find what I am doing wrong. > > I would appreciate any help. thanks in advance. > > > -- > Gast?n Ramos > > "I always thought Smalltalk would beat Java, I just didn't know it would be > called 'Ruby' when it did." > -- Kent Beck > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pritchie at videotron.ca Tue Jun 5 11:21:30 2007 From: pritchie at videotron.ca (Patrick Ritchie) Date: Tue, 05 Jun 2007 11:21:30 -0400 Subject: [rspec-users] slow execution times using spec_server Message-ID: <46657F7A.4080203@videotron.ca> Hi, I'm currently having the same problem, running both rspec and rspec_on_rails from trunk. Anyone have any ideas? Cheers! Patrick > hi all > > I'm seeing strange behaviour when running specs using spec_server. > They take longer to execute, and it looks like none of examples are > being run. here's the output for a simple spec file using just the > spec command: > > ---------- > foo at holly :~/rails/allison$ time ruby/script spec spec/models/listing_spec.rb > ...... > > Finished in 0.060469 seconds > > 6 examples, 0 failures < --- > > real 0m1.850s > user 0m1.500s > sys 0m0.276s > ---------- > > here's the same spec file run using the -X option (and spec_server running): > > ---------- > foo at holly :~/rails/allison$ time ruby/script spec spec/models/listing_spec.rb -X > > Finished in 1.6e-05 seconds > > 0 examples, 0 failures < --- > > real 0m5.441s > user 0m0.160s > sys 0m0.016s > ---------- > > > I havn't got a clue what's going on here, does anyone have any suggestions? > I'm using ubuntu 7.04, rspec 1.0.0 and rspec_on_rails 1.0.0 > > help! > dave -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070605/a49c4a5f/attachment.html From gramos at rectorado.unl.edu.ar Tue Jun 5 12:50:13 2007 From: gramos at rectorado.unl.edu.ar (Gaston Ramos) Date: Tue, 5 Jun 2007 13:50:13 -0300 Subject: [rspec-users] Help with spec controller In-Reply-To: <57c63afe0706050859t268f43e8i88108ba3cc634b3a@mail.gmail.com> References: <20070605155630.GA20082@marlasina> <57c63afe0706050859t268f43e8i88108ba3cc634b3a@mail.gmail.com> Message-ID: <20070605165013.GA23379@marlasina> El mar, 05 de jun de 2007, a las 10:59:15 -0500, David Chelimsky dijo: > On 6/5/07, Gaston Ramos wrote: > > Hello, > > > > I haven't been able to create a controller spec. > > You can see the code here: > > > > http://pastie.caboo.se/67980 > > Instead of this: > > Person.stub!(:save).and_return( @person ) > > do this: > > person.stub!(:save).and_return(true) > > Please let us know if that fixes it. I tried that way and it did'nt work > > > > > The error message I'm getting is: > > > > Spec::Mocks::MockExpectationError in 'PersonController should tell the Person > > model to create a new person on POST to create' > > Mock 'person' received unexpected message :save with (no args) > > /home/gramos/src/rails/dental/config/../app/controllers/person_controller.rb:26:in > > `create' > > ./spec/controllers/person_controller_spec.rb > > > > I can't find what I am doing wrong. > > > > I would appreciate any help. thanks in advance. > > > > > > -- > > Gast?n Ramos > > > > "I always thought Smalltalk would beat Java, I just didn't know it would be > > called 'Ruby' when it did." > > -- Kent Beck > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Gast?n Ramos "I always thought Smalltalk would beat Java, I just didn't know it would be called 'Ruby' when it did." -- Kent Beck From dchelimsky at gmail.com Tue Jun 5 13:00:11 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jun 2007 12:00:11 -0500 Subject: [rspec-users] Help with spec controller In-Reply-To: <20070605165013.GA23379@marlasina> References: <20070605155630.GA20082@marlasina> <57c63afe0706050859t268f43e8i88108ba3cc634b3a@mail.gmail.com> <20070605165013.GA23379@marlasina> Message-ID: <57c63afe0706051000n17e73db5k4fad244daea25a70@mail.gmail.com> On 6/5/07, Gaston Ramos wrote: > El mar, 05 de jun de 2007, a las 10:59:15 -0500, David Chelimsky dijo: > > On 6/5/07, Gaston Ramos wrote: > > > Hello, > > > > > > I haven't been able to create a controller spec. > > > You can see the code here: > > > > > > http://pastie.caboo.se/67980 > > > > Instead of this: > > > > Person.stub!(:save).and_return( @person ) > > > > do this: > > > > person.stub!(:save).and_return(true) > > > > Please let us know if that fixes it. > > I tried that way and it did'nt work "it didn't work" doesn't help us to help you. How didn't it work? What was the error this time? Can you post the controller code in addition to the rspec example? > > > > > > > > > The error message I'm getting is: > > > > > > Spec::Mocks::MockExpectationError in 'PersonController should tell the Person > > > model to create a new person on POST to create' > > > Mock 'person' received unexpected message :save with (no args) > > > /home/gramos/src/rails/dental/config/../app/controllers/person_controller.rb:26:in > > > `create' > > > ./spec/controllers/person_controller_spec.rb > > > > > > I can't find what I am doing wrong. > > > > > > I would appreciate any help. thanks in advance. > > > > > > > > > -- > > > Gast?n Ramos > > > > > > "I always thought Smalltalk would beat Java, I just didn't know it would be > > > called 'Ruby' when it did." > > > -- Kent Beck > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Gast?n Ramos > > "I always thought Smalltalk would beat Java, I just didn't know it would be > called 'Ruby' when it did." > -- Kent Beck > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From gramos at rectorado.unl.edu.ar Tue Jun 5 13:15:31 2007 From: gramos at rectorado.unl.edu.ar (Gaston Ramos) Date: Tue, 5 Jun 2007 14:15:31 -0300 Subject: [rspec-users] Help with spec controller In-Reply-To: <57c63afe0706051000n17e73db5k4fad244daea25a70@mail.gmail.com> References: <20070605155630.GA20082@marlasina> <57c63afe0706050859t268f43e8i88108ba3cc634b3a@mail.gmail.com> <20070605165013.GA23379@marlasina> <57c63afe0706051000n17e73db5k4fad244daea25a70@mail.gmail.com> Message-ID: <20070605171531.GA25836@marlasina> El mar, 05 de jun de 2007, a las 12:00:11 -0500, David Chelimsky dijo: > On 6/5/07, Gaston Ramos wrote: > > El mar, 05 de jun de 2007, a las 10:59:15 -0500, David Chelimsky dijo: > > > On 6/5/07, Gaston Ramos wrote: > > > > Hello, > > > > > > > > I haven't been able to create a controller spec. > > > > You can see the code here: > > > > > > > > http://pastie.caboo.se/67980 > > > > > > Instead of this: > > > > > > Person.stub!(:save).and_return( @person ) > > > > > > do this: > > > > > > person.stub!(:save).and_return(true) > > > > > > Please let us know if that fixes it. > > > > I tried that way and it did'nt work > > "it didn't work" doesn't help us to help you. How didn't it work? What > was the error this time? Can you post the controller code in addition > to the rspec example? you can see the person_controller_spec code: http://pastie.caboo.se/67993 and the person_controller code: http://pastie.caboo.se/67994 when I run: rake spec:controllers I get this error: DEPRECATION WARNING: model is deprecated and will be removed from Rails 2.0 See http://www.rubyonrails.org/deprecation for details. (called from /home/gramos/src/rails/dental/config/../app/controllers/application.rb:10) DEPRECATION WARNING: depend_on is deprecated and will be removed from Rails 2.0 See http://www.rubyonrails.org/deprecation for details. (called from model_without_deprecation at /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/deprecated_dependencies.rb:13) ...F 1) Spec::Mocks::MockExpectationError in 'PersonController should tell the Person model to create a new person on POST to create' Mock 'person' received unexpected message :save with (no args) /home/gramos/src/rails/dental/config/../app/controllers/person_controller.rb:26:in `create' ./spec/controllers/person_controller_spec.rb:47: Finished in 0.142998 seconds 4 examples, 1 failure > > > > > > > > > > > > > > > The error message I'm getting is: > > > > > > > > Spec::Mocks::MockExpectationError in 'PersonController should tell the Person > > > > model to create a new person on POST to create' > > > > Mock 'person' received unexpected message :save with (no args) > > > > /home/gramos/src/rails/dental/config/../app/controllers/person_controller.rb:26:in > > > > `create' > > > > ./spec/controllers/person_controller_spec.rb > > > > > > > > I can't find what I am doing wrong. > > > > > > > > I would appreciate any help. thanks in advance. > > > > > > > > > > > > -- > > > > Gast?n Ramos > > > > > > > > "I always thought Smalltalk would beat Java, I just didn't know it would be > > > > called 'Ruby' when it did." > > > > -- Kent Beck > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > -- > > Gast?n Ramos > > > > "I always thought Smalltalk would beat Java, I just didn't know it would be > > called 'Ruby' when it did." > > -- Kent Beck > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Gast?n Ramos "I always thought Smalltalk would beat Java, I just didn't know it would be called 'Ruby' when it did." -- Kent Beck From dchelimsky at gmail.com Tue Jun 5 13:22:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jun 2007 12:22:37 -0500 Subject: [rspec-users] Help with spec controller In-Reply-To: <20070605171531.GA25836@marlasina> References: <20070605155630.GA20082@marlasina> <57c63afe0706050859t268f43e8i88108ba3cc634b3a@mail.gmail.com> <20070605165013.GA23379@marlasina> <57c63afe0706051000n17e73db5k4fad244daea25a70@mail.gmail.com> <20070605171531.GA25836@marlasina> Message-ID: <57c63afe0706051022r37367cb4rccae058e91fc0aa1@mail.gmail.com> On 6/5/07, Gaston Ramos wrote: > El mar, 05 de jun de 2007, a las 12:00:11 -0500, David Chelimsky dijo: > > On 6/5/07, Gaston Ramos wrote: > > > El mar, 05 de jun de 2007, a las 10:59:15 -0500, David Chelimsky dijo: > > > > On 6/5/07, Gaston Ramos wrote: > > > > > Hello, > > > > > > > > > > I haven't been able to create a controller spec. > > > > > You can see the code here: > > > > > > > > > > http://pastie.caboo.se/67980 > > > > > > > > Instead of this: > > > > > > > > Person.stub!(:save).and_return( @person ) > > > > > > > > do this: > > > > > > > > person.stub!(:save).and_return(true) > > > > > > > > Please let us know if that fixes it. > > > > > > I tried that way and it did'nt work > > > > "it didn't work" doesn't help us to help you. How didn't it work? What > > was the error this time? Can you post the controller code in addition > > to the rspec example? > > you can see the person_controller_spec code: > > http://pastie.caboo.se/67993 > > and the person_controller code: > > http://pastie.caboo.se/67994 > > when I run: > rake spec:controllers > > I get this error: > > DEPRECATION WARNING: model is deprecated and will be removed from Rails 2.0 See > http://www.rubyonrails.org/deprecation for details. (called from > /home/gramos/src/rails/dental/config/../app/controllers/application.rb:10) > DEPRECATION WARNING: depend_on is deprecated and will be removed from Rails 2.0 > See http://www.rubyonrails.org/deprecation for details. (called from > model_without_deprecation at > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/deprecated_dependencies.rb:13) > ...F > > 1) > Spec::Mocks::MockExpectationError in 'PersonController should tell the Person > model to create a new person on POST to create' > Mock 'person' received unexpected message :save with (no args) > /home/gramos/src/rails/dental/config/../app/controllers/person_controller.rb:26:in > `create' > ./spec/controllers/person_controller_spec.rb:47: > > Finished in 0.142998 seconds > > 4 examples, 1 failure The stuff being mocked in the example is not the same as the stuff happening in the controller. The first problem is the one I brought up earlier. That's what is causing the specific error you are getting because you're mocking :save on the Person class, but sending :save to the @person instance in the controller. Also, there is no need for @person.should_receive(:new_record?).and_return(false) - that's not getting called. Lastly, the controller is calling Person.new, but the example is mocking Person.create. I think this should work: http://pastie.caboo.se/67998 Give it a shot. > > > > > > > > > > > > > > > > > > > > > > > The error message I'm getting is: > > > > > > > > > > Spec::Mocks::MockExpectationError in 'PersonController should tell the Person > > > > > model to create a new person on POST to create' > > > > > Mock 'person' received unexpected message :save with (no args) > > > > > /home/gramos/src/rails/dental/config/../app/controllers/person_controller.rb:26:in > > > > > `create' > > > > > ./spec/controllers/person_controller_spec.rb > > > > > > > > > > I can't find what I am doing wrong. > > > > > > > > > > I would appreciate any help. thanks in advance. > > > > > > > > > > > > > > > -- > > > > > Gast?n Ramos > > > > > > > > > > "I always thought Smalltalk would beat Java, I just didn't know it would be > > > > > called 'Ruby' when it did." > > > > > -- Kent Beck > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > -- > > > Gast?n Ramos > > > > > > "I always thought Smalltalk would beat Java, I just didn't know it would be > > > called 'Ruby' when it did." > > > -- Kent Beck > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Gast?n Ramos > > "I always thought Smalltalk would beat Java, I just didn't know it would be > called 'Ruby' when it did." > -- Kent Beck > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From address4spams at 21croissants.com Tue Jun 5 13:49:19 2007 From: address4spams at 21croissants.com (Jean-Michel Garnier) Date: Tue, 5 Jun 2007 19:49:19 +0200 Subject: [rspec-users] netvibes tab about rspec Message-ID: Hi, As I am not a big fan of mailing list, I have created a Yahoo!Pipes to generate a RSS from the user & developpers mailing list and integrated it into a netvibes tab. I have also put a few blogs from the rspec authors. More information and screenshots (worth 1000 words!) in http://21croissants.blogspot.com/2007/05/rspec-changes-log-rss.html Cheers, Jean-Michel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070605/8e35569f/attachment.html From gramos at rectorado.unl.edu.ar Tue Jun 5 14:10:19 2007 From: gramos at rectorado.unl.edu.ar (Gaston Ramos) Date: Tue, 5 Jun 2007 15:10:19 -0300 Subject: [rspec-users] Help with spec controller In-Reply-To: <57c63afe0706051022r37367cb4rccae058e91fc0aa1@mail.gmail.com> References: <20070605155630.GA20082@marlasina> <57c63afe0706050859t268f43e8i88108ba3cc634b3a@mail.gmail.com> <20070605165013.GA23379@marlasina> <57c63afe0706051000n17e73db5k4fad244daea25a70@mail.gmail.com> <20070605171531.GA25836@marlasina> <57c63afe0706051022r37367cb4rccae058e91fc0aa1@mail.gmail.com> Message-ID: <20070605181019.GA27756@marlasina> El mar, 05 de jun de 2007, a las 12:22:37 -0500, David Chelimsky dijo: > On 6/5/07, Gaston Ramos wrote: > > El mar, 05 de jun de 2007, a las 12:00:11 -0500, David Chelimsky dijo: > > > On 6/5/07, Gaston Ramos wrote: > > > > El mar, 05 de jun de 2007, a las 10:59:15 -0500, David Chelimsky dijo: > > > > > On 6/5/07, Gaston Ramos wrote: > > > > > > Hello, > > > > > > > > > > > > I haven't been able to create a controller spec. > > > > > > You can see the code here: > > > > > > > > > > > > http://pastie.caboo.se/67980 > > > > > > > > > > Instead of this: > > > > > > > > > > Person.stub!(:save).and_return( @person ) > > > > > > > > > > do this: > > > > > > > > > > person.stub!(:save).and_return(true) > > > > > > > > > > Please let us know if that fixes it. > > > > > > > > I tried that way and it did'nt work > > > > > > "it didn't work" doesn't help us to help you. How didn't it work? What > > > was the error this time? Can you post the controller code in addition > > > to the rspec example? > > > > you can see the person_controller_spec code: > > > > http://pastie.caboo.se/67993 > > > > and the person_controller code: > > > > http://pastie.caboo.se/67994 > > > > when I run: > > rake spec:controllers > > > > I get this error: > > > > DEPRECATION WARNING: model is deprecated and will be removed from Rails 2.0 See > > http://www.rubyonrails.org/deprecation for details. (called from > > /home/gramos/src/rails/dental/config/../app/controllers/application.rb:10) > > DEPRECATION WARNING: depend_on is deprecated and will be removed from Rails 2.0 > > See http://www.rubyonrails.org/deprecation for details. (called from > > model_without_deprecation at > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/deprecated_dependencies.rb:13) > > ...F > > > > 1) > > Spec::Mocks::MockExpectationError in 'PersonController should tell the Person > > model to create a new person on POST to create' > > Mock 'person' received unexpected message :save with (no args) > > /home/gramos/src/rails/dental/config/../app/controllers/person_controller.rb:26:in > > `create' > > ./spec/controllers/person_controller_spec.rb:47: > > > > Finished in 0.142998 seconds > > > > 4 examples, 1 failure > > The stuff being mocked in the example is not the same as the stuff > happening in the controller. The first problem is the one I brought up > earlier. That's what is causing the specific error you are getting > because you're mocking :save on the Person class, but sending :save to > the @person instance in the controller. > > Also, there is no need for > @person.should_receive(:new_record?).and_return(false) - that's not > getting called. > > Lastly, the controller is calling Person.new, but the example is > mocking Person.create. > > I think this should work: > > http://pastie.caboo.se/67998 > > Give it a shot. Thanks, now is working! > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > The error message I'm getting is: > > > > > > > > > > > > Spec::Mocks::MockExpectationError in 'PersonController should tell the Person > > > > > > model to create a new person on POST to create' > > > > > > Mock 'person' received unexpected message :save with (no args) > > > > > > /home/gramos/src/rails/dental/config/../app/controllers/person_controller.rb:26:in > > > > > > `create' > > > > > > ./spec/controllers/person_controller_spec.rb > > > > > > > > > > > > I can't find what I am doing wrong. > > > > > > > > > > > > I would appreciate any help. thanks in advance. > > > > > > > > > > > > > > > > > > -- > > > > > > Gast?n Ramos > > > > > > > > > > > > "I always thought Smalltalk would beat Java, I just didn't know it would be > > > > > > called 'Ruby' when it did." > > > > > > -- Kent Beck > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > -- > > > > Gast?n Ramos > > > > > > > > "I always thought Smalltalk would beat Java, I just didn't know it would be > > > > called 'Ruby' when it did." > > > > -- Kent Beck > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > -- > > Gast?n Ramos > > > > "I always thought Smalltalk would beat Java, I just didn't know it would be > > called 'Ruby' when it did." > > -- Kent Beck > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Gast?n Ramos "I always thought Smalltalk would beat Java, I just didn't know it would be called 'Ruby' when it did." -- Kent Beck From dchelimsky at gmail.com Tue Jun 5 15:30:11 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jun 2007 14:30:11 -0500 Subject: [rspec-users] slow execution times using spec_server In-Reply-To: <46657F7A.4080203@videotron.ca> References: <46657F7A.4080203@videotron.ca> Message-ID: <57c63afe0706051230i57948e59i25d91190c454dad0@mail.gmail.com> Please submit bug reports to the tracker if you want to see them get addressed. http://rubyforge.org/tracker/?group_id=797 Thanks, David On 6/5/07, Patrick Ritchie wrote: > > Hi, > > I'm currently having the same problem, running both rspec and > rspec_on_rails from trunk. > > Anyone have any ideas? > > Cheers! > Patrick > > hi all > > I'm seeing strange behaviour when running specs using spec_server. > They take longer to execute, and it looks like none of examples are > being run. here's the output for a simple spec file using just the > spec command: > > ---------- > foo at holly:~/rails/allison$ time ruby/script spec > spec/models/listing_spec.rb > ...... > > Finished in 0.060469 seconds > > 6 examples, 0 failures < --- > > real 0m1.850s > user 0m1.500s > sys 0m0.276s > ---------- > > here's the same spec file run using the -X option (and spec_server running): > > ---------- > foo at holly:~/rails/allison$ time ruby/script spec > spec/models/listing_spec.rb -X > > Finished in 1.6e-05 seconds > > 0 examples, 0 failures < --- > > real 0m5.441s > user 0m0.160s > sys 0m0.016s > ---------- > > > I havn't got a clue what's going on here, does anyone have any suggestions? > I'm using ubuntu 7.04, rspec 1.0.0 and rspec_on_rails 1.0.0 > > help! > dave > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Jun 5 18:38:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jun 2007 17:38:13 -0500 Subject: [rspec-users] slow execution times using spec_server In-Reply-To: <57c63afe0706051230i57948e59i25d91190c454dad0@mail.gmail.com> References: <46657F7A.4080203@videotron.ca> <57c63afe0706051230i57948e59i25d91190c454dad0@mail.gmail.com> Message-ID: <57c63afe0706051538v1e97859l270bb75530a54da1@mail.gmail.com> I opened and closed (fixed) http://rubyforge.org/tracker/index.php?func=detail&aid=11378&group_id=797&atid=3149. If you get the current trunk this problem should go away. Cheers, David On 6/5/07, David Chelimsky wrote: > Please submit bug reports to the tracker if you want to see them get addressed. > > http://rubyforge.org/tracker/?group_id=797 > > Thanks, > David > > On 6/5/07, Patrick Ritchie wrote: > > > > Hi, > > > > I'm currently having the same problem, running both rspec and > > rspec_on_rails from trunk. > > > > Anyone have any ideas? > > > > Cheers! > > Patrick > > > > hi all > > > > I'm seeing strange behaviour when running specs using spec_server. > > They take longer to execute, and it looks like none of examples are > > being run. here's the output for a simple spec file using just the > > spec command: > > > > ---------- > > foo at holly:~/rails/allison$ time ruby/script spec > > spec/models/listing_spec.rb > > ...... > > > > Finished in 0.060469 seconds > > > > 6 examples, 0 failures < --- > > > > real 0m1.850s > > user 0m1.500s > > sys 0m0.276s > > ---------- > > > > here's the same spec file run using the -X option (and spec_server running): > > > > ---------- > > foo at holly:~/rails/allison$ time ruby/script spec > > spec/models/listing_spec.rb -X > > > > Finished in 1.6e-05 seconds > > > > 0 examples, 0 failures < --- > > > > real 0m5.441s > > user 0m0.160s > > sys 0m0.016s > > ---------- > > > > > > I havn't got a clue what's going on here, does anyone have any suggestions? > > I'm using ubuntu 7.04, rspec 1.0.0 and rspec_on_rails 1.0.0 > > > > help! > > dave > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From dchelimsky at gmail.com Tue Jun 5 19:39:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 5 Jun 2007 18:39:40 -0500 Subject: [rspec-users] shared descriptions -- a couple of issues In-Reply-To: <41d5fadf0706050738n8e3cf13m93adeb79644c7ca9@mail.gmail.com> References: <57c63afe0705101027y5b91054cwbfcd18619f8b003b@mail.gmail.com> <7075BF68-D674-47C1-A8DA-FC6EC339431E@mydigitallife.com> <41d5fadf0706040855t7a6663ddwe3893b5208d38f87@mail.gmail.com> <57c63afe0706040904x1987f941t7ce8efc816f40835@mail.gmail.com> <41d5fadf0706041209p36000edbr36d439b6e8547eaf@mail.gmail.com> <57c63afe0706050442m7b2be917u380d7ce969355c7f@mail.gmail.com> <41d5fadf0706050738n8e3cf13m93adeb79644c7ca9@mail.gmail.com> Message-ID: <57c63afe0706051639jbe72369nd8be92e11628c593@mail.gmail.com> On 6/5/07, Fran?ois Beausoleil wrote: > 2007/6/5, David Chelimsky : > > > Was 1.0.4 cut from the current trunk? > > > > Nope. 1.0.4 was tagged at 2054 on 5/29. We're up to 2077 now. > > > > Grab the trunk and you should be OK. If you don't like using trunk, > > you'll have to wait for 1.0.5, but that will be coming soon. > > Thank you, David. I'll wait for 1.0.5. Your wait is over. I just released it. Might take a couple of hours for mirrors to get resolved, but you should be able to get it later today. Cheers, David > > Thanks ! > -- > Fran?ois Beausoleil > http://blog.teksol.info/ > http://piston.rubyforge.org/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From address4spams at 21croissants.com Wed Jun 6 06:26:08 2007 From: address4spams at 21croissants.com (Jean-Michel Garnier) Date: Wed, 6 Jun 2007 12:26:08 +0200 Subject: [rspec-users] sharing my netvibes tab about rspec Message-ID: Link was 404 :-( the correct link is http://21croissants.blogspot.com/2007/06/rspec-changes-log-rss.html I should definitely switch from blogger to mephisto ... Hi, As I am not a big fan of mailing list, I have created a Yahoo!Pipes to generate a RSS from the user & developpers mailing list and integrated it into a netvibes tab. I have also put a few blogs from the rspec authors. More information and screenshots (worth 1000 words!) in http://21croissants.blogspot.com/2007/06/rspec-changes-log-rss.html Cheers, Jean-Michel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070606/e1e2ba34/attachment-0001.html From pocketsized at tiscali.co.uk Thu Jun 7 05:54:09 2007 From: pocketsized at tiscali.co.uk (David Green) Date: Thu, 7 Jun 2007 10:54:09 +0100 Subject: [rspec-users] checking associated objects have been deleted Message-ID: <9612333e0706070254x7fa90460g4203ee0c64cf26d0@mail.gmail.com> I have the following model: class Book < ActiveRecord::Base has_many :taggings, :dependent => :delete_all has_many :tags, :through => :taggings end is it possible to check that associated taggings are being destroyed using mocks? I don't want to test that rails is deleting the associations, I want to test that I have specified the association as a dependent one. the only way I can think of is to use fixtures (or create real associations in the before callback) and then check that they have been deleted using Taggings.count(). Can it be done using mocks instead? describe Book do before do @book = mock_model(Book) @tagging = mock_model(Tagging) @book.stub!(:taggings).and_return([@tagging, @tagging]) end it "should delete associated taggings when destroyed" do end end thanks dave From dchelimsky at gmail.com Thu Jun 7 08:41:39 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 7 Jun 2007 07:41:39 -0500 Subject: [rspec-users] checking associated objects have been deleted In-Reply-To: <9612333e0706070254x7fa90460g4203ee0c64cf26d0@mail.gmail.com> References: <9612333e0706070254x7fa90460g4203ee0c64cf26d0@mail.gmail.com> Message-ID: <57c63afe0706070541m1949e008xf6f29212913e0b27@mail.gmail.com> On 6/7/07, David Green wrote: > I have the following model: > > class Book < ActiveRecord::Base > has_many :taggings, :dependent => :delete_all > has_many :tags, :through => :taggings > end > > is it possible to check that associated taggings are being destroyed > using mocks? I don't want to test that rails is deleting the > associations, I want to test that I have specified the association as > a dependent one. > > the only way I can think of is to use fixtures (or create real > associations in the before callback) and then check that they have > been deleted using Taggings.count(). Can it be done using mocks > instead? > > describe Book do > > before do > @book = mock_model(Book) > @tagging = mock_model(Tagging) > @book.stub!(:taggings).and_return([@tagging, @tagging]) > end > > it "should delete associated taggings when destroyed" do > end > > end You have to create a real book, but you can create a mock tagging: book = Book.create(:title => "the book") book.taggings << tagging = mock_model(Tagging, :[]= => true, :save => true) tagging.should_receive(:destroy) book.destroy Cheers, David > > thanks > dave > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Jun 7 08:43:25 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 7 Jun 2007 07:43:25 -0500 Subject: [rspec-users] checking associated objects have been deleted In-Reply-To: <57c63afe0706070541m1949e008xf6f29212913e0b27@mail.gmail.com> References: <9612333e0706070254x7fa90460g4203ee0c64cf26d0@mail.gmail.com> <57c63afe0706070541m1949e008xf6f29212913e0b27@mail.gmail.com> Message-ID: <57c63afe0706070543m29528a0ck96e8309e1c499cda@mail.gmail.com> On 6/7/07, David Chelimsky wrote: > On 6/7/07, David Green wrote: > > I have the following model: > > > > class Book < ActiveRecord::Base > > has_many :taggings, :dependent => :delete_all > > has_many :tags, :through => :taggings > > end > > > > is it possible to check that associated taggings are being destroyed > > using mocks? I don't want to test that rails is deleting the > > associations, I want to test that I have specified the association as > > a dependent one. > > > > the only way I can think of is to use fixtures (or create real > > associations in the before callback) and then check that they have > > been deleted using Taggings.count(). Can it be done using mocks > > instead? > > > > describe Book do > > > > before do > > @book = mock_model(Book) > > @tagging = mock_model(Tagging) > > @book.stub!(:taggings).and_return([@tagging, @tagging]) > > end > > > > it "should delete associated taggings when destroyed" do > > end > > > > end > > You have to create a real book, but you can create a mock tagging: Actually, you don't have to save it - you can use #new instead of create: book = Book.new(:title => "the book") book.taggings << tagging = mock_model(Tagging, :[]= => true, :save => true) tagging.should_receive(:destroy) book.destroy > > Cheers, > David > > > > > > > thanks > > dave > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From gramos at rectorado.unl.edu.ar Thu Jun 7 14:20:41 2007 From: gramos at rectorado.unl.edu.ar (Gaston Ramos) Date: Thu, 7 Jun 2007 15:20:41 -0300 Subject: [rspec-users] Problem with response.should render_template Message-ID: <20070607182041.GA32039@marlasina> Hello, I have problems with this spec controllers: http://pastie.caboo.se/68634 when I run: rake spec:controllers I get this error: ...............F...... 1) 'DocTypeController should update and redirect to show' FAILED expected redirect to {:action=>"show", :id=>1}, got redirect to "http://test.host/doc_type/show/%23%3CSpec%3A%3AMocks%3A%3AMock%3A0xb74a0d14%3E" ./spec/controllers/doc_type_controller_spec.rb:63: Finished in 0.386261 seconds 22 examples, 1 failure I would appreciate any help. -- Gast?n Ramos "I always thought Smalltalk would beat Java, I just didn't know it would be called 'Ruby' when it did." -- Kent Beck From anthony at digitalphenom.com Thu Jun 7 14:50:02 2007 From: anthony at digitalphenom.com (Anthony Carlos) Date: Thu, 7 Jun 2007 14:50:02 -0400 Subject: [rspec-users] Problem with response.should render_template In-Reply-To: <20070607182041.GA32039@marlasina> References: <20070607182041.GA32039@marlasina> Message-ID: Gaston: Just a guess, but maybe your :id => 1 should be :id => '1' (note the quotes)? The value that was returned looks like a description of a ruby object and its memory location (e.g., #). If anyone can explain how that got in there, I'd appreciate it. I hope it helps, -Anthony On Jun 7, 2007, at 2:20 PM, Gaston Ramos wrote: > Hello, I have problems with this spec controllers: > > http://pastie.caboo.se/68634 > > when I run: > rake spec:controllers > > I get this error: > > ...............F...... > > 1) > 'DocTypeController should update and redirect to show' FAILED > expected redirect to {:action=>"show", :id=>1}, got redirect to > "http://test.host/doc_type/show/%23%3CSpec%3A%3AMocks%3A%3AMock% > 3A0xb74a0d14%3E" > ./spec/controllers/doc_type_controller_spec.rb:63: > > Finished in 0.386261 seconds > > 22 examples, 1 failure > > I would appreciate any help. > > -- > Gast?n Ramos > > "I always thought Smalltalk would beat Java, I just didn't know it > would be > called 'Ruby' when it did." > -- Kent Beck > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Jun 7 14:59:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 7 Jun 2007 13:59:01 -0500 Subject: [rspec-users] Problem with response.should render_template In-Reply-To: <20070607182041.GA32039@marlasina> References: <20070607182041.GA32039@marlasina> Message-ID: <57c63afe0706071159u4ef726e6tadb3f1e2b5131764@mail.gmail.com> On 6/7/07, Gaston Ramos wrote: > Hello, I have problems with this spec controllers: > > http://pastie.caboo.se/68634 > > when I run: > rake spec:controllers > > I get this error: > > ...............F...... > > 1) > 'DocTypeController should update and redirect to show' FAILED > expected redirect to {:action=>"show", :id=>1}, got redirect to > "http://test.host/doc_type/show/%23%3CSpec%3A%3AMocks%3A%3AMock%3A0xb74a0d14%3E" > ./spec/controllers/doc_type_controller_spec.rb:63: > > Finished in 0.386261 seconds > > 22 examples, 1 failure > > I would appreciate any help. Can you please add the controller code to the pastie? > > -- > Gast?n Ramos > > "I always thought Smalltalk would beat Java, I just didn't know it would be > called 'Ruby' when it did." > -- Kent Beck > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From gramos at rectorado.unl.edu.ar Thu Jun 7 15:53:45 2007 From: gramos at rectorado.unl.edu.ar (Gastón Ramos) Date: Thu, 7 Jun 2007 16:53:45 -0300 Subject: [rspec-users] Problem with response.should render_template In-Reply-To: <57c63afe0706071159u4ef726e6tadb3f1e2b5131764@mail.gmail.com> References: <20070607182041.GA32039@marlasina> <57c63afe0706071159u4ef726e6tadb3f1e2b5131764@mail.gmail.com> Message-ID: <20070607195345.GB5933@marlasina> El jue, 07 de jun de 2007, a las 01:59:01 -0500, David Chelimsky dijo: > On 6/7/07, Gaston Ramos wrote: > > Hello, I have problems with this spec controllers: > > > > http://pastie.caboo.se/68634 > > > > when I run: > > rake spec:controllers > > > > I get this error: > > > > ...............F...... > > > > 1) > > 'DocTypeController should update and redirect to show' FAILED > > expected redirect to {:action=>"show", :id=>1}, got redirect to > > "http://test.host/doc_type/show/%23%3CSpec%3A%3AMocks%3A%3AMock%3A0xb74a0d14%3E" > > ./spec/controllers/doc_type_controller_spec.rb:63: > > > > Finished in 0.386261 seconds > > > > 22 examples, 1 failure > > > > I would appreciate any help. > > Can you please add the controller code to the pastie? http://pastie.caboo.se/68657 > > > > > -- > > Gast?n Ramos > > > > "I always thought Smalltalk would beat Java, I just didn't know it would be > > called 'Ruby' when it did." > > -- Kent Beck > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Gast?n Ramos "I always thought Smalltalk would beat Java, I just didn't know it would be called 'Ruby' when it did." -- Kent Beck From anthony at digitalphenom.com Thu Jun 7 16:31:48 2007 From: anthony at digitalphenom.com (Anthony Carlos) Date: Thu, 7 Jun 2007 16:31:48 -0400 Subject: [rspec-users] Problem with response.should render_template In-Reply-To: <20070607195345.GB5933@marlasina> References: <20070607182041.GA32039@marlasina> <57c63afe0706071159u4ef726e6tadb3f1e2b5131764@mail.gmail.com> <20070607195345.GB5933@marlasina> Message-ID: Gaston: It looks like on line 42 you're passing :id => @doc_type. I've heard that that is the proper way to pass around ids. However, in this case, it looks like ActiveRecord is passing the entire object, not just the id. You could try replacing @doc_type with @doc_type.id. If it does work, I don't know why ActiveRecord is messing up. Let us know if it works. -Anthony On Jun 7, 2007, at 3:53 PM, Gast?n Ramos wrote: > El jue, 07 de jun de 2007, a las 01:59:01 -0500, David Chelimsky dijo: >> On 6/7/07, Gaston Ramos wrote: >>> Hello, I have problems with this spec controllers: >>> >>> http://pastie.caboo.se/68634 >>> >>> when I run: >>> rake spec:controllers >>> >>> I get this error: >>> >>> ...............F...... >>> >>> 1) >>> 'DocTypeController should update and redirect to show' FAILED >>> expected redirect to {:action=>"show", :id=>1}, got redirect to >>> "http://test.host/doc_type/show/%23%3CSpec%3A%3AMocks%3A%3AMock% >>> 3A0xb74a0d14%3E" >>> ./spec/controllers/doc_type_controller_spec.rb:63: >>> >>> Finished in 0.386261 seconds >>> >>> 22 examples, 1 failure >>> >>> I would appreciate any help. >> >> Can you please add the controller code to the pastie? > > > http://pastie.caboo.se/68657 > >> >>> >>> -- >>> Gast?n Ramos >>> >>> "I always thought Smalltalk would beat Java, I just didn't know >>> it would be >>> called 'Ruby' when it did." >>> -- Kent Beck >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > -- > Gast?n Ramos > > "I always thought Smalltalk would beat Java, I just didn't know it > would be > called 'Ruby' when it did." > -- Kent Beck > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Jun 7 16:42:39 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 7 Jun 2007 15:42:39 -0500 Subject: [rspec-users] Problem with response.should render_template In-Reply-To: References: <20070607182041.GA32039@marlasina> <57c63afe0706071159u4ef726e6tadb3f1e2b5131764@mail.gmail.com> <20070607195345.GB5933@marlasina> Message-ID: <57c63afe0706071342o8360f27ube87d265c39ebd0e@mail.gmail.com> On 6/7/07, Anthony Carlos wrote: > Gaston: > > It looks like on line 42 you're passing :id => @doc_type. I've heard > that that is the proper way to pass around ids. However, in this > case, it looks like ActiveRecord is passing the entire object, not > just the id. You could try replacing @doc_type with @doc_type.id. I think the code is fine and the spec needs to use the ids quoted (strings) as Anthony suggests earlier in this thread. > > If it does work, I don't know why ActiveRecord is messing up. > > Let us know if it works. > > -Anthony > > On Jun 7, 2007, at 3:53 PM, Gast?n Ramos wrote: > > > El jue, 07 de jun de 2007, a las 01:59:01 -0500, David Chelimsky dijo: > >> On 6/7/07, Gaston Ramos wrote: > >>> Hello, I have problems with this spec controllers: > >>> > >>> http://pastie.caboo.se/68634 > >>> > >>> when I run: > >>> rake spec:controllers > >>> > >>> I get this error: > >>> > >>> ...............F...... > >>> > >>> 1) > >>> 'DocTypeController should update and redirect to show' FAILED > >>> expected redirect to {:action=>"show", :id=>1}, got redirect to > >>> "http://test.host/doc_type/show/%23%3CSpec%3A%3AMocks%3A%3AMock% > >>> 3A0xb74a0d14%3E" > >>> ./spec/controllers/doc_type_controller_spec.rb:63: > >>> > >>> Finished in 0.386261 seconds > >>> > >>> 22 examples, 1 failure > >>> > >>> I would appreciate any help. > >> > >> Can you please add the controller code to the pastie? > > > > > > http://pastie.caboo.se/68657 > > > >> > >>> > >>> -- > >>> Gast?n Ramos > >>> > >>> "I always thought Smalltalk would beat Java, I just didn't know > >>> it would be > >>> called 'Ruby' when it did." > >>> -- Kent Beck > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >>> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > > > -- > > Gast?n Ramos > > > > "I always thought Smalltalk would beat Java, I just didn't know it > > would be > > called 'Ruby' when it did." > > -- Kent Beck > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dj at collectiveinsight.net Thu Jun 7 23:08:59 2007 From: dj at collectiveinsight.net (David James) Date: Thu, 7 Jun 2007 22:08:59 -0500 Subject: [rspec-users] Still recommend the plugins over the gems? Message-ID: <7253F8CB-41F4-4BF6-8871-57E5F191D2FD@collectiveinsight.net> > We strongly recommend you install RSpec and Spec::Rails as plugins > (as opposed to relying on an RSpec gem). See special instructions > below if you want to install the HEAD of the trunk, or an older > version. (from http://rspec.rubyforge.org/documentation/rails/install.html) Is this still the case? Why? Is the rspec_on_rails available in gem form? Does rspec_generator (the gem, currently at 0.5.15) correspond to the plugins? -David From mailing_lists at railsnewbie.com Fri Jun 8 01:57:26 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 8 Jun 2007 01:57:26 -0400 Subject: [rspec-users] autotest bug? Message-ID: <89FA19F0-B330-4492-B141-C0F77289D9B3@railsnewbie.com> Autotest is running continuously - even when the files mtimes aren't changing. I believe this only happens if using a failures file. autotest -v gives me: euclid% autotest -v loading autotest/rails_rspec /opt/local/bin/ruby -S script/spec -O spec/spec.opts spec/ controllers/log_entries_controller_spec.rb spec/views/login/ new_spec.rb spec/controllers/login_controller_spec.rb spec/models/ user_spec.rb spec/views/log_entries/edit_html.erb_spec.rb spec/views/ log_entries/index_html.erb_spec.rb spec/views/log_entries/ new_html.erb_spec.rb spec/views/log_entries/show_html.erb_spec.rb spec/helpers/login_helper_spec.rb spec/models/log_entry_spec.rb ........................................................................ .....F.. 1) 'LoginController routes should route create to POST /login' FAILED expected "/login", got "/login/create" (using ==) ./spec/controllers/login_controller_spec.rb:13: script/spec:4: Finished in 3.04389 seconds 80 examples, 1 failure [["spec/previous_failures.txt", Fri Jun 08 01:13:32 -0400 2007]] (The last line is the important one). Is there a way to get around this via autotest? Or does this suggest that Autotest::Rspec needs to be patched? Or should rspec use a standard failures file? Scott From mailing_lists at railsnewbie.com Fri Jun 8 02:01:08 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 8 Jun 2007 02:01:08 -0400 Subject: [rspec-users] Still recommend the plugins over the gems? In-Reply-To: <7253F8CB-41F4-4BF6-8871-57E5F191D2FD@collectiveinsight.net> References: <7253F8CB-41F4-4BF6-8871-57E5F191D2FD@collectiveinsight.net> Message-ID: On Jun 7, 2007, at 11:08 PM, David James wrote: >> We strongly recommend you install RSpec and Spec::Rails as plugins >> (as opposed to relying on an RSpec gem). See special instructions >> below if you want to install the HEAD of the trunk, or an older >> version. > (from http://rspec.rubyforge.org/documentation/rails/install.html) > > Is this still the case? Why? > > Is the rspec_on_rails available in gem form? The rspec_on_rails plugin has never been available in gem form, has it? Potentially, you could install the rspec_on_rails plugin, while using the autotest gem (assuming you got the version numbers exactly right). Or am I wrong on this one, as well? Scott From mailing_lists at railsnewbie.com Fri Jun 8 02:32:32 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 8 Jun 2007 02:32:32 -0400 Subject: [rspec-users] When to use BDD/TDD w/ external libraries Message-ID: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> Test First Development is great...But should you use it when you are adding classes/methods on to external library that doesn't have an extensive test suite? I noticed that the rspec plugin for autotest has no specs. David Chemlinsky said something to the list a while back that has been stewing in my subconscious - that you develop software differently using Test First Development/BDD. I noticed that it would be very hard to add a spec library to autotest (I once performed some code coverage on it and I believe it was at something like 30 or 40 percent.). So if one wanted to develop something like the rspec plugin to autotest, would it be wise to develop it test first? I'm not sure if anyone else has had this difficulty, or if I'm being clear. Let me know if I should clarify with some examples. Best, Scott From win at wincent.com Fri Jun 8 04:01:11 2007 From: win at wincent.com (Wincent Colaiuta) Date: Fri, 8 Jun 2007 10:01:11 +0200 Subject: [rspec-users] autotest bug? In-Reply-To: <89FA19F0-B330-4492-B141-C0F77289D9B3@railsnewbie.com> References: <89FA19F0-B330-4492-B141-C0F77289D9B3@railsnewbie.com> Message-ID: El 8/6/2007, a las 7:57, Scott Taylor escribi?: > Autotest is running continuously - even when the files mtimes aren't > changing. I believe this only happens if using a failures file. Have you removed these lines from your spec/spec.opts file (no longer necessary)? --format failing_examples:previous_failures.txt --example previous_failures.txt Are you running the latest RSpec (contains some autotest-related fixes)? Cheers, Wincent From aslak.hellesoy at gmail.com Fri Jun 8 05:13:03 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 8 Jun 2007 11:13:03 +0200 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> Message-ID: <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> On 6/8/07, Scott Taylor wrote: > > Test First Development is great...But should you use it when you are > adding classes/methods on to external library that doesn't have an > extensive test suite? I noticed that the rspec plugin for autotest > has no specs. > > David Chemlinsky said something to the list a while back that has > been stewing in my subconscious - that you develop software > differently using Test First Development/BDD. I noticed that it David (Chelimsky is his last name) and Ryan Davis paired on the RSpec plugin for Autotest at Railsconf, and I suspect that "they didn't have time" to write specs for it ;-) Look at the number of bugs that have been reported (and fixed) against RSpec's Autotest plugin in the previous weeks. Maybe there is a relationship between the number of bugs and the lack of specs? ;-) > would be very hard to add a spec library to autotest (I once > performed some code coverage on it and I believe it was at something > like 30 or 40 percent.). So if one wanted to develop something like > the rspec plugin to autotest, would it be wise to develop it test first? > Any code that doesn't have automated tests works by accident as far as I'm concerned. It makes no difference whether the code is using a third party library or code whether it's part of your own code. However, some third party libraries (like J2EE) makes it so hard to test any code using it that you essentially have to choose between the third party or the ability to test. Sometimes having both is too much work. Aslak > I'm not sure if anyone else has had this difficulty, or if I'm being > clear. Let me know if I should clarify with some examples. > > Best, > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From thibaut.barrere at gmail.com Fri Jun 8 05:30:02 2007 From: thibaut.barrere at gmail.com (=?ISO-8859-1?Q?Thibaut_Barr=E8re?=) Date: Fri, 8 Jun 2007 11:30:02 +0200 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> Message-ID: <4a68b8cf0706080230y9ef7066hc57807f89f03281@mail.gmail.com> > Test First Development is great...But should you use it when you are > adding classes/methods on to external library that doesn't have an > extensive test suite? I noticed that the rspec plugin for autotest > has no specs. Hi, with external libraries like rails plugins, I find RSpec great to 'secure' the expectations that my application has over these third parties. I don't 'secure' everything, only the things which seem critical in the context of this application. I find this very useful before migrating a plugin to its new version, or when replacing a plugin by another. I also use it to reproduce bugs in those plugins. my 0.02?! ps: RSpec is a kind of a dream to me - the isolation provided by default is bringing a lot of benefits to my testing process ! Thanks. Best, Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070608/d47d837e/attachment.html From mailing_lists at railsnewbie.com Fri Jun 8 08:09:30 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 8 Jun 2007 08:09:30 -0400 Subject: [rspec-users] autotest bug? In-Reply-To: References: <89FA19F0-B330-4492-B141-C0F77289D9B3@railsnewbie.com> Message-ID: On Jun 8, 2007, at 4:01 AM, Wincent Colaiuta wrote: > El 8/6/2007, a las 7:57, Scott Taylor escribi?: > >> Autotest is running continuously - even when the files mtimes aren't >> changing. I believe this only happens if using a failures file. > > Have you removed these lines from your spec/spec.opts file (no longer > necessary)? > > --format > failing_examples:previous_failures.txt > --example > previous_failures.txt > In what revision did that change?! Is this applicable only to rspec_on_rails, or to rspec generally? > Are you running the latest RSpec (contains some autotest-related > fixes)? yep. trunk. It works. Thanks alot. Scott From dchelimsky at gmail.com Fri Jun 8 08:42:54 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Jun 2007 07:42:54 -0500 Subject: [rspec-users] Still recommend the plugins over the gems? In-Reply-To: References: <7253F8CB-41F4-4BF6-8871-57E5F191D2FD@collectiveinsight.net> Message-ID: <57c63afe0706080542j5b2c0a01r15ef954d39a7797c@mail.gmail.com> On 6/8/07, Scott Taylor wrote: > > On Jun 7, 2007, at 11:08 PM, David James wrote: > > >> We strongly recommend you install RSpec and Spec::Rails as plugins > >> (as opposed to relying on an RSpec gem). See special instructions > >> below if you want to install the HEAD of the trunk, or an older > >> version. > > (from http://rspec.rubyforge.org/documentation/rails/install.html) > > > > Is this still the case? Why? > > > > Is the rspec_on_rails available in gem form? > > The rspec_on_rails plugin has never been available in gem form, has it? > > Potentially, you could install the rspec_on_rails plugin, while using > the autotest gem (assuming you got the version numbers exactly > right). Or am I wrong on this one, as well? autotest? I think he was just asking about rspec and rspec_on_rails. The rspec_generator is ancient. I'd delete it. We started off w/ gems but decided w/ all the volatility it was easier to manage different versions directly in the app as plugins. As things are less volatile now, we could revisit this. > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From win at wincent.com Fri Jun 8 08:48:47 2007 From: win at wincent.com (Wincent Colaiuta) Date: Fri, 8 Jun 2007 14:48:47 +0200 Subject: [rspec-users] autotest bug? In-Reply-To: References: <89FA19F0-B330-4492-B141-C0F77289D9B3@railsnewbie.com> Message-ID: <09B09896-C571-4D98-9515-D501359EFBC8@wincent.com> El 8/6/2007, a las 14:09, Scott Taylor escribi?: > On Jun 8, 2007, at 4:01 AM, Wincent Colaiuta wrote: > >> Have you removed these lines from your spec/spec.opts file (no longer >> necessary)? >> >> --format >> failing_examples:previous_failures.txt >> --example >> previous_failures.txt > > In what revision did that change?! Is this applicable only to > rspec_on_rails, or to rspec generally? I don't remember which exact revision, but I was seeing the exact same problem until David set me straight in this post : > These lines configure rspec to limit the number of files that get run > when there are failures, but autotest is doing the same thing so there > is no need. I believe that file is specific to rspec_on_rails, in any case. For the record, when working in a Rails app, each time you do arspec/ rspec_on_rails plugin update I think you should probably run "script/ generate rspec" from the top level of your app; if it tells you that spec/spec.opts has been modified then you can hit the "d" key to see a diff of exactly what's changed... In one of the recent RSpec updates, they dropped those lines from spec/spec.opts. Cheers, Wincent From bkeepers at gmail.com Fri Jun 8 08:52:27 2007 From: bkeepers at gmail.com (Brandon Keepers) Date: Fri, 8 Jun 2007 08:52:27 -0400 Subject: [rspec-users] Still recommend the plugins over the gems? In-Reply-To: <57c63afe0706080542j5b2c0a01r15ef954d39a7797c@mail.gmail.com> References: <7253F8CB-41F4-4BF6-8871-57E5F191D2FD@collectiveinsight.net> <57c63afe0706080542j5b2c0a01r15ef954d39a7797c@mail.gmail.com> Message-ID: <1C8B898D-B6AF-405D-B6A5-CFFF641074D4@gmail.com> On Jun 8, 2007, at 8:42 AM, David Chelimsky wrote: > We started off w/ gems but decided w/ all the volatility it was easier > to manage different versions directly in the app as plugins. As things > are less volatile now, we could revisit this. Think it would be possible to make the plugin not depend on a specific version of rspec, but maybe just a branch (e.g. 1.0.x)? Brandon From gramos at rectorado.unl.edu.ar Fri Jun 8 09:20:31 2007 From: gramos at rectorado.unl.edu.ar (Gaston Ramos) Date: Fri, 8 Jun 2007 10:20:31 -0300 Subject: [rspec-users] Problem with response.should render_template In-Reply-To: <57c63afe0706071342o8360f27ube87d265c39ebd0e@mail.gmail.com> References: <20070607182041.GA32039@marlasina> <57c63afe0706071159u4ef726e6tadb3f1e2b5131764@mail.gmail.com> <20070607195345.GB5933@marlasina> <57c63afe0706071342o8360f27ube87d265c39ebd0e@mail.gmail.com> Message-ID: <20070608132031.GA10067@marlasina> El jue, 07 de jun de 2007, a las 03:42:39 -0500, David Chelimsky dijo: > On 6/7/07, Anthony Carlos wrote: > > Gaston: > > > > It looks like on line 42 you're passing :id => @doc_type. I've heard > > that that is the proper way to pass around ids. However, in this > > case, it looks like ActiveRecord is passing the entire object, not > > just the id. You could try replacing @doc_type with @doc_type.id. > > I think the code is fine and the spec needs to use the ids quoted > (strings) as Anthony suggests earlier in this thread. thanks, I changed the spec and it works! response.should redirect_to :action => 'show', :id => @doc_type > > > > > If it does work, I don't know why ActiveRecord is messing up. > > > > Let us know if it works. > > > > -Anthony > > > > On Jun 7, 2007, at 3:53 PM, Gast?n Ramos wrote: > > > > > El jue, 07 de jun de 2007, a las 01:59:01 -0500, David Chelimsky dijo: > > >> On 6/7/07, Gaston Ramos wrote: > > >>> Hello, I have problems with this spec controllers: > > >>> > > >>> http://pastie.caboo.se/68634 > > >>> > > >>> when I run: > > >>> rake spec:controllers > > >>> > > >>> I get this error: > > >>> > > >>> ...............F...... > > >>> > > >>> 1) > > >>> 'DocTypeController should update and redirect to show' FAILED > > >>> expected redirect to {:action=>"show", :id=>1}, got redirect to > > >>> "http://test.host/doc_type/show/%23%3CSpec%3A%3AMocks%3A%3AMock% > > >>> 3A0xb74a0d14%3E" > > >>> ./spec/controllers/doc_type_controller_spec.rb:63: > > >>> > > >>> Finished in 0.386261 seconds > > >>> > > >>> 22 examples, 1 failure > > >>> > > >>> I would appreciate any help. > > >> > > >> Can you please add the controller code to the pastie? > > > > > > > > > http://pastie.caboo.se/68657 > > > > > >> > > >>> > > >>> -- > > >>> Gast?n Ramos > > >>> > > >>> "I always thought Smalltalk would beat Java, I just didn't know > > >>> it would be > > >>> called 'Ruby' when it did." > > >>> -- Kent Beck > > >>> _______________________________________________ > > >>> rspec-users mailing list > > >>> rspec-users at rubyforge.org > > >>> http://rubyforge.org/mailman/listinfo/rspec-users > > >>> > > >> _______________________________________________ > > >> rspec-users mailing list > > >> rspec-users at rubyforge.org > > >> http://rubyforge.org/mailman/listinfo/rspec-users > > >> > > > > > > -- > > > Gast?n Ramos > > > > > > "I always thought Smalltalk would beat Java, I just didn't know it > > > would be > > > called 'Ruby' when it did." > > > -- Kent Beck > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Gast?n Ramos "I always thought Smalltalk would beat Java, I just didn't know it would be called 'Ruby' when it did." -- Kent Beck From dchelimsky at gmail.com Fri Jun 8 09:19:10 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Jun 2007 08:19:10 -0500 Subject: [rspec-users] Still recommend the plugins over the gems? In-Reply-To: <1C8B898D-B6AF-405D-B6A5-CFFF641074D4@gmail.com> References: <7253F8CB-41F4-4BF6-8871-57E5F191D2FD@collectiveinsight.net> <57c63afe0706080542j5b2c0a01r15ef954d39a7797c@mail.gmail.com> <1C8B898D-B6AF-405D-B6A5-CFFF641074D4@gmail.com> Message-ID: <57c63afe0706080619w6cd820e4v766d98d8d49e35aa@mail.gmail.com> On 6/8/07, Brandon Keepers wrote: > > On Jun 8, 2007, at 8:42 AM, David Chelimsky wrote: > > > We started off w/ gems but decided w/ all the volatility it was easier > > to manage different versions directly in the app as plugins. As things > > are less volatile now, we could revisit this. > > Think it would be possible to make the plugin not depend on a > specific version of rspec, but maybe just a branch (e.g. 1.0.x)? I'm not sure we're there yet. With 1.0, we committed to reducing volatility in the public API. rspec_on_rails, however, is an extension of rspec and most of the extension points are not published extension points. We're basically subclassing specific classes in RSpec. If the structure changes, which it might if we decide there's value in it, we're going to have to mirror those changes in rspec_on_rails. We've started to provide extension APIs like using Spec::Runner.configure instead of forcing you to monkey patch rspec to include modules in the examples, etc. But we have a long way to go before I'd be comfortable decoupling rspec_on_rails from rspec in this way. David > > Brandon > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jun 8 09:48:29 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Jun 2007 08:48:29 -0500 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> Message-ID: <57c63afe0706080648ucda2d97u9abce1aa5f37870c@mail.gmail.com> On 6/8/07, aslak hellesoy wrote: > On 6/8/07, Scott Taylor wrote: > > > > Test First Development is great...But should you use it when you are > > adding classes/methods on to external library that doesn't have an > > extensive test suite? I noticed that the rspec plugin for autotest > > has no specs. > > > > David Chemlinsky said something to the list a while back that has > > been stewing in my subconscious - that you develop software > > differently using Test First Development/BDD. I noticed that it > > David (Chelimsky is his last name) and Ryan Davis paired on the RSpec > plugin for Autotest at Railsconf, and I suspect that "they didn't have > time" to write specs for it ;-) > > Look at the number of bugs that have been reported (and fixed) against > RSpec's Autotest plugin in the previous weeks. > > Maybe there is a relationship between the number of bugs and the lack > of specs? ;-) Definitely. > > > would be very hard to add a spec library to autotest (I once > > performed some code coverage on it and I believe it was at something > > like 30 or 40 percent.). So if one wanted to develop something like > > the rspec plugin to autotest, would it be wise to develop it test first? Absolutely. TDD allows for the process that Ryan and I went through but I skipped an important step because I was excited to get it out the door. You're allowed to hack stuff together to figure out how it works. But you're then supposed to throw all of that code out and start over, test first. I failed to take this step :( That said, I think that most of the bugs that have been reported wouldn't have been tested against anyhow - they've mostly been due to conflicts between varying versions of spec.opts and file loading issues that I never saw happen and therefore wouldn't have likely considered to describe. This is part of the nature of TDD. TDD didn't evolve in one or two-man, all-developer shops. It evolved on teams that included testers. The goal was never for the tests to serve as tests as far as the customer was concerned. It was about design. It was about documentation. It was about making the job of the tester (the official tester w/ the title and all) easier by reducing the number of bugs they had to deal with. This meant that they could focus more on the really important stuff instead of getting hung up on the trivial stuff that *should* have been caught during development. This helped to reduce the thrashing that often occurred once you reached the testing phase. That's part of why BDD came to be - to help put the focus back in the right places: developers develop, testers test. In the end, even the most disciplined TDD'er is only going to write examples for the things he/she thinks of. You still should have a tester on your team. The person who lives and breathes breaking code, rather than developing code. We don't have a person like that on the RSpec team. Well, actually, we DO have that. It's all of you! Which means, really, we shouldn't be making major releases without release candidates. I think RC is open source's informal means of exploratory testing. > Any code that doesn't have automated tests works by accident as far as > I'm concerned. > It makes no difference whether the code is using a third party library > or code whether it's part of your own code. > > However, some third party libraries (like J2EE) makes it so hard to > test any code using it that you essentially have to choose between the > third party or the ability to test. Sometimes having both is too much > work. In terms of rspec and autotest, I think we're somewhere in the middle here. Scott points out 30-40% coverage on autotest. There's a school of thought in TDD that says "test your own code," implying that you don't test 3rd party libraries. You test that your code interacts w/ the 3rd party code per the published API, but you either trust that the 3rd party code works or you either accept the possibility of bugs because the benefits are worth it or you don't use it. For me, autotest has been great. There have been some integration problems w/ rspec but while they've been annoying they haven't instilled fear in me that I'm getting the wrong feedback. So I put up with it. But we could certainly get some tests around the existing integration points: The test-to-file mappings, the command that gets generated, etc. Patches welcome! Cheers, David > > Aslak > > > I'm not sure if anyone else has had this difficulty, or if I'm being > > clear. Let me know if I should clarify with some examples. > > > > Best, > > > > Scott > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dj at collectiveinsight.net Fri Jun 8 10:05:32 2007 From: dj at collectiveinsight.net (David James) Date: Fri, 8 Jun 2007 09:05:32 -0500 Subject: [rspec-users] Testing two interdependent ActiveRecord models Message-ID: <9EB53500-25A5-49C8-93B7-245CF48D34CB@collectiveinsight.net> Hello, In my app, I'd like to test two model object objects that interact with each other. (In my example, a Person can have Contributions.) I guess you could say that I'm testing ActiveRecord associations. For example, a Person has zero or many Contributions. A Contribution has one or more People. This is the very basic version, but I think it will illustrate the dependency. (In practice, I'm interested in testing these associations because there is some extra logic going on that needs testing.) Here are my observations / questions: 1. Since there are two models, it doesn't seem quite right to make a unit test for this, does it? 2. There is an interaction between the two models. What is a good way to test the interaction? Do I put some of the testing in person_spec.rb and some in contribution_spec.rb? Or do I create some sort of "interaction" spec? 3. I don't think that an integration test makes sense, because I don't want to test the controller and views. 4. I wonder if mocks or stubs would make sense. I don't think I need to stub out a particular method (i.e. credit card processing), though. I'm pretty new to mocking, any advice or perspective would be helpful. I would appreciate any feedback -- testing philosophy, and maybe some hand waving, if you like. :) I would also be open to a refactoring / redesign if that will help with testing. Thanks, -David From justnothing at tiscali.co.uk Fri Jun 8 11:00:38 2007 From: justnothing at tiscali.co.uk (David Green) Date: Fri, 8 Jun 2007 08:00:38 -0700 (PDT) Subject: [rspec-users] checking associated objects have been deleted In-Reply-To: <57c63afe0706070543m29528a0ck96e8309e1c499cda@mail.gmail.com> References: <9612333e0706070254x7fa90460g4203ee0c64cf26d0@mail.gmail.com> <57c63afe0706070541m1949e008xf6f29212913e0b27@mail.gmail.com> <57c63afe0706070543m29528a0ck96e8309e1c499cda@mail.gmail.com> Message-ID: <11028074.post@talk.nabble.com> On 6/7/07, David Chelimsky wrote: > On 6/7/07, David Green wrote: > > I have the following model: > > > > class Book < ActiveRecord::Base > > has_many :taggings, :dependent => :delete_all > > has_many :tags, :through => :taggings > > end > > > > is it possible to check that associated taggings are being destroyed > > using mocks? I don't want to test that rails is deleting the > > associations, I want to test that I have specified the association as > > a dependent one. > > > > the only way I can think of is to use fixtures (or create real > > associations in the before callback) and then check that they have > > been deleted using Taggings.count(). Can it be done using mocks > > instead? > > > > describe Book do > > > > before do > > @book = mock_model(Book) > > @tagging = mock_model(Tagging) > > @book.stub!(:taggings).and_return([@tagging, @tagging]) > > end > > > > it "should delete associated taggings when destroyed" do > > end > > > > end > > You have to create a real book, but you can create a mock tagging: Actually, you don't have to save it - you can use #new instead of create: book = Book.new(:title => "the book") book.taggings << tagging = mock_model(Tagging, :[]= => true, :save => true) tagging.should_receive(:destroy) book.destroy > > Cheers, > David > hi David that spec fails because associations defined using :dependent => :delete_all don't call the destroy() method on associated objects. I'm not sure if I can avoid creating and counting objects after all thanks dave -- View this message in context: http://www.nabble.com/checking-associated-objects-have-been-deleted-tf3882933.html#a11028074 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Fri Jun 8 11:02:47 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Jun 2007 10:02:47 -0500 Subject: [rspec-users] checking associated objects have been deleted In-Reply-To: <11028074.post@talk.nabble.com> References: <9612333e0706070254x7fa90460g4203ee0c64cf26d0@mail.gmail.com> <57c63afe0706070541m1949e008xf6f29212913e0b27@mail.gmail.com> <57c63afe0706070543m29528a0ck96e8309e1c499cda@mail.gmail.com> <11028074.post@talk.nabble.com> Message-ID: <57c63afe0706080802o72ccfc06lc18d9a53baa3bb1e@mail.gmail.com> On 6/8/07, David Green wrote: > > > > On 6/7/07, David Chelimsky wrote: > > On 6/7/07, David Green wrote: > > > I have the following model: > > > > > > class Book < ActiveRecord::Base > > > has_many :taggings, :dependent => :delete_all > > > has_many :tags, :through => :taggings > > > end > > > > > > is it possible to check that associated taggings are being destroyed > > > using mocks? I don't want to test that rails is deleting the > > > associations, I want to test that I have specified the association as > > > a dependent one. > > > > > > the only way I can think of is to use fixtures (or create real > > > associations in the before callback) and then check that they have > > > been deleted using Taggings.count(). Can it be done using mocks > > > instead? > > > > > > describe Book do > > > > > > before do > > > @book = mock_model(Book) > > > @tagging = mock_model(Tagging) > > > @book.stub!(:taggings).and_return([@tagging, @tagging]) > > > end > > > > > > it "should delete associated taggings when destroyed" do > > > end > > > > > > end > > > > You have to create a real book, but you can create a mock tagging: > > Actually, you don't have to save it - you can use #new instead of create: > > book = Book.new(:title => "the book") > book.taggings << tagging = mock_model(Tagging, :[]= => true, :save => true) > tagging.should_receive(:destroy) > book.destroy > > > > > Cheers, > > David > > > > hi David > > that spec fails because associations defined using :dependent => :delete_all > don't call the destroy() method on associated objects. I'm not sure if I can > avoid creating and counting objects after all Ah - i had set up :dependent => :destroy. Bummer. > > thanks > dave > -- > View this message in context: http://www.nabble.com/checking-associated-objects-have-been-deleted-tf3882933.html#a11028074 > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Fri Jun 8 12:31:10 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 8 Jun 2007 12:31:10 -0400 Subject: [rspec-users] autotest bug? In-Reply-To: <09B09896-C571-4D98-9515-D501359EFBC8@wincent.com> References: <89FA19F0-B330-4492-B141-C0F77289D9B3@railsnewbie.com> <09B09896-C571-4D98-9515-D501359EFBC8@wincent.com> Message-ID: On Jun 8, 2007, at 8:48 AM, Wincent Colaiuta wrote: > El 8/6/2007, a las 14:09, Scott Taylor escribi?: > >> On Jun 8, 2007, at 4:01 AM, Wincent Colaiuta wrote: >> >>> Have you removed these lines from your spec/spec.opts file (no >>> longer >>> necessary)? >>> >>> --format >>> failing_examples:previous_failures.txt >>> --example >>> previous_failures.txt >> >> In what revision did that change?! Is this applicable only to >> rspec_on_rails, or to rspec generally? > > I don't remember which exact revision, but I was seeing the exact > same problem until David set me straight in this post rubyforge.org/pipermail/rspec-users/2007-May/001650.html>: > >> These lines configure rspec to limit the number of files that get run >> when there are failures, but autotest is doing the same thing so >> there >> is no need. > > I believe that file is specific to rspec_on_rails, in any case. > > For the record, when working in a Rails app, each time you do arspec/ > rspec_on_rails plugin update I think you should probably run "script/ > generate rspec" from the top level of your app; if it tells you that > spec/spec.opts has been modified then you can hit the "d" key to see > a diff of exactly what's changed... In one of the recent RSpec > updates, they dropped those lines from spec/spec.opts. Ah - that diff is very helpful. I had no idea. Thanks, Scott From dchelimsky at gmail.com Fri Jun 8 12:40:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Jun 2007 11:40:40 -0500 Subject: [rspec-users] autotest bug? In-Reply-To: References: <89FA19F0-B330-4492-B141-C0F77289D9B3@railsnewbie.com> <09B09896-C571-4D98-9515-D501359EFBC8@wincent.com> Message-ID: <57c63afe0706080940r64f6dc27u392e6c13a467b26f@mail.gmail.com> On 6/8/07, Scott Taylor wrote: > > On Jun 8, 2007, at 8:48 AM, Wincent Colaiuta wrote: > > > El 8/6/2007, a las 14:09, Scott Taylor escribi?: > > > >> On Jun 8, 2007, at 4:01 AM, Wincent Colaiuta wrote: > >> > >>> Have you removed these lines from your spec/spec.opts file (no > >>> longer > >>> necessary)? > >>> > >>> --format > >>> failing_examples:previous_failures.txt > >>> --example > >>> previous_failures.txt > >> > >> In what revision did that change?! Is this applicable only to > >> rspec_on_rails, or to rspec generally? > > > > I don't remember which exact revision, but I was seeing the exact > > same problem until David set me straight in this post > rubyforge.org/pipermail/rspec-users/2007-May/001650.html>: > > > >> These lines configure rspec to limit the number of files that get run > >> when there are failures, but autotest is doing the same thing so > >> there > >> is no need. > > > > I believe that file is specific to rspec_on_rails, in any case. > > > > For the record, when working in a Rails app, each time you do arspec/ > > rspec_on_rails plugin update I think you should probably run "script/ > > generate rspec" from the top level of your app; if it tells you that > > spec/spec.opts has been modified then you can hit the "d" key to see > > a diff of exactly what's changed... In one of the recent RSpec > > updates, they dropped those lines from spec/spec.opts. > > Ah - that diff is very helpful. I had no idea. I did blog about it a while back: http://blog.davidchelimsky.net/articles/2007/05/29/rspec-and-autotest I'll also add it to the upgrade page http://rspec.rubyforge.org/upgrade.html > > Thanks, > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jonathan at parkerhill.com Fri Jun 8 13:06:29 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Fri, 8 Jun 2007 13:06:29 -0400 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: <57c63afe0706080648ucda2d97u9abce1aa5f37870c@mail.gmail.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> <57c63afe0706080648ucda2d97u9abce1aa5f37870c@mail.gmail.com> Message-ID: <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> most plugins come with their own rails tests i've converted one by hand to rspec (restful_authentication) because - its functionality is integral to my app - its really a generator so the code ends up in my app - there's a good chance i'll be making custom changes to it as my app develops perhaps a tool that automatically converts rails tests to rspecs would be useful? obviously thats not TDD but it would give you the code coverage and provide a starting point if you make custom changes to the plugin On Jun 8, 2007, at 9:48 AM, David Chelimsky wrote: > On 6/8/07, aslak hellesoy wrote: >> On 6/8/07, Scott Taylor wrote: >>> >>> Test First Development is great...But should you use it when you are >>> adding classes/methods on to external library that doesn't have an >>> extensive test suite? I noticed that the rspec plugin for autotest >>> has no specs. >>> >>> David Chemlinsky said something to the list a while back that has >>> been stewing in my subconscious - that you develop software >>> differently using Test First Development/BDD. I noticed that it >> >> David (Chelimsky is his last name) and Ryan Davis paired on the RSpec >> plugin for Autotest at Railsconf, and I suspect that "they didn't >> have >> time" to write specs for it ;-) >> >> Look at the number of bugs that have been reported (and fixed) >> against >> RSpec's Autotest plugin in the previous weeks. >> >> Maybe there is a relationship between the number of bugs and the lack >> of specs? ;-) > > Definitely. > >> >>> would be very hard to add a spec library to autotest (I once >>> performed some code coverage on it and I believe it was at something >>> like 30 or 40 percent.). So if one wanted to develop something like >>> the rspec plugin to autotest, would it be wise to develop it test >>> first? > > Absolutely. TDD allows for the process that Ryan and I went through > but I skipped an important step because I was excited to get it out > the door. You're allowed to hack stuff together to figure out how it > works. But you're then supposed to throw all of that code out and > start over, test first. I failed to take this step :( > > That said, I think that most of the bugs that have been reported > wouldn't have been tested against anyhow - they've mostly been due to > conflicts between varying versions of spec.opts and file loading > issues that I never saw happen and therefore wouldn't have likely > considered to describe. > > This is part of the nature of TDD. TDD didn't evolve in one or > two-man, all-developer shops. It evolved on teams that included > testers. The goal was never for the tests to serve as tests as far as > the customer was concerned. It was about design. It was about > documentation. It was about making the job of the tester (the official > tester w/ the title and all) easier by reducing the number of bugs > they had to deal with. This meant that they could focus more on the > really important stuff instead of getting hung up on the trivial stuff > that *should* have been caught during development. This helped to > reduce the thrashing that often occurred once you reached the testing > phase. > > That's part of why BDD came to be - to help put the focus back in the > right places: developers develop, testers test. > > In the end, even the most disciplined TDD'er is only going to write > examples for the things he/she thinks of. You still should have a > tester on your team. The person who lives and breathes breaking code, > rather than developing code. We don't have a person like that on the > RSpec team. Well, actually, we DO have that. It's all of you! Which > means, really, we shouldn't be making major releases without release > candidates. I think RC is open source's informal means of exploratory > testing. > >> Any code that doesn't have automated tests works by accident as >> far as >> I'm concerned. >> It makes no difference whether the code is using a third party >> library >> or code whether it's part of your own code. >> >> However, some third party libraries (like J2EE) makes it so hard to >> test any code using it that you essentially have to choose between >> the >> third party or the ability to test. Sometimes having both is too much >> work. > > In terms of rspec and autotest, I think we're somewhere in the middle > here. Scott points out 30-40% coverage on autotest. There's a school > of thought in TDD that says "test your own code," implying that you > don't test 3rd party libraries. You test that your code interacts w/ > the 3rd party code per the published API, but you either trust that > the 3rd party code works or you either accept the possibility of bugs > because the benefits are worth it or you don't use it. > > For me, autotest has been great. There have been some integration > problems w/ rspec but while they've been annoying they haven't > instilled fear in me that I'm getting the wrong feedback. So I put up > with it. > > But we could certainly get some tests around the existing integration > points: The test-to-file mappings, the command that gets generated, > etc. Patches welcome! > > Cheers, > David > >> >> Aslak >> >>> I'm not sure if anyone else has had this difficulty, or if I'm being >>> clear. Let me know if I should clarify with some examples. >>> >>> Best, >>> >>> Scott >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Jun 8 13:15:44 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Jun 2007 12:15:44 -0500 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> <57c63afe0706080648ucda2d97u9abce1aa5f37870c@mail.gmail.com> <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> Message-ID: <57c63afe0706081015n76bba66ej3e6ca68c9740c8a5@mail.gmail.com> On 6/8/07, Jonathan Linowes wrote: > most plugins come with their own rails tests > > i've converted one by hand to rspec (restful_authentication) because > - its functionality is integral to my app > - its really a generator so the code ends up in my app > - there's a good chance i'll be making custom changes to it as my app > develops > > perhaps a tool that automatically converts rails tests to rspecs > would be useful? We had one of those a while back. It was pretty good, but not perfect. It's very complex to get right and cover all the possibilities and it's something that we will likely not build as part of rspec. That said, if somebody else wanted to create such a thing, I'm sure you'd make a lot of people happy. > obviously thats not TDD but it would give you the code coverage > and provide a starting point if you make custom changes to the plugin > > > On Jun 8, 2007, at 9:48 AM, David Chelimsky wrote: > > > On 6/8/07, aslak hellesoy wrote: > >> On 6/8/07, Scott Taylor wrote: > >>> > >>> Test First Development is great...But should you use it when you are > >>> adding classes/methods on to external library that doesn't have an > >>> extensive test suite? I noticed that the rspec plugin for autotest > >>> has no specs. > >>> > >>> David Chemlinsky said something to the list a while back that has > >>> been stewing in my subconscious - that you develop software > >>> differently using Test First Development/BDD. I noticed that it > >> > >> David (Chelimsky is his last name) and Ryan Davis paired on the RSpec > >> plugin for Autotest at Railsconf, and I suspect that "they didn't > >> have > >> time" to write specs for it ;-) > >> > >> Look at the number of bugs that have been reported (and fixed) > >> against > >> RSpec's Autotest plugin in the previous weeks. > >> > >> Maybe there is a relationship between the number of bugs and the lack > >> of specs? ;-) > > > > Definitely. > > > >> > >>> would be very hard to add a spec library to autotest (I once > >>> performed some code coverage on it and I believe it was at something > >>> like 30 or 40 percent.). So if one wanted to develop something like > >>> the rspec plugin to autotest, would it be wise to develop it test > >>> first? > > > > Absolutely. TDD allows for the process that Ryan and I went through > > but I skipped an important step because I was excited to get it out > > the door. You're allowed to hack stuff together to figure out how it > > works. But you're then supposed to throw all of that code out and > > start over, test first. I failed to take this step :( > > > > That said, I think that most of the bugs that have been reported > > wouldn't have been tested against anyhow - they've mostly been due to > > conflicts between varying versions of spec.opts and file loading > > issues that I never saw happen and therefore wouldn't have likely > > considered to describe. > > > > This is part of the nature of TDD. TDD didn't evolve in one or > > two-man, all-developer shops. It evolved on teams that included > > testers. The goal was never for the tests to serve as tests as far as > > the customer was concerned. It was about design. It was about > > documentation. It was about making the job of the tester (the official > > tester w/ the title and all) easier by reducing the number of bugs > > they had to deal with. This meant that they could focus more on the > > really important stuff instead of getting hung up on the trivial stuff > > that *should* have been caught during development. This helped to > > reduce the thrashing that often occurred once you reached the testing > > phase. > > > > That's part of why BDD came to be - to help put the focus back in the > > right places: developers develop, testers test. > > > > In the end, even the most disciplined TDD'er is only going to write > > examples for the things he/she thinks of. You still should have a > > tester on your team. The person who lives and breathes breaking code, > > rather than developing code. We don't have a person like that on the > > RSpec team. Well, actually, we DO have that. It's all of you! Which > > means, really, we shouldn't be making major releases without release > > candidates. I think RC is open source's informal means of exploratory > > testing. > > > >> Any code that doesn't have automated tests works by accident as > >> far as > >> I'm concerned. > >> It makes no difference whether the code is using a third party > >> library > >> or code whether it's part of your own code. > >> > >> However, some third party libraries (like J2EE) makes it so hard to > >> test any code using it that you essentially have to choose between > >> the > >> third party or the ability to test. Sometimes having both is too much > >> work. > > > > In terms of rspec and autotest, I think we're somewhere in the middle > > here. Scott points out 30-40% coverage on autotest. There's a school > > of thought in TDD that says "test your own code," implying that you > > don't test 3rd party libraries. You test that your code interacts w/ > > the 3rd party code per the published API, but you either trust that > > the 3rd party code works or you either accept the possibility of bugs > > because the benefits are worth it or you don't use it. > > > > For me, autotest has been great. There have been some integration > > problems w/ rspec but while they've been annoying they haven't > > instilled fear in me that I'm getting the wrong feedback. So I put up > > with it. > > > > But we could certainly get some tests around the existing integration > > points: The test-to-file mappings, the command that gets generated, > > etc. Patches welcome! > > > > Cheers, > > David > > > >> > >> Aslak > >> > >>> I'm not sure if anyone else has had this difficulty, or if I'm being > >>> clear. Let me know if I should clarify with some examples. > >>> > >>> Best, > >>> > >>> Scott > >>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >>> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Fri Jun 8 13:21:37 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 8 Jun 2007 13:21:37 -0400 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> <57c63afe0706080648ucda2d97u9abce1aa5f37870c@mail.gmail.com> <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> Message-ID: <66EB0AAB-DBDB-4DB7-B1FB-A8A1DEB1F016@railsnewbie.com> On Jun 8, 2007, at 1:06 PM, Jonathan Linowes wrote: > most plugins come with their own rails tests > > i've converted one by hand to rspec (restful_authentication) because > - its functionality is integral to my app > - its really a generator so the code ends up in my app > - there's a good chance i'll be making custom changes to it as my app > develops > I thought about doing the same thing a while back. You might want to send those specs back to Rick Olson. Scott > On Jun 8, 2007, at 9:48 AM, David Chelimsky wrote: > >> On 6/8/07, aslak hellesoy wrote: >>> On 6/8/07, Scott Taylor wrote: >>>> >>>> Test First Development is great...But should you use it when you >>>> are >>>> adding classes/methods on to external library that doesn't have an >>>> extensive test suite? I noticed that the rspec plugin for autotest >>>> has no specs. >>>> >>>> David Chemlinsky said something to the list a while back that has >>>> been stewing in my subconscious - that you develop software >>>> differently using Test First Development/BDD. I noticed that it >>> >>> David (Chelimsky is his last name) and Ryan Davis paired on the >>> RSpec >>> plugin for Autotest at Railsconf, and I suspect that "they didn't >>> have >>> time" to write specs for it ;-) >>> >>> Look at the number of bugs that have been reported (and fixed) >>> against >>> RSpec's Autotest plugin in the previous weeks. >>> >>> Maybe there is a relationship between the number of bugs and the >>> lack >>> of specs? ;-) >> >> Definitely. >> >>> >>>> would be very hard to add a spec library to autotest (I once >>>> performed some code coverage on it and I believe it was at >>>> something >>>> like 30 or 40 percent.). So if one wanted to develop something >>>> like >>>> the rspec plugin to autotest, would it be wise to develop it test >>>> first? >> >> Absolutely. TDD allows for the process that Ryan and I went through >> but I skipped an important step because I was excited to get it out >> the door. You're allowed to hack stuff together to figure out how it >> works. But you're then supposed to throw all of that code out and >> start over, test first. I failed to take this step :( >> >> That said, I think that most of the bugs that have been reported >> wouldn't have been tested against anyhow - they've mostly been due to >> conflicts between varying versions of spec.opts and file loading >> issues that I never saw happen and therefore wouldn't have likely >> considered to describe. >> >> This is part of the nature of TDD. TDD didn't evolve in one or >> two-man, all-developer shops. It evolved on teams that included >> testers. The goal was never for the tests to serve as tests as far as >> the customer was concerned. It was about design. It was about >> documentation. It was about making the job of the tester (the >> official >> tester w/ the title and all) easier by reducing the number of bugs >> they had to deal with. This meant that they could focus more on the >> really important stuff instead of getting hung up on the trivial >> stuff >> that *should* have been caught during development. This helped to >> reduce the thrashing that often occurred once you reached the testing >> phase. >> >> That's part of why BDD came to be - to help put the focus back in the >> right places: developers develop, testers test. >> >> In the end, even the most disciplined TDD'er is only going to write >> examples for the things he/she thinks of. You still should have a >> tester on your team. The person who lives and breathes breaking code, >> rather than developing code. We don't have a person like that on the >> RSpec team. Well, actually, we DO have that. It's all of you! Which >> means, really, we shouldn't be making major releases without release >> candidates. I think RC is open source's informal means of exploratory >> testing. >> >>> Any code that doesn't have automated tests works by accident as >>> far as >>> I'm concerned. >>> It makes no difference whether the code is using a third party >>> library >>> or code whether it's part of your own code. >>> >>> However, some third party libraries (like J2EE) makes it so hard to >>> test any code using it that you essentially have to choose between >>> the >>> third party or the ability to test. Sometimes having both is too >>> much >>> work. >> >> In terms of rspec and autotest, I think we're somewhere in the middle >> here. Scott points out 30-40% coverage on autotest. There's a school >> of thought in TDD that says "test your own code," implying that you >> don't test 3rd party libraries. You test that your code interacts w/ >> the 3rd party code per the published API, but you either trust that >> the 3rd party code works or you either accept the possibility of bugs >> because the benefits are worth it or you don't use it. >> >> For me, autotest has been great. There have been some integration >> problems w/ rspec but while they've been annoying they haven't >> instilled fear in me that I'm getting the wrong feedback. So I put up >> with it. >> >> But we could certainly get some tests around the existing integration >> points: The test-to-file mappings, the command that gets generated, >> etc. Patches welcome! >> >> Cheers, >> David >> >>> >>> Aslak >>> >>>> I'm not sure if anyone else has had this difficulty, or if I'm >>>> being >>>> clear. Let me know if I should clarify with some examples. >>>> >>>> Best, >>>> >>>> Scott >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Fri Jun 8 13:22:55 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 8 Jun 2007 13:22:55 -0400 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: <57c63afe0706081015n76bba66ej3e6ca68c9740c8a5@mail.gmail.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> <57c63afe0706080648ucda2d97u9abce1aa5f37870c@mail.gmail.com> <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> <57c63afe0706081015n76bba66ej3e6ca68c9740c8a5@mail.gmail.com> Message-ID: On Jun 8, 2007, at 1:15 PM, David Chelimsky wrote: > On 6/8/07, Jonathan Linowes wrote: >> most plugins come with their own rails tests >> >> i've converted one by hand to rspec (restful_authentication) because >> - its functionality is integral to my app >> - its really a generator so the code ends up in my app >> - there's a good chance i'll be making custom changes to it as my app >> develops >> >> perhaps a tool that automatically converts rails tests to rspecs >> would be useful? > > We had one of those a while back. It was pretty good, but not perfect. > It's very complex to get right and cover all the possibilities and > it's something that we will likely not build as part of rspec. That > said, if somebody else wanted to create such a thing, I'm sure you'd > make a lot of people happy. Wow. That code must still be around somewhere in subversion (any hints as to it's last release?) Scott > >> obviously thats not TDD but it would give you the code coverage >> and provide a starting point if you make custom changes to the plugin >> >> >> On Jun 8, 2007, at 9:48 AM, David Chelimsky wrote: >> >>> On 6/8/07, aslak hellesoy wrote: >>>> On 6/8/07, Scott Taylor wrote: >>>>> >>>>> Test First Development is great...But should you use it when >>>>> you are >>>>> adding classes/methods on to external library that doesn't have an >>>>> extensive test suite? I noticed that the rspec plugin for >>>>> autotest >>>>> has no specs. >>>>> >>>>> David Chemlinsky said something to the list a while back that has >>>>> been stewing in my subconscious - that you develop software >>>>> differently using Test First Development/BDD. I noticed that it >>>> >>>> David (Chelimsky is his last name) and Ryan Davis paired on the >>>> RSpec >>>> plugin for Autotest at Railsconf, and I suspect that "they didn't >>>> have >>>> time" to write specs for it ;-) >>>> >>>> Look at the number of bugs that have been reported (and fixed) >>>> against >>>> RSpec's Autotest plugin in the previous weeks. >>>> >>>> Maybe there is a relationship between the number of bugs and the >>>> lack >>>> of specs? ;-) >>> >>> Definitely. >>> >>>> >>>>> would be very hard to add a spec library to autotest (I once >>>>> performed some code coverage on it and I believe it was at >>>>> something >>>>> like 30 or 40 percent.). So if one wanted to develop something >>>>> like >>>>> the rspec plugin to autotest, would it be wise to develop it test >>>>> first? >>> >>> Absolutely. TDD allows for the process that Ryan and I went through >>> but I skipped an important step because I was excited to get it out >>> the door. You're allowed to hack stuff together to figure out how it >>> works. But you're then supposed to throw all of that code out and >>> start over, test first. I failed to take this step :( >>> >>> That said, I think that most of the bugs that have been reported >>> wouldn't have been tested against anyhow - they've mostly been >>> due to >>> conflicts between varying versions of spec.opts and file loading >>> issues that I never saw happen and therefore wouldn't have likely >>> considered to describe. >>> >>> This is part of the nature of TDD. TDD didn't evolve in one or >>> two-man, all-developer shops. It evolved on teams that included >>> testers. The goal was never for the tests to serve as tests as >>> far as >>> the customer was concerned. It was about design. It was about >>> documentation. It was about making the job of the tester (the >>> official >>> tester w/ the title and all) easier by reducing the number of bugs >>> they had to deal with. This meant that they could focus more on the >>> really important stuff instead of getting hung up on the trivial >>> stuff >>> that *should* have been caught during development. This helped to >>> reduce the thrashing that often occurred once you reached the >>> testing >>> phase. >>> >>> That's part of why BDD came to be - to help put the focus back in >>> the >>> right places: developers develop, testers test. >>> >>> In the end, even the most disciplined TDD'er is only going to write >>> examples for the things he/she thinks of. You still should have a >>> tester on your team. The person who lives and breathes breaking >>> code, >>> rather than developing code. We don't have a person like that on the >>> RSpec team. Well, actually, we DO have that. It's all of you! Which >>> means, really, we shouldn't be making major releases without release >>> candidates. I think RC is open source's informal means of >>> exploratory >>> testing. >>> >>>> Any code that doesn't have automated tests works by accident as >>>> far as >>>> I'm concerned. >>>> It makes no difference whether the code is using a third party >>>> library >>>> or code whether it's part of your own code. >>>> >>>> However, some third party libraries (like J2EE) makes it so hard to >>>> test any code using it that you essentially have to choose between >>>> the >>>> third party or the ability to test. Sometimes having both is too >>>> much >>>> work. >>> >>> In terms of rspec and autotest, I think we're somewhere in the >>> middle >>> here. Scott points out 30-40% coverage on autotest. There's a school >>> of thought in TDD that says "test your own code," implying that you >>> don't test 3rd party libraries. You test that your code interacts w/ >>> the 3rd party code per the published API, but you either trust that >>> the 3rd party code works or you either accept the possibility of >>> bugs >>> because the benefits are worth it or you don't use it. >>> >>> For me, autotest has been great. There have been some integration >>> problems w/ rspec but while they've been annoying they haven't >>> instilled fear in me that I'm getting the wrong feedback. So I >>> put up >>> with it. >>> >>> But we could certainly get some tests around the existing >>> integration >>> points: The test-to-file mappings, the command that gets generated, >>> etc. Patches welcome! >>> >>> Cheers, >>> David >>> >>>> >>>> Aslak >>>> >>>>> I'm not sure if anyone else has had this difficulty, or if I'm >>>>> being >>>>> clear. Let me know if I should clarify with some examples. >>>>> >>>>> Best, >>>>> >>>>> Scott >>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Jun 8 13:23:52 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Jun 2007 12:23:52 -0500 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> <57c63afe0706080648ucda2d97u9abce1aa5f37870c@mail.gmail.com> <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> <57c63afe0706081015n76bba66ej3e6ca68c9740c8a5@mail.gmail.com> Message-ID: <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> On 6/8/07, Scott Taylor wrote: > > On Jun 8, 2007, at 1:15 PM, David Chelimsky wrote: > > > On 6/8/07, Jonathan Linowes wrote: > >> most plugins come with their own rails tests > >> > >> i've converted one by hand to rspec (restful_authentication) because > >> - its functionality is integral to my app > >> - its really a generator so the code ends up in my app > >> - there's a good chance i'll be making custom changes to it as my app > >> develops > >> > >> perhaps a tool that automatically converts rails tests to rspecs > >> would be useful? > > > > We had one of those a while back. It was pretty good, but not perfect. > > It's very complex to get right and cover all the possibilities and > > it's something that we will likely not build as part of rspec. That > > said, if somebody else wanted to create such a thing, I'm sure you'd > > make a lot of people happy. > > > Wow. That code must still be around somewhere in subversion (any > hints as to it's last release?) hint: svn log > > Scott > > > > > > >> obviously thats not TDD but it would give you the code coverage > >> and provide a starting point if you make custom changes to the plugin > >> > >> > >> On Jun 8, 2007, at 9:48 AM, David Chelimsky wrote: > >> > >>> On 6/8/07, aslak hellesoy wrote: > >>>> On 6/8/07, Scott Taylor wrote: > >>>>> > >>>>> Test First Development is great...But should you use it when > >>>>> you are > >>>>> adding classes/methods on to external library that doesn't have an > >>>>> extensive test suite? I noticed that the rspec plugin for > >>>>> autotest > >>>>> has no specs. > >>>>> > >>>>> David Chemlinsky said something to the list a while back that has > >>>>> been stewing in my subconscious - that you develop software > >>>>> differently using Test First Development/BDD. I noticed that it > >>>> > >>>> David (Chelimsky is his last name) and Ryan Davis paired on the > >>>> RSpec > >>>> plugin for Autotest at Railsconf, and I suspect that "they didn't > >>>> have > >>>> time" to write specs for it ;-) > >>>> > >>>> Look at the number of bugs that have been reported (and fixed) > >>>> against > >>>> RSpec's Autotest plugin in the previous weeks. > >>>> > >>>> Maybe there is a relationship between the number of bugs and the > >>>> lack > >>>> of specs? ;-) > >>> > >>> Definitely. > >>> > >>>> > >>>>> would be very hard to add a spec library to autotest (I once > >>>>> performed some code coverage on it and I believe it was at > >>>>> something > >>>>> like 30 or 40 percent.). So if one wanted to develop something > >>>>> like > >>>>> the rspec plugin to autotest, would it be wise to develop it test > >>>>> first? > >>> > >>> Absolutely. TDD allows for the process that Ryan and I went through > >>> but I skipped an important step because I was excited to get it out > >>> the door. You're allowed to hack stuff together to figure out how it > >>> works. But you're then supposed to throw all of that code out and > >>> start over, test first. I failed to take this step :( > >>> > >>> That said, I think that most of the bugs that have been reported > >>> wouldn't have been tested against anyhow - they've mostly been > >>> due to > >>> conflicts between varying versions of spec.opts and file loading > >>> issues that I never saw happen and therefore wouldn't have likely > >>> considered to describe. > >>> > >>> This is part of the nature of TDD. TDD didn't evolve in one or > >>> two-man, all-developer shops. It evolved on teams that included > >>> testers. The goal was never for the tests to serve as tests as > >>> far as > >>> the customer was concerned. It was about design. It was about > >>> documentation. It was about making the job of the tester (the > >>> official > >>> tester w/ the title and all) easier by reducing the number of bugs > >>> they had to deal with. This meant that they could focus more on the > >>> really important stuff instead of getting hung up on the trivial > >>> stuff > >>> that *should* have been caught during development. This helped to > >>> reduce the thrashing that often occurred once you reached the > >>> testing > >>> phase. > >>> > >>> That's part of why BDD came to be - to help put the focus back in > >>> the > >>> right places: developers develop, testers test. > >>> > >>> In the end, even the most disciplined TDD'er is only going to write > >>> examples for the things he/she thinks of. You still should have a > >>> tester on your team. The person who lives and breathes breaking > >>> code, > >>> rather than developing code. We don't have a person like that on the > >>> RSpec team. Well, actually, we DO have that. It's all of you! Which > >>> means, really, we shouldn't be making major releases without release > >>> candidates. I think RC is open source's informal means of > >>> exploratory > >>> testing. > >>> > >>>> Any code that doesn't have automated tests works by accident as > >>>> far as > >>>> I'm concerned. > >>>> It makes no difference whether the code is using a third party > >>>> library > >>>> or code whether it's part of your own code. > >>>> > >>>> However, some third party libraries (like J2EE) makes it so hard to > >>>> test any code using it that you essentially have to choose between > >>>> the > >>>> third party or the ability to test. Sometimes having both is too > >>>> much > >>>> work. > >>> > >>> In terms of rspec and autotest, I think we're somewhere in the > >>> middle > >>> here. Scott points out 30-40% coverage on autotest. There's a school > >>> of thought in TDD that says "test your own code," implying that you > >>> don't test 3rd party libraries. You test that your code interacts w/ > >>> the 3rd party code per the published API, but you either trust that > >>> the 3rd party code works or you either accept the possibility of > >>> bugs > >>> because the benefits are worth it or you don't use it. > >>> > >>> For me, autotest has been great. There have been some integration > >>> problems w/ rspec but while they've been annoying they haven't > >>> instilled fear in me that I'm getting the wrong feedback. So I > >>> put up > >>> with it. > >>> > >>> But we could certainly get some tests around the existing > >>> integration > >>> points: The test-to-file mappings, the command that gets generated, > >>> etc. Patches welcome! > >>> > >>> Cheers, > >>> David > >>> > >>>> > >>>> Aslak > >>>> > >>>>> I'm not sure if anyone else has had this difficulty, or if I'm > >>>>> being > >>>>> clear. Let me know if I should clarify with some examples. > >>>>> > >>>>> Best, > >>>>> > >>>>> Scott > >>>>> > >>>>> _______________________________________________ > >>>>> rspec-users mailing list > >>>>> rspec-users at rubyforge.org > >>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>> > >>>> _______________________________________________ > >>>> rspec-users mailing list > >>>> rspec-users at rubyforge.org > >>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jun 8 13:24:50 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Jun 2007 12:24:50 -0500 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> <57c63afe0706080648ucda2d97u9abce1aa5f37870c@mail.gmail.com> <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> <57c63afe0706081015n76bba66ej3e6ca68c9740c8a5@mail.gmail.com> <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> Message-ID: <57c63afe0706081024t68fb0235xe4977ea031b5a2ad@mail.gmail.com> On 6/8/07, David Chelimsky wrote: > On 6/8/07, Scott Taylor wrote: > > > > On Jun 8, 2007, at 1:15 PM, David Chelimsky wrote: > > > > > On 6/8/07, Jonathan Linowes wrote: > > >> most plugins come with their own rails tests > > >> > > >> i've converted one by hand to rspec (restful_authentication) because > > >> - its functionality is integral to my app > > >> - its really a generator so the code ends up in my app > > >> - there's a good chance i'll be making custom changes to it as my app > > >> develops > > >> > > >> perhaps a tool that automatically converts rails tests to rspecs > > >> would be useful? > > > > > > We had one of those a while back. It was pretty good, but not perfect. > > > It's very complex to get right and cover all the possibilities and > > > it's something that we will likely not build as part of rspec. That > > > said, if somebody else wanted to create such a thing, I'm sure you'd > > > make a lot of people happy. > > > > > > Wow. That code must still be around somewhere in subversion (any > > hints as to it's last release?) > > hint: svn log hint 2: http://rspec.rubyforge.org/changes.html (look for test2spec) > > > > > Scott > > > > > > > > > > > >> obviously thats not TDD but it would give you the code coverage > > >> and provide a starting point if you make custom changes to the plugin > > >> > > >> > > >> On Jun 8, 2007, at 9:48 AM, David Chelimsky wrote: > > >> > > >>> On 6/8/07, aslak hellesoy wrote: > > >>>> On 6/8/07, Scott Taylor wrote: > > >>>>> > > >>>>> Test First Development is great...But should you use it when > > >>>>> you are > > >>>>> adding classes/methods on to external library that doesn't have an > > >>>>> extensive test suite? I noticed that the rspec plugin for > > >>>>> autotest > > >>>>> has no specs. > > >>>>> > > >>>>> David Chemlinsky said something to the list a while back that has > > >>>>> been stewing in my subconscious - that you develop software > > >>>>> differently using Test First Development/BDD. I noticed that it > > >>>> > > >>>> David (Chelimsky is his last name) and Ryan Davis paired on the > > >>>> RSpec > > >>>> plugin for Autotest at Railsconf, and I suspect that "they didn't > > >>>> have > > >>>> time" to write specs for it ;-) > > >>>> > > >>>> Look at the number of bugs that have been reported (and fixed) > > >>>> against > > >>>> RSpec's Autotest plugin in the previous weeks. > > >>>> > > >>>> Maybe there is a relationship between the number of bugs and the > > >>>> lack > > >>>> of specs? ;-) > > >>> > > >>> Definitely. > > >>> > > >>>> > > >>>>> would be very hard to add a spec library to autotest (I once > > >>>>> performed some code coverage on it and I believe it was at > > >>>>> something > > >>>>> like 30 or 40 percent.). So if one wanted to develop something > > >>>>> like > > >>>>> the rspec plugin to autotest, would it be wise to develop it test > > >>>>> first? > > >>> > > >>> Absolutely. TDD allows for the process that Ryan and I went through > > >>> but I skipped an important step because I was excited to get it out > > >>> the door. You're allowed to hack stuff together to figure out how it > > >>> works. But you're then supposed to throw all of that code out and > > >>> start over, test first. I failed to take this step :( > > >>> > > >>> That said, I think that most of the bugs that have been reported > > >>> wouldn't have been tested against anyhow - they've mostly been > > >>> due to > > >>> conflicts between varying versions of spec.opts and file loading > > >>> issues that I never saw happen and therefore wouldn't have likely > > >>> considered to describe. > > >>> > > >>> This is part of the nature of TDD. TDD didn't evolve in one or > > >>> two-man, all-developer shops. It evolved on teams that included > > >>> testers. The goal was never for the tests to serve as tests as > > >>> far as > > >>> the customer was concerned. It was about design. It was about > > >>> documentation. It was about making the job of the tester (the > > >>> official > > >>> tester w/ the title and all) easier by reducing the number of bugs > > >>> they had to deal with. This meant that they could focus more on the > > >>> really important stuff instead of getting hung up on the trivial > > >>> stuff > > >>> that *should* have been caught during development. This helped to > > >>> reduce the thrashing that often occurred once you reached the > > >>> testing > > >>> phase. > > >>> > > >>> That's part of why BDD came to be - to help put the focus back in > > >>> the > > >>> right places: developers develop, testers test. > > >>> > > >>> In the end, even the most disciplined TDD'er is only going to write > > >>> examples for the things he/she thinks of. You still should have a > > >>> tester on your team. The person who lives and breathes breaking > > >>> code, > > >>> rather than developing code. We don't have a person like that on the > > >>> RSpec team. Well, actually, we DO have that. It's all of you! Which > > >>> means, really, we shouldn't be making major releases without release > > >>> candidates. I think RC is open source's informal means of > > >>> exploratory > > >>> testing. > > >>> > > >>>> Any code that doesn't have automated tests works by accident as > > >>>> far as > > >>>> I'm concerned. > > >>>> It makes no difference whether the code is using a third party > > >>>> library > > >>>> or code whether it's part of your own code. > > >>>> > > >>>> However, some third party libraries (like J2EE) makes it so hard to > > >>>> test any code using it that you essentially have to choose between > > >>>> the > > >>>> third party or the ability to test. Sometimes having both is too > > >>>> much > > >>>> work. > > >>> > > >>> In terms of rspec and autotest, I think we're somewhere in the > > >>> middle > > >>> here. Scott points out 30-40% coverage on autotest. There's a school > > >>> of thought in TDD that says "test your own code," implying that you > > >>> don't test 3rd party libraries. You test that your code interacts w/ > > >>> the 3rd party code per the published API, but you either trust that > > >>> the 3rd party code works or you either accept the possibility of > > >>> bugs > > >>> because the benefits are worth it or you don't use it. > > >>> > > >>> For me, autotest has been great. There have been some integration > > >>> problems w/ rspec but while they've been annoying they haven't > > >>> instilled fear in me that I'm getting the wrong feedback. So I > > >>> put up > > >>> with it. > > >>> > > >>> But we could certainly get some tests around the existing > > >>> integration > > >>> points: The test-to-file mappings, the command that gets generated, > > >>> etc. Patches welcome! > > >>> > > >>> Cheers, > > >>> David > > >>> > > >>>> > > >>>> Aslak > > >>>> > > >>>>> I'm not sure if anyone else has had this difficulty, or if I'm > > >>>>> being > > >>>>> clear. Let me know if I should clarify with some examples. > > >>>>> > > >>>>> Best, > > >>>>> > > >>>>> Scott > > >>>>> > > >>>>> _______________________________________________ > > >>>>> rspec-users mailing list > > >>>>> rspec-users at rubyforge.org > > >>>>> http://rubyforge.org/mailman/listinfo/rspec-users > > >>>>> > > >>>> _______________________________________________ > > >>>> rspec-users mailing list > > >>>> rspec-users at rubyforge.org > > >>>> http://rubyforge.org/mailman/listinfo/rspec-users > > >>>> > > >>> _______________________________________________ > > >>> rspec-users mailing list > > >>> rspec-users at rubyforge.org > > >>> http://rubyforge.org/mailman/listinfo/rspec-users > > >> > > >> _______________________________________________ > > >> rspec-users mailing list > > >> rspec-users at rubyforge.org > > >> http://rubyforge.org/mailman/listinfo/rspec-users > > >> > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From mailing_lists at railsnewbie.com Fri Jun 8 13:27:13 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 8 Jun 2007 13:27:13 -0400 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> <57c63afe0706080648ucda2d97u9abce1aa5f37870c@mail.gmail.com> <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> <57c63afe0706081015n76bba66ej3e6ca68c9740c8a5@mail.gmail.com> <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> Message-ID: <60EA0DF4-68DC-4853-8DFF-A2DA3BC1171E@railsnewbie.com> On Jun 8, 2007, at 1:23 PM, David Chelimsky wrote: > On 6/8/07, Scott Taylor wrote: >> >> On Jun 8, 2007, at 1:15 PM, David Chelimsky wrote: >> >>> On 6/8/07, Jonathan Linowes wrote: >>>> most plugins come with their own rails tests >>>> >>>> i've converted one by hand to rspec (restful_authentication) >>>> because >>>> - its functionality is integral to my app >>>> - its really a generator so the code ends up in my app >>>> - there's a good chance i'll be making custom changes to it as >>>> my app >>>> develops >>>> >>>> perhaps a tool that automatically converts rails tests to rspecs >>>> would be useful? >>> >>> We had one of those a while back. It was pretty good, but not >>> perfect. >>> It's very complex to get right and cover all the possibilities and >>> it's something that we will likely not build as part of rspec. That >>> said, if somebody else wanted to create such a thing, I'm sure you'd >>> make a lot of people happy. >> >> >> Wow. That code must still be around somewhere in subversion (any >> hints as to it's last release?) > > hint: svn log Sorry. I wasn't thinking. Scott From dchelimsky at gmail.com Fri Jun 8 13:29:33 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Jun 2007 12:29:33 -0500 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: <60EA0DF4-68DC-4853-8DFF-A2DA3BC1171E@railsnewbie.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> <57c63afe0706080648ucda2d97u9abce1aa5f37870c@mail.gmail.com> <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> <57c63afe0706081015n76bba66ej3e6ca68c9740c8a5@mail.gmail.com> <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> <60EA0DF4-68DC-4853-8DFF-A2DA3BC1171E@railsnewbie.com> Message-ID: <57c63afe0706081029kf9f7e57lf28afba517725bbc@mail.gmail.com> On 6/8/07, Scott Taylor wrote: > > On Jun 8, 2007, at 1:23 PM, David Chelimsky wrote: > > > On 6/8/07, Scott Taylor wrote: > >> > >> On Jun 8, 2007, at 1:15 PM, David Chelimsky wrote: > >> > >>> On 6/8/07, Jonathan Linowes wrote: > >>>> most plugins come with their own rails tests > >>>> > >>>> i've converted one by hand to rspec (restful_authentication) > >>>> because > >>>> - its functionality is integral to my app > >>>> - its really a generator so the code ends up in my app > >>>> - there's a good chance i'll be making custom changes to it as > >>>> my app > >>>> develops > >>>> > >>>> perhaps a tool that automatically converts rails tests to rspecs > >>>> would be useful? > >>> > >>> We had one of those a while back. It was pretty good, but not > >>> perfect. > >>> It's very complex to get right and cover all the possibilities and > >>> it's something that we will likely not build as part of rspec. That > >>> said, if somebody else wanted to create such a thing, I'm sure you'd > >>> make a lot of people happy. > >> > >> > >> Wow. That code must still be around somewhere in subversion (any > >> hints as to it's last release?) > > > > hint: svn log > > Sorry. I wasn't thinking. Please - no apology necessary. Just trying to teach a man to fish .... Cheers, David > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Fri Jun 8 13:38:28 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 8 Jun 2007 13:38:28 -0400 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: <57c63afe0706081029kf9f7e57lf28afba517725bbc@mail.gmail.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> <57c63afe0706080648ucda2d97u9abce1aa5f37870c@mail.gmail.com> <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> <57c63afe0706081015n76bba66ej3e6ca68c9740c8a5@mail.gmail.com> <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> <60EA0DF4-68DC-4853-8DFF-A2DA3BC1171E@railsnewbie.com> <57c63afe0706081029kf9f7e57lf28afba517725bbc@mail.gmail.com> Message-ID: Well, actually my problem wasn't thinking of svn log, but of how I would get revision/version numbers. I tried piping svn log to grep with 'test' as an argument. Clearly that didn't work. But even svn log | grep test2spec didn't give me revision numbers. How would you have done it, if you were me? Scott On Jun 8, 2007, at 1:29 PM, David Chelimsky wrote: > On 6/8/07, Scott Taylor wrote: >> >> On Jun 8, 2007, at 1:23 PM, David Chelimsky wrote: >> >>> On 6/8/07, Scott Taylor wrote: >>>> >>>> On Jun 8, 2007, at 1:15 PM, David Chelimsky wrote: >>>> >>>>> On 6/8/07, Jonathan Linowes wrote: >>>>>> most plugins come with their own rails tests >>>>>> >>>>>> i've converted one by hand to rspec (restful_authentication) >>>>>> because >>>>>> - its functionality is integral to my app >>>>>> - its really a generator so the code ends up in my app >>>>>> - there's a good chance i'll be making custom changes to it as >>>>>> my app >>>>>> develops >>>>>> >>>>>> perhaps a tool that automatically converts rails tests to rspecs >>>>>> would be useful? >>>>> >>>>> We had one of those a while back. It was pretty good, but not >>>>> perfect. >>>>> It's very complex to get right and cover all the possibilities and >>>>> it's something that we will likely not build as part of rspec. >>>>> That >>>>> said, if somebody else wanted to create such a thing, I'm sure >>>>> you'd >>>>> make a lot of people happy. >>>> >>>> >>>> Wow. That code must still be around somewhere in subversion (any >>>> hints as to it's last release?) >>> >>> hint: svn log >> >> Sorry. I wasn't thinking. > > Please - no apology necessary. Just trying to teach a man to fish .... > > Cheers, > David > >> >> Scott >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Jun 8 13:44:42 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Jun 2007 12:44:42 -0500 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> <57c63afe0706080648ucda2d97u9abce1aa5f37870c@mail.gmail.com> <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> <57c63afe0706081015n76bba66ej3e6ca68c9740c8a5@mail.gmail.com> <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> <60EA0DF4-68DC-4853-8DFF-A2DA3BC1171E@railsnewbie.com> <57c63afe0706081029kf9f7e57lf28afba517725bbc@mail.gmail.com> Message-ID: <57c63afe0706081044j1e993f51u3ca39ebed53c99a0@mail.gmail.com> On 6/8/07, Scott Taylor wrote: > > Well, actually my problem wasn't thinking of svn log, but of how I > would get revision/version numbers. I tried piping svn log to grep > with 'test' as an argument. Clearly that didn't work. But even svn > log | grep test2spec didn't give me revision numbers. > > How would you have done it, if you were me? svn log > log mate log now search for test2spec - the revision number will be close by The last one w/ test2spec in the comment is r621. In http://rspec.rubyforge.org/changes.html, the last time test2spec is mentioned is release 0.5.16. Note that that was back in the days.of.dots. > > Scott > > > On Jun 8, 2007, at 1:29 PM, David Chelimsky wrote: > > > On 6/8/07, Scott Taylor wrote: > >> > >> On Jun 8, 2007, at 1:23 PM, David Chelimsky wrote: > >> > >>> On 6/8/07, Scott Taylor wrote: > >>>> > >>>> On Jun 8, 2007, at 1:15 PM, David Chelimsky wrote: > >>>> > >>>>> On 6/8/07, Jonathan Linowes wrote: > >>>>>> most plugins come with their own rails tests > >>>>>> > >>>>>> i've converted one by hand to rspec (restful_authentication) > >>>>>> because > >>>>>> - its functionality is integral to my app > >>>>>> - its really a generator so the code ends up in my app > >>>>>> - there's a good chance i'll be making custom changes to it as > >>>>>> my app > >>>>>> develops > >>>>>> > >>>>>> perhaps a tool that automatically converts rails tests to rspecs > >>>>>> would be useful? > >>>>> > >>>>> We had one of those a while back. It was pretty good, but not > >>>>> perfect. > >>>>> It's very complex to get right and cover all the possibilities and > >>>>> it's something that we will likely not build as part of rspec. > >>>>> That > >>>>> said, if somebody else wanted to create such a thing, I'm sure > >>>>> you'd > >>>>> make a lot of people happy. > >>>> > >>>> > >>>> Wow. That code must still be around somewhere in subversion (any > >>>> hints as to it's last release?) > >>> > >>> hint: svn log > >> > >> Sorry. I wasn't thinking. > > > > Please - no apology necessary. Just trying to teach a man to fish .... > > > > Cheers, > > David > > > >> > >> Scott > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Fri Jun 8 14:44:55 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 8 Jun 2007 14:44:55 -0400 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: <57c63afe0706081044j1e993f51u3ca39ebed53c99a0@mail.gmail.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <8d961d900706080213t11bf5c18pcb9f315df04e75e8@mail.gmail.com> <57c63afe0706080648ucda2d97u9abce1aa5f37870c@mail.gmail.com> <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> <57c63afe0706081015n76bba66ej3e6ca68c9740c8a5@mail.gmail.com> <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> <60EA0DF4-68DC-4853-8DFF-A2DA3BC1171E@railsnewbie.com> <57c63afe0706081029kf9f7e57lf28afba517725bbc@mail.gmail.com> <57c63afe0706081044j1e993f51u3ca39ebed53c99a0@mail.gmail.com> Message-ID: <667FD090-8B35-4982-A6F4-C63F9F1CC3C3@railsnewbie.com> On Jun 8, 2007, at 1:44 PM, David Chelimsky wrote: > On 6/8/07, Scott Taylor wrote: >> >> Well, actually my problem wasn't thinking of svn log, but of how I >> would get revision/version numbers. I tried piping svn log to grep >> with 'test' as an argument. Clearly that didn't work. But even svn >> log | grep test2spec didn't give me revision numbers. >> >> How would you have done it, if you were me? > > svn log > log > mate log > > now search for test2spec - the revision number will be close by > My solution was something like the following: svn log | grep test2spec -n # for the line number svn log | mate # then searched for line number Although after hanging out in #bash, I found a much better solution: svn log | grep test2spec -B 3 | head the -B 3 prints three lines before each entry. Scott > The last one w/ test2spec in the comment is r621. > > In http://rspec.rubyforge.org/changes.html, the last time test2spec is > mentioned is release 0.5.16. Note that that was back in the > days.of.dots. > >> >> Scott >> >> >> On Jun 8, 2007, at 1:29 PM, David Chelimsky wrote: >> >>> On 6/8/07, Scott Taylor wrote: >>>> >>>> On Jun 8, 2007, at 1:23 PM, David Chelimsky wrote: >>>> >>>>> On 6/8/07, Scott Taylor wrote: >>>>>> >>>>>> On Jun 8, 2007, at 1:15 PM, David Chelimsky wrote: >>>>>> >>>>>>> On 6/8/07, Jonathan Linowes wrote: >>>>>>>> most plugins come with their own rails tests >>>>>>>> >>>>>>>> i've converted one by hand to rspec (restful_authentication) >>>>>>>> because >>>>>>>> - its functionality is integral to my app >>>>>>>> - its really a generator so the code ends up in my app >>>>>>>> - there's a good chance i'll be making custom changes to it as >>>>>>>> my app >>>>>>>> develops >>>>>>>> >>>>>>>> perhaps a tool that automatically converts rails tests to >>>>>>>> rspecs >>>>>>>> would be useful? >>>>>>> >>>>>>> We had one of those a while back. It was pretty good, but not >>>>>>> perfect. >>>>>>> It's very complex to get right and cover all the >>>>>>> possibilities and >>>>>>> it's something that we will likely not build as part of rspec. >>>>>>> That >>>>>>> said, if somebody else wanted to create such a thing, I'm sure >>>>>>> you'd >>>>>>> make a lot of people happy. >>>>>> >>>>>> >>>>>> Wow. That code must still be around somewhere in subversion (any >>>>>> hints as to it's last release?) >>>>> >>>>> hint: svn log >>>> >>>> Sorry. I wasn't thinking. >>> >>> Please - no apology necessary. Just trying to teach a man to >>> fish .... >>> >>> Cheers, >>> David >>> >>>> >>>> Scott >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Jun 8 14:46:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Jun 2007 13:46:40 -0500 Subject: [rspec-users] When to use BDD/TDD w/ external libraries In-Reply-To: <667FD090-8B35-4982-A6F4-C63F9F1CC3C3@railsnewbie.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> <57c63afe0706081015n76bba66ej3e6ca68c9740c8a5@mail.gmail.com> <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> <60EA0DF4-68DC-4853-8DFF-A2DA3BC1171E@railsnewbie.com> <57c63afe0706081029kf9f7e57lf28afba517725bbc@mail.gmail.com> <57c63afe0706081044j1e993f51u3ca39ebed53c99a0@mail.gmail.com> <667FD090-8B35-4982-A6F4-C63F9F1CC3C3@railsnewbie.com> Message-ID: <57c63afe0706081146i5c58484ao359cf003f4ce5ebe@mail.gmail.com> On 6/8/07, Scott Taylor wrote: > > On Jun 8, 2007, at 1:44 PM, David Chelimsky wrote: > > > On 6/8/07, Scott Taylor wrote: > >> > >> Well, actually my problem wasn't thinking of svn log, but of how I > >> would get revision/version numbers. I tried piping svn log to grep > >> with 'test' as an argument. Clearly that didn't work. But even svn > >> log | grep test2spec didn't give me revision numbers. > >> > >> How would you have done it, if you were me? > > > > svn log > log > > mate log > > > > now search for test2spec - the revision number will be close by > > > > My solution was something like the following: > > svn log | grep test2spec -n # for the line number > svn log | mate # then searched for line number > > Although after hanging out in #bash, I found a much better solution: > > svn log | grep test2spec -B 3 | head > > the -B 3 prints three lines before each entry. :) Cool. > > > Scott > > > > > The last one w/ test2spec in the comment is r621. > > > > In http://rspec.rubyforge.org/changes.html, the last time test2spec is > > mentioned is release 0.5.16. Note that that was back in the > > days.of.dots. > > > >> > >> Scott > >> > >> > >> On Jun 8, 2007, at 1:29 PM, David Chelimsky wrote: > >> > >>> On 6/8/07, Scott Taylor wrote: > >>>> > >>>> On Jun 8, 2007, at 1:23 PM, David Chelimsky wrote: > >>>> > >>>>> On 6/8/07, Scott Taylor wrote: > >>>>>> > >>>>>> On Jun 8, 2007, at 1:15 PM, David Chelimsky wrote: > >>>>>> > >>>>>>> On 6/8/07, Jonathan Linowes wrote: > >>>>>>>> most plugins come with their own rails tests > >>>>>>>> > >>>>>>>> i've converted one by hand to rspec (restful_authentication) > >>>>>>>> because > >>>>>>>> - its functionality is integral to my app > >>>>>>>> - its really a generator so the code ends up in my app > >>>>>>>> - there's a good chance i'll be making custom changes to it as > >>>>>>>> my app > >>>>>>>> develops > >>>>>>>> > >>>>>>>> perhaps a tool that automatically converts rails tests to > >>>>>>>> rspecs > >>>>>>>> would be useful? > >>>>>>> > >>>>>>> We had one of those a while back. It was pretty good, but not > >>>>>>> perfect. > >>>>>>> It's very complex to get right and cover all the > >>>>>>> possibilities and > >>>>>>> it's something that we will likely not build as part of rspec. > >>>>>>> That > >>>>>>> said, if somebody else wanted to create such a thing, I'm sure > >>>>>>> you'd > >>>>>>> make a lot of people happy. > >>>>>> > >>>>>> > >>>>>> Wow. That code must still be around somewhere in subversion (any > >>>>>> hints as to it's last release?) > >>>>> > >>>>> hint: svn log > >>>> > >>>> Sorry. I wasn't thinking. > >>> > >>> Please - no apology necessary. Just trying to teach a man to > >>> fish .... > >>> > >>> Cheers, > >>> David > >>> > >>>> > >>>> Scott > >>>> > >>>> _______________________________________________ > >>>> rspec-users mailing list > >>>> rspec-users at rubyforge.org > >>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Fri Jun 8 14:55:40 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 8 Jun 2007 14:55:40 -0400 Subject: [rspec-users] [OT] SVN Utils from: When to use BDD/TDD w/ external libraries In-Reply-To: <57c63afe0706081146i5c58484ao359cf003f4ce5ebe@mail.gmail.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <84F9A79F-2361-4F98-AA22-256E3519C6F6@parkerhill.com> <57c63afe0706081015n76bba66ej3e6ca68c9740c8a5@mail.gmail.com> <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> <60EA0DF4-68DC-4853-8DFF-A2DA3BC1171E@railsnewbie.com> <57c63afe0706081029kf9f7e57lf28afba517725bbc@mail.gmail.com> <57c63afe0706081044j1e993f51u3ca39ebed53c99a0@mail.gmail.com> <667FD090-8B35-4982-A6F4-C63F9F1CC3C3@railsnewbie.com> <57c63afe0706081146i5c58484ao359cf003f4ce5ebe@mail.gmail.com> Message-ID: <285EEE7F-7429-466D-B348-00A3D9B1E35A@railsnewbie.com> I've been noticing recently that svn doesn't always meet up to expectations. For instance, in copying directories: svn mv dir1/ dir2 will move dir1 into dir2, not the contents of dir1 into dir2. dir1/* doesn't work either. The exchange with David also shows that finding when a piece of software was removed from a project's log is not a trivial task to do without a text editor present. I wonder if it would be worth while developing some shell scripts to supplement SVN? Scott On Jun 8, 2007, at 2:46 PM, David Chelimsky wrote: > On 6/8/07, Scott Taylor wrote: >> >> On Jun 8, 2007, at 1:44 PM, David Chelimsky wrote: >> >>> On 6/8/07, Scott Taylor wrote: >>>> >>>> Well, actually my problem wasn't thinking of svn log, but of how I >>>> would get revision/version numbers. I tried piping svn log to grep >>>> with 'test' as an argument. Clearly that didn't work. But even >>>> svn >>>> log | grep test2spec didn't give me revision numbers. >>>> >>>> How would you have done it, if you were me? >>> >>> svn log > log >>> mate log >>> >>> now search for test2spec - the revision number will be close by >>> >> >> My solution was something like the following: >> >> svn log | grep test2spec -n # for the line number >> svn log | mate # then searched for line number >> >> Although after hanging out in #bash, I found a much better solution: >> >> svn log | grep test2spec -B 3 | head >> >> the -B 3 prints three lines before each entry. > > :) > > Cool. > >> >> >> Scott >> >> >> >>> The last one w/ test2spec in the comment is r621. >>> >>> In http://rspec.rubyforge.org/changes.html, the last time >>> test2spec is >>> mentioned is release 0.5.16. Note that that was back in the >>> days.of.dots. >>> >>>> >>>> Scott >>>> >>>> >>>> On Jun 8, 2007, at 1:29 PM, David Chelimsky wrote: >>>> >>>>> On 6/8/07, Scott Taylor wrote: >>>>>> >>>>>> On Jun 8, 2007, at 1:23 PM, David Chelimsky wrote: >>>>>> >>>>>>> On 6/8/07, Scott Taylor wrote: >>>>>>>> >>>>>>>> On Jun 8, 2007, at 1:15 PM, David Chelimsky wrote: >>>>>>>> >>>>>>>>> On 6/8/07, Jonathan Linowes wrote: >>>>>>>>>> most plugins come with their own rails tests >>>>>>>>>> >>>>>>>>>> i've converted one by hand to rspec (restful_authentication) >>>>>>>>>> because >>>>>>>>>> - its functionality is integral to my app >>>>>>>>>> - its really a generator so the code ends up in my app >>>>>>>>>> - there's a good chance i'll be making custom changes to >>>>>>>>>> it as >>>>>>>>>> my app >>>>>>>>>> develops >>>>>>>>>> >>>>>>>>>> perhaps a tool that automatically converts rails tests to >>>>>>>>>> rspecs >>>>>>>>>> would be useful? >>>>>>>>> >>>>>>>>> We had one of those a while back. It was pretty good, but not >>>>>>>>> perfect. >>>>>>>>> It's very complex to get right and cover all the >>>>>>>>> possibilities and >>>>>>>>> it's something that we will likely not build as part of rspec. >>>>>>>>> That >>>>>>>>> said, if somebody else wanted to create such a thing, I'm sure >>>>>>>>> you'd >>>>>>>>> make a lot of people happy. >>>>>>>> >>>>>>>> >>>>>>>> Wow. That code must still be around somewhere in subversion >>>>>>>> (any >>>>>>>> hints as to it's last release?) >>>>>>> >>>>>>> hint: svn log >>>>>> >>>>>> Sorry. I wasn't thinking. >>>>> >>>>> Please - no apology necessary. Just trying to teach a man to >>>>> fish .... >>>>> >>>>> Cheers, >>>>> David >>>>> >>>>>> >>>>>> Scott >>>>>> >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mattaimonetti at gmail.com Fri Jun 8 20:48:24 2007 From: mattaimonetti at gmail.com (Matt Aimonetti) Date: Fri, 8 Jun 2007 17:48:24 -0700 Subject: [rspec-users] sharing my netvibes tab about rspec In-Reply-To: References: Message-ID: Thanks Jean-Michel and good luck with your book about RSpec and BDD in general. Matt On 6/6/07, Jean-Michel Garnier wrote: > > Link was 404 :-( > > the correct link is > http://21croissants.blogspot.com/2007/06/rspec-changes-log-rss.html > > I should definitely switch from blogger to mephisto ... > > Hi, > > As I am not a big fan of mailing list, I have created a Yahoo!Pipes to > generate a RSS from the user & developpers mailing list and integrated it > into a netvibes tab. I have also put a few blogs from the rspec authors. > > More information and screenshots (worth 1000 words!) in > http://21croissants.blogspot.com/2007/06/rspec-changes-log-rss.html > > Cheers, > > Jean-Michel > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070608/f4f855cf/attachment.html From dchelimsky at gmail.com Fri Jun 8 23:07:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 8 Jun 2007 22:07:01 -0500 Subject: [rspec-users] sharing my netvibes tab about rspec In-Reply-To: References: Message-ID: <57c63afe0706082007w68a38243w23d55295fcac431d@mail.gmail.com> On 6/8/07, Matt Aimonetti wrote: > Thanks Jean-Michel and good luck with your book about RSpec and BDD in general. Book? From joevandyk at gmail.com Sat Jun 9 03:42:17 2007 From: joevandyk at gmail.com (Joe Van Dyk) Date: Sat, 9 Jun 2007 00:42:17 -0700 Subject: [rspec-users] mystery problem with svn post-commit script running rspec tests Message-ID: So, just spent seven straight hours on this. I have a post-commit svn script that runs all my tests. Emails me if something goes wrong. One of the lines looks like: @output = `rake test RAILS_ENV=test` The output from the rspec tests don't seem to appear in @output. Why would that be? Oddly enough, that only seems to happen when the script is ran from svn's post-commit hook. When I run the script manually, the rspec test results show up in @output. Joe From joevandyk at gmail.com Sat Jun 9 03:56:17 2007 From: joevandyk at gmail.com (Joe Van Dyk) Date: Sat, 9 Jun 2007 00:56:17 -0700 Subject: [rspec-users] mystery problem with svn post-commit script running rspec tests In-Reply-To: References: Message-ID: Oh, this is a Rails project, by the way. Do the specs mess around with stdout or stderr? Joe On 6/9/07, Joe Van Dyk wrote: > So, just spent seven straight hours on this. > > I have a post-commit svn script that runs all my tests. Emails me if > something goes wrong. > > One of the lines looks like: > @output = `rake test RAILS_ENV=test` > > The output from the rspec tests don't seem to appear in @output. Why > would that be? Oddly enough, that only seems to happen when the > script is ran from svn's post-commit hook. When I run the script > manually, the rspec test results show up in @output. > > Joe > From rick.tessner at gmail.com Sat Jun 9 16:05:29 2007 From: rick.tessner at gmail.com (Rick Tessner) Date: Sat, 09 Jun 2007 13:05:29 -0700 Subject: [rspec-users] authentication, controller specs. I think I'm missing something simple .... Message-ID: <1181419529.16605.136.camel@localhost> Hi all, I feel like I'm missing something really easy and I'm just not seeing it. I'm using the restful_authentication plugin and have a User model. Uesr has_many :things and Thing belongs_to :user. That's it. I did a "script/generate rspec_scaffold thing" to generate all the necessary bits. The "rake db:migrate" to create the db. At this point, a "rake spec" works just fine. All specs pass. I add in the "include AuthenticatedSystem" in the ThingsController and add a line to the "before" section in each of the describe stanzas that reads: controller.should_receive(:login_required).with(no_args).once.and_return(true) All tests pass just fine at this point as well. It's this next part where I get really confused about how the spec should be written. What I change in the controller itself (and at this point, all methods are the default generated by the scaffold) is to add scoping of the current user to the finds: For example, the "index" method becomes (to find all things for the current user) @things = current_user.things.find(:all) rather than @things = Thing.find(:all) I run "rake spec" and of course it fails. So, I try to mock/stub the current_user and add a stub for the things method on it and it's at this point that I feel like I'm missing something fundamental since I get many many failures of various types. LocalJumpError in 'ThingsController handling GET /things should render index template' no block given is the major error. If I remove the "find(:all)" a number of these LocalJumpErrors disappear. I am interested in how to resolve the LocalJumpError issue tho since I'm sure it will be a use-case that crops up in my application. The basic issue I'm struggling with is how does define mocks/stubs for a controller method that does something of the form: method_a.method_b.find Pasted code/spec/errors here * things_controller http://pastie.caboo.se/69136 * things_controller_spec http://pastie.caboo.se/69137 * Errors w/ find(:all) http://pastie.caboo.se/69138 -- Rick rick.tessner at gmail.com From joevandyk at gmail.com Sat Jun 9 17:34:47 2007 From: joevandyk at gmail.com (Joe Van Dyk) Date: Sat, 9 Jun 2007 14:34:47 -0700 Subject: [rspec-users] authentication, controller specs. I think I'm missing something simple .... In-Reply-To: <1181419529.16605.136.camel@localhost> References: <1181419529.16605.136.camel@localhost> Message-ID: Your pasties have wrapped lines in them for some reason, which makes matching up the errors to the lines of code difficult. On 6/9/07, Rick Tessner wrote: > Hi all, > > I feel like I'm missing something really easy and I'm just not seeing > it. > > I'm using the restful_authentication plugin and have a User model. Uesr > has_many :things and Thing belongs_to :user. > > That's it. > > I did a "script/generate rspec_scaffold thing" to generate all the > necessary bits. The "rake db:migrate" to create the db. > > At this point, a "rake spec" works just fine. All specs pass. > > I add in the "include AuthenticatedSystem" in the ThingsController and > add a line to the "before" section in each of the describe stanzas that > reads: > > controller.should_receive(:login_required).with(no_args).once.and_return(true) > > All tests pass just fine at this point as well. > > It's this next part where I get really confused about how the spec > should be written. > > What I change in the controller itself (and at this point, all methods > are the default generated by the scaffold) is to add scoping of the > current user to the finds: > > For example, the "index" method becomes (to find all things for the > current user) > > @things = current_user.things.find(:all) > > rather than > > @things = Thing.find(:all) > > I run "rake spec" and of course it fails. So, I try to mock/stub the > current_user and add a stub for the things method on it and it's at this > point that I feel like I'm missing something fundamental since I get > many many failures of various types. > > LocalJumpError in 'ThingsController handling GET /things should > render index template' > no block given > > is the major error. If I remove the "find(:all)" a number of these > LocalJumpErrors disappear. I am interested in how to resolve the > LocalJumpError issue tho since I'm sure it will be a use-case that crops > up in my application. > > The basic issue I'm struggling with is how does define mocks/stubs for a > controller method that does something of the form: > > method_a.method_b.find > > Pasted code/spec/errors here > > * things_controller http://pastie.caboo.se/69136 > * things_controller_spec http://pastie.caboo.se/69137 > * Errors w/ find(:all) http://pastie.caboo.se/69138 > > -- > Rick > rick.tessner at gmail.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From joevandyk at gmail.com Sat Jun 9 18:00:43 2007 From: joevandyk at gmail.com (Joe Van Dyk) Date: Sat, 9 Jun 2007 15:00:43 -0700 Subject: [rspec-users] [OT] SVN Utils from: When to use BDD/TDD w/ external libraries In-Reply-To: <285EEE7F-7429-466D-B348-00A3D9B1E35A@railsnewbie.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> <60EA0DF4-68DC-4853-8DFF-A2DA3BC1171E@railsnewbie.com> <57c63afe0706081029kf9f7e57lf28afba517725bbc@mail.gmail.com> <57c63afe0706081044j1e993f51u3ca39ebed53c99a0@mail.gmail.com> <667FD090-8B35-4982-A6F4-C63F9F1CC3C3@railsnewbie.com> <57c63afe0706081146i5c58484ao359cf003f4ce5ebe@mail.gmail.com> <285EEE7F-7429-466D-B348-00A3D9B1E35A@railsnewbie.com> Message-ID: On 6/8/07, Scott Taylor wrote: > > I've been noticing recently that svn doesn't always meet up to > expectations. For instance, in copying directories: > > svn mv dir1/ dir2 > > will move dir1 into dir2, not the contents of dir1 into dir2. dir1/* > doesn't work either. $ svn mv dir1/* dir2 that doesn't move all dir1's content to dir2? Joe From rick.tessner at gmail.com Sat Jun 9 18:58:24 2007 From: rick.tessner at gmail.com (Rick Tessner) Date: Sat, 09 Jun 2007 15:58:24 -0700 Subject: [rspec-users] authentication, controller specs. I think I'm missing something simple .... In-Reply-To: References: <1181419529.16605.136.camel@localhost> Message-ID: <1181429904.16605.149.camel@localhost> On Sat, 2007-09-06 at 14:34 -0700, Joe Van Dyk wrote: > Your pasties have wrapped lines in them for some reason, which makes > matching up the errors to the lines of code difficult. Dang. Sorry about that. Looks like it was the things_controller_spec was messed up for some reason. Re-pastied that. The three pasties are then: * things_controller http://pastie.caboo.se/69136 * things_controller_spec http://pastie.caboo.se/69166 * Errors w/ find(:all) http://pastie.caboo.se/69138 -- Rick rick.tessner at gmail.com From mailing_lists at railsnewbie.com Sat Jun 9 20:40:26 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 9 Jun 2007 20:40:26 -0400 Subject: [rspec-users] [OT] SVN Utils from: When to use BDD/TDD w/ external libraries In-Reply-To: References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> <60EA0DF4-68DC-4853-8DFF-A2DA3BC1171E@railsnewbie.com> <57c63afe0706081029kf9f7e57lf28afba517725bbc@mail.gmail.com> <57c63afe0706081044j1e993f51u3ca39ebed53c99a0@mail.gmail.com> <667FD090-8B35-4982-A6F4-C63F9F1CC3C3@railsnewbie.com> <57c63afe0706081146i5c58484ao359cf003f4ce5ebe@mail.gmail.com> <285EEE7F-7429-466D-B348-00A3D9B1E35A@railsnewbie.com> Message-ID: <0E2F5D22-F17E-499C-8B8A-EE6AFE0F6992@railsnewbie.com> On Jun 9, 2007, at 6:00 PM, Joe Van Dyk wrote: > On 6/8/07, Scott Taylor wrote: >> >> I've been noticing recently that svn doesn't always meet up to >> expectations. For instance, in copying directories: >> >> svn mv dir1/ dir2 >> >> will move dir1 into dir2, not the contents of dir1 into dir2. dir1/* >> doesn't work either. > > $ svn mv dir1/* dir2 > > that doesn't move all dir1's content to dir2? If my memory recalls correctly, no, because the svn command can only handle one file at a time (so the shell substitution for '*' will feed in all of the files, and svn will complain). euclid% svn cp test/* something/ svn: Client error in parsing arguments Also see this: http://blog.caboo.se/articles/2005/12/16/svn-mv-dir Scott From ricktessner at canada.com Sat Jun 9 18:43:47 2007 From: ricktessner at canada.com (Rick Tessner) Date: Sat, 09 Jun 2007 15:43:47 -0700 Subject: [rspec-users] authentication, controller specs. I think I'm missing something simple .... In-Reply-To: References: <1181419529.16605.136.camel@localhost> Message-ID: <1181429027.16605.147.camel@localhost> On Sat, 2007-09-06 at 14:34 -0700, Joe Van Dyk wrote: > Your pasties have wrapped lines in them for some reason, which makes > matching up the errors to the lines of code difficult. Dang. Sorry about that. Looks like it was the things_controller_spec was messed up for some reason. Re-pastied that. The three pasties are then: things_controller http://pastie.caboo.se/69136 things_controller_spec http://pastie.caboo.se/69166 Errors w/ find(:all) http://pastie.caboo.se/69138 -- Rick Tessner From nick at ekenosen.net Sun Jun 10 10:46:43 2007 From: nick at ekenosen.net (nicholas a. evans) Date: Sun, 10 Jun 2007 10:46:43 -0400 Subject: [rspec-users] [OT] SVN Utils from: When to use BDD/TDD w/ external libraries In-Reply-To: <285EEE7F-7429-466D-B348-00A3D9B1E35A@railsnewbie.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> <60EA0DF4-68DC-4853-8DFF-A2DA3BC1171E@railsnewbie.com> <57c63afe0706081029kf9f7e57lf28afba517725bbc@mail.gmail.com> <57c63afe0706081044j1e993f51u3ca39ebed53c99a0@mail.gmail.com> <667FD090-8B35-4982-A6F4-C63F9F1CC3C3@railsnewbie.com> <57c63afe0706081146i5c58484ao359cf003f4ce5ebe@mail.gmail.com> <285EEE7F-7429-466D-B348-00A3D9B1E35A@railsnewbie.com> Message-ID: <276ff9870706100746l13e652a4x33282fa9d5a732d0@mail.gmail.com> On 6/8/07, Scott Taylor wrote: > I wonder if it would be worth while developing some shell scripts to > supplement SVN? For what it's worth, I'll show you my svn aliases... but some of them are highly specific to my workflow, so I don't really think they're worth sharing around much: http://pastie.caboo.se/69244 I never bothered to make a bash function to handle subversion move of multiple files, but it wouldn't be hard to do. I just use the for loop approach: "for i in src/*; do svn mv $i dest/; done". I only made aliases for the commands that I use often. Of course, the various GUI clients make this sort of task much simpler, too. ;-) -- Nick From dchelimsky at gmail.com Sun Jun 10 10:51:36 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 10 Jun 2007 09:51:36 -0500 Subject: [rspec-users] [OT] SVN Utils from: When to use BDD/TDD w/ external libraries In-Reply-To: <276ff9870706100746l13e652a4x33282fa9d5a732d0@mail.gmail.com> References: <8827D84E-5ADB-4C9C-ACB6-9150EE01EEFB@railsnewbie.com> <57c63afe0706081023g6c6b9a39jcfc1218fdace2c0a@mail.gmail.com> <60EA0DF4-68DC-4853-8DFF-A2DA3BC1171E@railsnewbie.com> <57c63afe0706081029kf9f7e57lf28afba517725bbc@mail.gmail.com> <57c63afe0706081044j1e993f51u3ca39ebed53c99a0@mail.gmail.com> <667FD090-8B35-4982-A6F4-C63F9F1CC3C3@railsnewbie.com> <57c63afe0706081146i5c58484ao359cf003f4ce5ebe@mail.gmail.com> <285EEE7F-7429-466D-B348-00A3D9B1E35A@railsnewbie.com> <276ff9870706100746l13e652a4x33282fa9d5a732d0@mail.gmail.com> Message-ID: <57c63afe0706100751y5de85607u9f0c6aa5cc498868@mail.gmail.com> On 6/10/07, nicholas a. evans wrote: > On 6/8/07, Scott Taylor wrote: > > I wonder if it would be worth while developing some shell scripts to > > supplement SVN? > > For what it's worth, I'll show you my svn aliases... but some of them > are highly specific to my workflow, so I don't really think they're > worth sharing around much: > > http://pastie.caboo.se/69244 Cool. Here's another one I use all the time to see what files I've created that I haven't added to svn. snew() { svn st | awk '/^\?/ {print $2}' } It prints a list of only the filenames, which you can then pipe to svn add w/ xargs: snew | xargs svn add > > I never bothered to make a bash function to handle subversion move of > multiple files, but it wouldn't be hard to do. I just use the for > loop approach: "for i in src/*; do svn mv $i dest/; done". I only > made aliases for the commands that I use often. > > Of course, the various GUI clients make this sort of task much > simpler, too. ;-) > > -- > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From joevandyk at gmail.com Sun Jun 10 15:18:05 2007 From: joevandyk at gmail.com (Joe Van Dyk) Date: Sun, 10 Jun 2007 12:18:05 -0700 Subject: [rspec-users] authentication, controller specs. I think I'm missing something simple .... In-Reply-To: <1181429027.16605.147.camel@localhost> References: <1181419529.16605.136.camel@localhost> <1181429027.16605.147.camel@localhost> Message-ID: On 6/9/07, Rick Tessner wrote: > On Sat, 2007-09-06 at 14:34 -0700, Joe Van Dyk wrote: > > Your pasties have wrapped lines in them for some reason, which makes > > matching up the errors to the lines of code difficult. > > Dang. Sorry about that. Looks like it was the things_controller_spec > was messed up for some reason. Re-pastied that. > > The three pasties are then: > > things_controller http://pastie.caboo.se/69136 > things_controller_spec http://pastie.caboo.se/69166 > Errors w/ find(:all) http://pastie.caboo.se/69138 I don't have the solution and I've ran into this in the past. But at least I can explain what is happening. :-) @thing = mock_model(Thing) Thing.stub!(:find).and_return([@thing]) @current_user = mock_model(User, :things => [@thing]) controller.should_receive(:login_required).with(no_args).once.and_return(true) controller.should_receive(:current_user).with(no_args).and_return(@current_user) So, when you do: current_user.things.find You are calling the find method on an array that contains one @thing object. The find you are calling is Enumerable#find (the plain old Ruby version, not the ActiveRecord::Base::find version). Enumerable#find expects a block. i.e. ["hello, "world"].find { |e| e.include?('el') } would return "hello" However, in the Rails code, when you call current_user.things.find, You are calling Thing::find with a scoped find for only the Things that belong to the current user. That's an entirely different find method. Hope that makes sense. I don't know what the solution is. Joe Van Dyk From cwdinfo at gmail.com Sun Jun 10 18:08:27 2007 From: cwdinfo at gmail.com (s.ross) Date: Sun, 10 Jun 2007 15:08:27 -0700 Subject: [rspec-users] authentication, controller specs. I think I'm missing something simple .... In-Reply-To: References: <1181419529.16605.136.camel@localhost> <1181429027.16605.147.camel@localhost> Message-ID: Try pulling do_get outside the block and see if that helps... Just a thought. On Jun 10, 2007, at 12:18 PM, Joe Van Dyk wrote: > On 6/9/07, Rick Tessner wrote: >> On Sat, 2007-09-06 at 14:34 -0700, Joe Van Dyk wrote: >>> Your pasties have wrapped lines in them for some reason, which makes >>> matching up the errors to the lines of code difficult. >> >> Dang. Sorry about that. Looks like it was the >> things_controller_spec >> was messed up for some reason. Re-pastied that. >> >> The three pasties are then: >> >> things_controller http://pastie.caboo.se/69136 >> things_controller_spec http://pastie.caboo.se/69166 >> Errors w/ find(:all) http://pastie.caboo.se/69138 > > I don't have the solution and I've ran into this in the past. But at > least I can explain what is happening. :-) > > @thing = mock_model(Thing) > Thing.stub!(:find).and_return([@thing]) > > @current_user = mock_model(User, :things => [@thing]) > controller.should_receive(:login_required).with > (no_args).once.and_return(true) > controller.should_receive(:current_user).with > (no_args).and_return(@current_user) > > So, when you do: > current_user.things.find > > You are calling the find method on an array that contains one @thing > object. The find you are calling is Enumerable#find (the plain old > Ruby version, not the ActiveRecord::Base::find version). > Enumerable#find expects a block. > > i.e. > ["hello, "world"].find { |e| e.include?('el') } > would return "hello" > > However, in the Rails code, when you call current_user.things.find, > You are calling Thing::find with a scoped find for only the Things > that belong to the current user. That's an entirely different find > method. > > Hope that makes sense. I don't know what the solution is. > > Joe Van Dyk > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Steve Ross sross at calicowebdev.com http://www.calicowebdev.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070610/e27cbc70/attachment-0001.html From rick.tessner at gmail.com Sun Jun 10 20:16:00 2007 From: rick.tessner at gmail.com (Rick Tessner) Date: Mon, 11 Jun 2007 00:16:00 +0000 Subject: [rspec-users] authentication, controller specs. I think I'm missing something simple .... In-Reply-To: References: <1181419529.16605.136.camel@localhost> <1181429027.16605.147.camel@localhost> Message-ID: <1181520960.16605.155.camel@localhost> On Sun, 2007-10-06 at 15:08 -0700, s.ross wrote: > Try pulling do_get outside the block and see if that helps... Nope, no difference there. Joe's explanation of Enumerable#find vs. the find method that rails uses makes sense and certainly explains the error. Not sure yet how to work around this one ... -- Rick rick.tessner at gmail.com From smingins at elctech.com Mon Jun 11 04:16:16 2007 From: smingins at elctech.com (Shane Mingins) Date: Mon, 11 Jun 2007 20:16:16 +1200 Subject: [rspec-users] Testing create in Rails controller Message-ID: <7A1F4C10-99F5-44CE-860A-93DC0672D5EB@elctech.com> Hi All So I am a first-time caller ;-) ... and have been trying to apply RSpec to the depot example in Dave Thomas' book as I build the application. I am having a problem testing the admin controller create method and cannot quite see where I am going wrong so was hoping for a pointer :-) My spec looks like: describe AdminController do before(:each) do @product = mock("product") # Generally, prefer stub! over should_receive in setup. @product.stub!(:new_record?).and_return(false) Product.stub!(:new).and_return(@product) end it "should create a new, unsaved product on GET to new" do # Using should_receive here overrides the stub in setup. Even # though it is the same as the stub, using should_receive sets # an expectation that will be verified. It also helps to # better express the intent of this example. Product.should_receive(:new).and_return(@product) get :new end it "should assign new product to template on GET to new" do get :new assigns[:product].should equal(@product) end it "should render 'product/new' on GET to new" do get :new response.should render_template(:new) end it "should tell the Product model to save a new product on POST to create" do attributes = {"title" => 'Apple Wireless Keyboard', "description" => 'Really cool wireless keyboard', "image_url" => 'a.gif', "price" => 1.00} Product.should_receive(:new).with(attributes) Product.should_receive(:save).with(:no_arg) post :create, :product => attributes end end Which I copied and modified from the example. The code in the controller looks like: def create @product = Product.new(params[:product]) if @product.save flash[:notice] = 'Product was successfully created.' redirect_to :action => 'list' else render :action => 'new' end end I am guessing that I haven't quite got the mock/stub setup correctly?? The error I get is: 1) NoMethodError in 'AdminController should tell the Product model to save a new product on POST to create' You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.save /Users/smingins/Work/depot/config/../app/controllers/ admin_controller.rb:25:in `create' ./spec/controllers/admin_controller_spec.rb:41: Finished in 0.226535 seconds I have been playing around with things but without any luck. The nil error does strike me as rather odd but the test reads as I would have thought it should ... but obviously I am missing something. Cheer Shane From dchelimsky at gmail.com Mon Jun 11 07:25:17 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 11 Jun 2007 06:25:17 -0500 Subject: [rspec-users] Testing create in Rails controller In-Reply-To: <7A1F4C10-99F5-44CE-860A-93DC0672D5EB@elctech.com> References: <7A1F4C10-99F5-44CE-860A-93DC0672D5EB@elctech.com> Message-ID: <57c63afe0706110425p310d1103r9f5e551e2314c5d4@mail.gmail.com> On 6/11/07, Shane Mingins wrote: > Hi All > > So I am a first-time caller ;-) ... and have been trying to apply > RSpec to the depot example in Dave Thomas' book as I build the > application. > > I am having a problem testing the admin controller create method and > cannot quite see where I am going wrong so was hoping for a pointer :-) > > My spec looks like: > > describe AdminController do > > before(:each) do > @product = mock("product") > # Generally, prefer stub! over should_receive in setup. > @product.stub!(:new_record?).and_return(false) > Product.stub!(:new).and_return(@product) > end > > it "should create a new, unsaved product on GET to new" do > # Using should_receive here overrides the stub in setup. Even > # though it is the same as the stub, using should_receive sets > # an expectation that will be verified. It also helps to > # better express the intent of this example. > Product.should_receive(:new).and_return(@product) > get :new > end > > it "should assign new product to template on GET to new" do > get :new > assigns[:product].should equal(@product) > end > > it "should render 'product/new' on GET to new" do > get :new > response.should render_template(:new) > end > > it "should tell the Product model to save a new product on POST to > create" do > attributes = {"title" => 'Apple Wireless Keyboard', > "description" => 'Really cool wireless keyboard', > "image_url" => 'a.gif', > "price" => 1.00} > > Product.should_receive(:new).with(attributes) > Product.should_receive(:save).with(:no_arg) > > post :create, :product => attributes > end > > end > > > Which I copied and modified from the example. > > The code in the controller looks like: > > def create > @product = Product.new(params[:product]) > if @product.save > flash[:notice] = 'Product was successfully created.' > redirect_to :action => 'list' > else > render :action => 'new' > end > end Two problems. 1. The return value from Product.new(params[:product]) gets assigned to @product. You need to tell the :new method to return something when setting up the Message Expectation. 2. :save is getting called on @product, not the Product class. To solve both of these, create a mock instance of product and tell Product to return that for :new So replace this: Product.should_receive(:new).with(attributes) Product.should_receive(:save).with(:no_arg) with this: product = mock("product") product.should_receive(:save).with(no_args).and_return(true) Product.should_receive(:new).with(attributes).and_return(product) Note that I used no_args instead of :no_args. The Symbol is deprecated and replaced by a method. Also, since you're telling product to return true for :save, you're describing only one branch of create. To describe the other branch you can have a separate example in which it returns false and then say: response.should render_template('new') Enjoy, David > > > I am guessing that I haven't quite got the mock/stub setup correctly?? > > The error I get is: > > 1) > NoMethodError in 'AdminController should tell the Product model to > save a new product on POST to create' > You have a nil object when you didn't expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.save > /Users/smingins/Work/depot/config/../app/controllers/ > admin_controller.rb:25:in `create' > ./spec/controllers/admin_controller_spec.rb:41: > > Finished in 0.226535 seconds > > > I have been playing around with things but without any luck. The nil > error does strike me as rather odd but the test reads as I would have > thought it should ... but obviously I am missing something. > > Cheer > Shane > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Mon Jun 11 12:32:00 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 11 Jun 2007 12:32:00 -0400 Subject: [rspec-users] hpricot as dependency for building rspec? Message-ID: <978FCF19-D9A7-47BC-AA11-66470DEC4B0F@railsnewbie.com> It looks to me that hpricot is a dependency to building rspec: euclid% rake pre_commit (in /Users/smtlaissezfaire/ruby/projects/rspec/hpricot) rake aborted! Could not find RubyGem hpricot (>= 0.0.0) /Users/smtlaissezfaire/ruby/projects/rspec/hpricot/rakefile:9 (See full trace by running task with --trace) Let me know if I'm wrong. Otherwise, I'll submit a patch in the docs. Scott From dchelimsky at gmail.com Mon Jun 11 12:32:59 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 11 Jun 2007 11:32:59 -0500 Subject: [rspec-users] hpricot as dependency for building rspec? In-Reply-To: <978FCF19-D9A7-47BC-AA11-66470DEC4B0F@railsnewbie.com> References: <978FCF19-D9A7-47BC-AA11-66470DEC4B0F@railsnewbie.com> Message-ID: <57c63afe0706110932p4a23c4e3rcc985b5b9392bc2d@mail.gmail.com> On 6/11/07, Scott Taylor wrote: > > It looks to me that hpricot is a dependency to building rspec: > > euclid% rake pre_commit > (in /Users/smtlaissezfaire/ruby/projects/rspec/hpricot) > rake aborted! > Could not find RubyGem hpricot (>= 0.0.0) > /Users/smtlaissezfaire/ruby/projects/rspec/hpricot/rakefile:9 > (See full trace by running task with --trace) > > Let me know if I'm wrong. Otherwise, I'll submit a patch in the docs. Submit away. Thanks Scott. David > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Mon Jun 11 12:37:19 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 11 Jun 2007 12:37:19 -0400 Subject: [rspec-users] hpricot as dependency for building rspec? In-Reply-To: <57c63afe0706110932p4a23c4e3rcc985b5b9392bc2d@mail.gmail.com> References: <978FCF19-D9A7-47BC-AA11-66470DEC4B0F@railsnewbie.com> <57c63afe0706110932p4a23c4e3rcc985b5b9392bc2d@mail.gmail.com> Message-ID: <7BC4DB0B-D627-472F-A104-0110F43A3DA2@railsnewbie.com> Why is it included? What html are you parsing? Scott On Jun 11, 2007, at 12:32 PM, David Chelimsky wrote: > On 6/11/07, Scott Taylor wrote: >> >> It looks to me that hpricot is a dependency to building rspec: >> >> euclid% rake pre_commit >> (in /Users/smtlaissezfaire/ruby/projects/rspec/hpricot) >> rake aborted! >> Could not find RubyGem hpricot (>= 0.0.0) >> /Users/smtlaissezfaire/ruby/projects/rspec/hpricot/rakefile:9 >> (See full trace by running task with --trace) >> >> Let me know if I'm wrong. Otherwise, I'll submit a patch in the >> docs. > > Submit away. Thanks Scott. > > David > >> >> Scott >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Jun 11 12:40:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 11 Jun 2007 11:40:13 -0500 Subject: [rspec-users] hpricot as dependency for building rspec? In-Reply-To: <7BC4DB0B-D627-472F-A104-0110F43A3DA2@railsnewbie.com> References: <978FCF19-D9A7-47BC-AA11-66470DEC4B0F@railsnewbie.com> <57c63afe0706110932p4a23c4e3rcc985b5b9392bc2d@mail.gmail.com> <7BC4DB0B-D627-472F-A104-0110F43A3DA2@railsnewbie.com> Message-ID: <57c63afe0706110940q3cf345cej37e69523c507b792@mail.gmail.com> On 6/11/07, Scott Taylor wrote: > > Why is it included? What html are you parsing? Take a look at html_formatter_spec.rb > > Scott > > > On Jun 11, 2007, at 12:32 PM, David Chelimsky wrote: > > > On 6/11/07, Scott Taylor wrote: > >> > >> It looks to me that hpricot is a dependency to building rspec: > >> > >> euclid% rake pre_commit > >> (in /Users/smtlaissezfaire/ruby/projects/rspec/hpricot) > >> rake aborted! > >> Could not find RubyGem hpricot (>= 0.0.0) > >> /Users/smtlaissezfaire/ruby/projects/rspec/hpricot/rakefile:9 > >> (See full trace by running task with --trace) > >> > >> Let me know if I'm wrong. Otherwise, I'll submit a patch in the > >> docs. > > > > Submit away. Thanks Scott. > > > > David > > > >> > >> Scott > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From smingins at elctech.com Mon Jun 11 14:14:00 2007 From: smingins at elctech.com (Shane Mingins) Date: Tue, 12 Jun 2007 06:14:00 +1200 Subject: [rspec-users] Testing create in Rails controller In-Reply-To: <57c63afe0706110425p310d1103r9f5e551e2314c5d4@mail.gmail.com> References: <7A1F4C10-99F5-44CE-860A-93DC0672D5EB@elctech.com> <57c63afe0706110425p310d1103r9f5e551e2314c5d4@mail.gmail.com> Message-ID: <58F61B40-D3BC-4C41-A87A-A12090B2F94B@elctech.com> Thanks David On 11/06/2007, at 11:25 PM, David Chelimsky wrote: > > Two problems. > > 1. The return value from Product.new(params[:product]) gets assigned > to @product. You need to tell the :new method to return something when > setting up the Message Expectation. > > 2. :save is getting called on @product, not the Product class. > > > Enjoy, > David > > From jtprince at gmail.com Mon Jun 11 15:42:14 2007 From: jtprince at gmail.com (John Prince) Date: Mon, 11 Jun 2007 14:42:14 -0500 Subject: [rspec-users] DelegateClass fails Message-ID: <466DA596.1070406@byu.net> This is not a big deal, but DelegateClass fails with rspec when methods are defined in the the delegating class. Here's code that demonstrates: require 'delegate' gem 'rspec' # Version 1.0.5 ############################################################ # CONTROL EXAMPLE: Works FINE. ############################################################ class InheritedClass < Array def large? self.size >= 5 end end describe InheritedClass, "normal inheriting class is OK" do it 'works just fine' do myclass = InheritedClass.new([1,2,3,4,5,6]) myclass.should be_large end end ############################################################ # rspec should work on DelegateClasses. Not sure how... ############################################################ class DelegateKlass < DelegateClass(Array) def initialize(array) @internal_array = array super(@internal_array) end def large? @internal_array.size >= 5 end end =begin # will work if this code is available. class Array def large? self.size >= 5 end end =end describe DelegateKlass, "delegate class fails" do it 'does not work on methods defined within the delegating class' do myclass = DelegateKlass.new([1,2,3,4,5,6]) myclass.should be_large end end --JTP From dchelimsky at gmail.com Mon Jun 11 17:19:41 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 11 Jun 2007 16:19:41 -0500 Subject: [rspec-users] DelegateClass fails In-Reply-To: <466DA596.1070406@byu.net> References: <466DA596.1070406@byu.net> Message-ID: <57c63afe0706111419kc079218m3a2f6b3fce37ad08@mail.gmail.com> On 6/11/07, John Prince wrote: > This is not a big deal, but DelegateClass fails with rspec when methods > are defined in the the delegating class. Here's code that demonstrates: > > require 'delegate' > gem 'rspec' > # Version 1.0.5 > > ############################################################ > # CONTROL EXAMPLE: Works FINE. > ############################################################ > class InheritedClass < Array > def large? > self.size >= 5 > end > end > > describe InheritedClass, "normal inheriting class is OK" do > it 'works just fine' do > myclass = InheritedClass.new([1,2,3,4,5,6]) > myclass.should be_large > end > end > > > ############################################################ > # rspec should work on DelegateClasses. Not sure how... > ############################################################ > > class DelegateKlass < DelegateClass(Array) > > def initialize(array) > @internal_array = array > super(@internal_array) > end > > def large? > @internal_array.size >= 5 > end > > end > > =begin > # will work if this code is available. > class Array > def large? > self.size >= 5 > end > end > =end > > > describe DelegateKlass, "delegate class fails" do > it 'does not work on methods defined within the delegating class' do > myclass = DelegateKlass.new([1,2,3,4,5,6]) > myclass.should be_large > end > end What's the error message? > > > --JTP > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From linojon at gmail.com Mon Jun 11 18:17:20 2007 From: linojon at gmail.com (Jonathan Linowes) Date: Mon, 11 Jun 2007 18:17:20 -0400 Subject: [rspec-users] not response Message-ID: <834B8CFD-8ADC-4DFD-B5FE-E9603DD0CCC9@gmail.com> (rails) I was making a model called Survey and another called Response hehe, don't use a model named Response... it really messes up the mocks and stubs :) From aslak.hellesoy at gmail.com Mon Jun 11 18:42:54 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 12 Jun 2007 00:42:54 +0200 Subject: [rspec-users] DelegateClass fails In-Reply-To: <466DA596.1070406@byu.net> References: <466DA596.1070406@byu.net> Message-ID: <8d961d900706111542t64b8c420je6e4d4dfd4a07e5e@mail.gmail.com> Please submit a failing spec On 6/11/07, John Prince wrote: > This is not a big deal, but DelegateClass fails with rspec when methods > are defined in the the delegating class. Here's code that demonstrates: > > require 'delegate' > gem 'rspec' > # Version 1.0.5 > > ############################################################ > # CONTROL EXAMPLE: Works FINE. > ############################################################ > class InheritedClass < Array > def large? > self.size >= 5 > end > end > > describe InheritedClass, "normal inheriting class is OK" do > it 'works just fine' do > myclass = InheritedClass.new([1,2,3,4,5,6]) > myclass.should be_large > end > end > > > ############################################################ > # rspec should work on DelegateClasses. Not sure how... > ############################################################ > > class DelegateKlass < DelegateClass(Array) > > def initialize(array) > @internal_array = array > super(@internal_array) > end > > def large? > @internal_array.size >= 5 > end > > end > > =begin > # will work if this code is available. > class Array > def large? > self.size >= 5 > end > end > =end > > > describe DelegateKlass, "delegate class fails" do > it 'does not work on methods defined within the delegating class' do > myclass = DelegateKlass.new([1,2,3,4,5,6]) > myclass.should be_large > end > end > > > --JTP > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Mon Jun 11 18:49:29 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 12 Jun 2007 00:49:29 +0200 Subject: [rspec-users] not response In-Reply-To: <834B8CFD-8ADC-4DFD-B5FE-E9603DD0CCC9@gmail.com> References: <834B8CFD-8ADC-4DFD-B5FE-E9603DD0CCC9@gmail.com> Message-ID: <8d961d900706111549k5c740a92w6857244971c5a1c5@mail.gmail.com> On 6/12/07, Jonathan Linowes wrote: > (rails) > I was making a model called Survey and another called Response > hehe, don't use a model named Response... > it really messes up the mocks and stubs > :) > was this supposed to be part of a previous thread? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jonathan at parkerhill.com Mon Jun 11 19:01:53 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Mon, 11 Jun 2007 19:01:53 -0400 Subject: [rspec-users] not response In-Reply-To: <8d961d900706111549k5c740a92w6857244971c5a1c5@mail.gmail.com> References: <834B8CFD-8ADC-4DFD-B5FE-E9603DD0CCC9@gmail.com> <8d961d900706111549k5c740a92w6857244971c5a1c5@mail.gmail.com> Message-ID: nope On Jun 11, 2007, at 6:49 PM, aslak hellesoy wrote: > On 6/12/07, Jonathan Linowes wrote: >> (rails) >> I was making a model called Survey and another called Response >> hehe, don't use a model named Response... >> it really messes up the mocks and stubs >> :) >> > > was this supposed to be part of a previous thread? > >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jonathan at parkerhill.com Tue Jun 12 02:23:06 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 12 Jun 2007 02:23:06 -0400 Subject: [rspec-users] rdebug spec ? Message-ID: Can you run rdebug on specs? I get errors when I try: $ rdebug spec ./spec/models/select_option_spec.rb ./spec: Is a directory - ./spec (Errno::EISDIR) from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ rdebug:136:in `debug_load' from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ rdebug:136 from /opt/local/bin/rdebug:16:in `load' from /opt/local/bin/rdebug:16 From luislavena at gmail.com Tue Jun 12 02:37:08 2007 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 12 Jun 2007 03:37:08 -0300 Subject: [rspec-users] rdebug spec ? In-Reply-To: References: Message-ID: <71166b3b0706112337y1dd52461u7d72cfa8e9822ca1@mail.gmail.com> On 6/12/07, Jonathan Linowes wrote: > Can you run rdebug on specs? > > I get errors when I try: > > $ rdebug spec ./spec/models/select_option_spec.rb > ./spec: Is a directory - ./spec (Errno::EISDIR) > from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ > rdebug:136:in `debug_load' > from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ > rdebug:136 > from /opt/local/bin/rdebug:16:in `load' > from /opt/local/bin/rdebug:16 > Try the following: require 'ruby-debug' at top of your spec file. then, put 'debugger' inside your example block. That worked for me, also in combination with spec -e (just to run a specific example to pinpoint the problem). HTH, -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi From james.deville at gmail.com Tue Jun 12 02:40:08 2007 From: james.deville at gmail.com (James Deville) Date: Mon, 11 Jun 2007 23:40:08 -0700 Subject: [rspec-users] rdebug spec ? In-Reply-To: References: Message-ID: <466e3ff7.1917c45d.7b08.5bbc@mx.google.com> Since this appears to be for Rails, get ruby-debug instead. Then you just have to put 'debugger' in where you want to enter your code. It works great. Otherwise, it may still work, but it will probably require configuration. The other option is to see what rdebug's version of the -I switch is. For ruby (command line) -I followed by the library path makes that library get loaded. -----Original Message----- From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of Jonathan Linowes Sent: Monday, June 11, 2007 11:23 PM To: rspec-users Subject: [rspec-users] rdebug spec ? Can you run rdebug on specs? I get errors when I try: $ rdebug spec ./spec/models/select_option_spec.rb ./spec: Is a directory - ./spec (Errno::EISDIR) from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ rdebug:136:in `debug_load' from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ rdebug:136 from /opt/local/bin/rdebug:16:in `load' from /opt/local/bin/rdebug:16 _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Tue Jun 12 02:43:47 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 12 Jun 2007 02:43:47 -0400 Subject: [rspec-users] rdebug spec ? In-Reply-To: <71166b3b0706112337y1dd52461u7d72cfa8e9822ca1@mail.gmail.com> References: <71166b3b0706112337y1dd52461u7d72cfa8e9822ca1@mail.gmail.com> Message-ID: <1A34269B-902F-443B-A59D-FBCD8D8B97C6@railsnewbie.com> As I said in #ruby-lang (I thought it may be helpful to someone else)... For those of you using textmate, I've setup a snippet called rdebug, which adds the following: require 'rubygems'; require 'ruby-debug'; debugger Usually I only do this as a last resort. My workflow goes as follows: I run my spec suite for the newest spec. If it fails and I simply cannot figure out why, I add this snippet before the line which fails (inside the spec), and then rerun the spec suite. Since I use a failure file, it will only run this spec, and dump me right before the spec fails. Hope that helps, Scott On Jun 12, 2007, at 2:37 AM, Luis Lavena wrote: > On 6/12/07, Jonathan Linowes wrote: >> Can you run rdebug on specs? >> >> I get errors when I try: >> >> $ rdebug spec ./spec/models/select_option_spec.rb >> ./spec: Is a directory - ./spec (Errno::EISDIR) >> from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ >> rdebug:136:in `debug_load' >> from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ >> rdebug:136 >> from /opt/local/bin/rdebug:16:in `load' >> from /opt/local/bin/rdebug:16 >> > > Try the following: > > require 'ruby-debug' at top of your spec file. > > then, put 'debugger' inside your example block. > > That worked for me, also in combination with spec -e (just to run a > specific example to pinpoint the problem). > > HTH, > > -- > Luis Lavena > Multimedia systems > - > Leaders are made, they are not born. They are made by hard effort, > which is the price which all of us must pay to achieve any goal that > is worthwhile. > Vince Lombardi > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From linojon at gmail.com Tue Jun 12 04:38:02 2007 From: linojon at gmail.com (Jonathan Linowes) Date: Tue, 12 Jun 2007 04:38:02 -0400 Subject: [rspec-users] should_change Message-ID: <1D3F44FF-5202-48B5-A7A4-4F96EF46D01A@gmail.com> Hi, I'm wondering if I'm using should_change correctly. Here's what I'm doing http://pastie.caboo.se/69704 thanks From jonathan at parkerhill.com Tue Jun 12 04:38:54 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 12 Jun 2007 04:38:54 -0400 Subject: [rspec-users] rdebug spec ? In-Reply-To: <466e3ff7.1917c45d.7b08.5bbc@mx.google.com> References: <466e3ff7.1917c45d.7b08.5bbc@mx.google.com> Message-ID: <8BE26717-9EC7-42AC-AC01-829BDE82D61E@parkerhill.com> ruby-debug works nice, I can put the breakpoint in my app rather than the spec examples. thanks On Jun 12, 2007, at 2:40 AM, James Deville wrote: > Since this appears to be for Rails, get ruby-debug instead. Then > you just > have to put 'debugger' in where you want to enter your code. It > works great. > > Otherwise, it may still work, but it will probably require > configuration. > > The other option is to see what rdebug's version of the -I switch > is. For > ruby (command line) -I followed by the library path makes that > library get > loaded. > > -----Original Message----- > From: rspec-users-bounces at rubyforge.org > [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of Jonathan > Linowes > Sent: Monday, June 11, 2007 11:23 PM > To: rspec-users > Subject: [rspec-users] rdebug spec ? > > Can you run rdebug on specs? > > I get errors when I try: > > $ rdebug spec ./spec/models/select_option_spec.rb > ./spec: Is a directory - ./spec (Errno::EISDIR) > from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ > rdebug:136:in `debug_load' > from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ > rdebug:136 > from /opt/local/bin/rdebug:16:in `load' > from /opt/local/bin/rdebug:16 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From court3nay at gmail.com Tue Jun 12 05:32:36 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 12 Jun 2007 02:32:36 -0700 Subject: [rspec-users] mystery problem with svn post-commit script running rspec tests In-Reply-To: References: Message-ID: <4b430c8f0706120232h141e20bem309b68dbebb1879c@mail.gmail.com> probably. best to use popen3 to capture those. stdin, stdout, stderr = Open3.popen3('nroff -man') On 6/9/07, Joe Van Dyk wrote: > Oh, this is a Rails project, by the way. > > Do the specs mess around with stdout or stderr? > > Joe > > On 6/9/07, Joe Van Dyk wrote: > > So, just spent seven straight hours on this. > > > > I have a post-commit svn script that runs all my tests. Emails me if > > something goes wrong. > > > > One of the lines looks like: > > @output = `rake test RAILS_ENV=test` > > > > The output from the rspec tests don't seem to appear in @output. Why > > would that be? Oddly enough, that only seems to happen when the > > script is ran from svn's post-commit hook. When I run the script > > manually, the rspec test results show up in @output. > > > > Joe > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From court3nay at gmail.com Tue Jun 12 05:39:33 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 12 Jun 2007 02:39:33 -0700 Subject: [rspec-users] rspec 1.0.x and liquid? Message-ID: <4b430c8f0706120239o76ea330ax45c8051a9548a0ce@mail.gmail.com> Is anyone else using liquid with the > 1 rspec? This seems to fail: it 'should render show' do response.should render_template('buyers/show') get :show, :id => 1 end with an error like 1) NoMethodError in '/buyer GET should render show' You have a nil object when you didn't expect it! The error occurred while evaluating nil.first_render /rails/store/trunk/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/render_template.rb:12:in `matches?' spec/controllers/buyer_controller_spec.rb:57: spec/controllers/buyer_controller_spec.rb:63: should render_template is looking for 11: def matches?(response) 12: @actual = response.rendered_file(!expected.include?('/')) 13: actual == expected 14: end TestResponse.rendered_file looks like 208: def rendered_file(with_controller=false) 209: unless template.first_render.nil? 210: unless with_controller 211: template.first_render so TestResponse is missing 'template'. Any clues? Courtenay http://blog.caboo.se http://entp.com From court3nay at gmail.com Tue Jun 12 06:32:57 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 12 Jun 2007 03:32:57 -0700 Subject: [rspec-users] RSpec In-Reply-To: References: <8d961d900705260304n5fe70858mf39aef06d648328@mail.gmail.com> <8d961d900705260901h3e86b4cauacba95be7c0ebc11@mail.gmail.com> <8d961d900705260938n539dba57k4de53a995b76f68f@mail.gmail.com> <4b430c8f0705261428w17b88a2bwb2d2e8b7fab4b451@mail.gmail.com> Message-ID: <4b430c8f0706120332y395d103cwefb20ac67d09111a@mail.gmail.com> The app is now updated to 1.0.4 or thereabouts. On 5/26/07, Omen King wrote: > He's really lazy, > > I've updated the spec_helper.rb and translated the spec. > I'm getting different errors now such as: > > 1) > NoMethodError in 'Requesting /assets/1;edit using GET should render > edit.rhtml' > undefined method `render?' for > # > ./spec/controllers/user_assets_controller_spec.rb:201: > > and > > 5) > NoMethodError in '/users/edit.rhtml should render edit form' > undefined method `matches?' for # > ./spec/views/users/edit_rhtml_spec.rb:21: > > I'm not too certain why it isn't seeing matches but I'll have to do more > digging. > > I love caboo.se! > > > > > On 5/26/07, Courtenay wrote: > > Heh. The author is lazy and hasn't upgraded his sample apps to latest > rspec. > > Also, you didn't load the database schema; > > > > rake db:migrate > > > > Patches are, of course, always welcome. > > > > Courtenay (the lazy author) > > http://blog.caboo.se > > > > > > On 5/26/07, aslak hellesoy < aslak.hellesoy at gmail.com> wrote: > > > The app you downloaded is not compatible with rspec 1.0. Please > > > contact the app authors or upgrade it yourself. See upgrading on the > > > rspec website. > > > > > > On 5/26/07, Omen King wrote: > > > > So I can run rake spec. I've gotten errors and I not too sure what I'm > > > > looking at. > > > > > > > > Lets take a look at error 1: > > > > =================================================== > > > > specify "should render new" do > > > > controller.should_render :new > > > > get :new > > > > end > > > > > > > > 1) > > > > NoMethodError in '/session/new GET should render new' > > > > undefined method `should_render' for # > > > > ./spec/controllers/session_controller_spec.rb:7: > > > > =================================================== > > > > Is it trying to called a method called 'should_render' for > > > > session_controller of session_controller_spec? > > > > > > > > 2) > > > > NameError in '/session POST without remember me should authenticate > user' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:15: > > > > > > > > 3) > > > > NameError in '/session POST without remember me should login user' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:15: > > > > > > > > 4) > > > > NameError in '/session POST without remember me should not remember > me' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:15: > > > > > > > > 5) > > > > NameError in '/session POST without remember me should redirect to > root' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:15: > > > > > > > > 6) > > > > NameError in '/session POST with remember me should remember me' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:44: > > > > > > > > 7) > > > > NameError in '/session POST with remember me should create cookie' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:44: > > > > > > > > 8) > > > > NameError in '/session POST when invalid should authenticate user' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:72: > > > > > > > > 9) > > > > NameError in '/session POST when invalid should login user' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:72: > > > > > > > > 10) > > > > NameError in '/session POST when invalid should not remember me' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:72: > > > > > > > > 11) > > > > NameError in '/session POST when invalid should render new' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:72: > > > > > > > > 12) > > > > NameError in '/session DELETE should get current user' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:102: > > > > > > > > 13) > > > > NameError in '/session DELETE should forget current user' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:102: > > > > > > > > 14) > > > > NameError in '/session DELETE should delete token on logout' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:102: > > > > > > > > 15) > > > > NameError in '/session DELETE should reset session' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:102: > > > > > > > > 16) > > > > NameError in '/session DELETE should redirect to root' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/controllers/session_controller_spec.rb:102: > > > > > > > > 17) > > > > NoMethodError in 'Requesting /assets using GET should render > index.rhtml' > > > > undefined method `should_render' for > # > > > > ./spec/controllers/user_assets_controller_spec.rb:25: > > > > > > > > 18) > > > > NoMethodError in 'Requesting /assets/1 using GET should render > show.rhtml' > > > > undefined method `should_render' for > # > > > > ./spec/controllers/user_assets_controller_spec.rb:93: > > > > > > > > 19) > > > > NoMethodError in 'Requesting /assets/new using GET should render > new.rhtml' > > > > undefined method `should_render' for > # > > > > > ./spec/controllers/user_assets_controller_spec.rb:159: > > > > > > > > 20) > > > > NoMethodError in 'Requesting /assets/1;edit using GET should render > > > > edit.rhtml' > > > > undefined method `should_render' for > # > > > > > ./spec/controllers/user_assets_controller_spec.rb:201: > > > > > > > > 21) > > > > NoMethodError in 'Requesting /users using GET should render > index.rhtml' > > > > undefined method `should_render' for # > > > > ./spec/controllers/users_controller_spec.rb:49: > > > > > > > > 22) > > > > NoMethodError in 'Requesting /users/1 using GET should render > show.rhtml' > > > > undefined method `should_render' for # > > > > ./spec/controllers/users_controller_spec.rb:112: > > > > > > > > 23) > > > > NoMethodError in 'Requesting /users/new using GET should render > new.rhtml' > > > > undefined method `should_render' for # > > > > ./spec/controllers/users_controller_spec.rb:175: > > > > > > > > 24) > > > > ActiveRecord::StatementInvalid in 'Requesting /users/1;edit using GET > should > > > > fail if current user doesn't match' > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > FIELDS > > > > FROM users > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > `log' > > > > ./spec/controllers/users_controller_spec.rb:209:in > `new' > > > > ./spec/controllers/users_controller_spec.rb:209: > > > > > > > > 25) > > > > NoMethodError in 'Requesting /users/1;edit using GET should render > > > > edit.rhtml' > > > > undefined method `should_render' for # > > > > ./spec/controllers/users_controller_spec.rb:221: > > > > > > > > 26) > > > > NoMethodError in 'the UserAssetsHelper should return user login name' > > > > undefined method `should_eql' for "JoeLogin":String > > > > ./spec/helpers/user_assets_helper_spec.rb:11: > > > > > > > > 27) > > > > NameError in 'the generated url helpers for UserAssetsController > should > > > > return assets path given no arguments' > > > > undefined local variable or method `controller' for [Dynamically > generated > > > > class for RSpec example]:# > > > > (eval):2:in `assets_path' > > > > ./spec/helpers/user_assets_url_helpers_spec.rb:24: > > > > > > > > 28) > > > > NameError in 'the generated url helpers for UserAssetsController > should > > > > return assets path given explicit argument' > > > > undefined local variable or method `controller' for [Dynamically > generated > > > > class for RSpec example]:# > > > > (eval):2:in `assets_path' > > > > ./spec/helpers/user_assets_url_helpers_spec.rb:28: > > > > > > > > 29) > > > > NameError in 'the generated url helpers for UserAssetsController > should > > > > return asset path' > > > > undefined local variable or method `controller' for [Dynamically > generated > > > > class for RSpec example]:# > > > > (eval):2:in `asset_path' > > > > ./spec/helpers/user_assets_url_helpers_spec.rb:32: > > > > > > > > 30) > > > > NameError in 'the generated url helpers for UserAssetsController > should > > > > return edit_asset path' > > > > undefined local variable or method `controller' for [Dynamically > generated > > > > class for RSpec example]:# > > > > (eval):2:in `edit_asset_path' > > > > ./spec/helpers/user_assets_url_helpers_spec.rb:36: > > > > > > > > 31) > > > > NameError in 'the generated url helpers for UserAssetsController > should > > > > return new_asset path' > > > > undefined local variable or method `controller' for [Dynamically > generated > > > > class for RSpec example]:# > > > > (eval):2:in `new_asset_path' > > > > ./spec/helpers/user_assets_url_helpers_spec.rb:40: > > > > > > > > 32) > > > > NameError in 'the generated url helpers for UserAssetsController > should > > > > return asset_attachable path' > > > > undefined local variable or method `controller' for [Dynamically > generated > > > > class for RSpec example]:# > > > > (eval):2:in `asset_attachable_path' > > > > ./spec/helpers/user_assets_url_helpers_spec.rb:44: > > > > > > > > 33) > > > > ActiveRecord::StatementInvalid in 'Given a generated asset_spec.rb > with > > > > fixtures loaded fixtures should load two Assets' > > > > ActiveRecord::StatementInvalid: Mysql::Error: #42S02Table > > > > 'sample_test.assets' doesn't exist: DELETE FROM assets: DELETE FROM > assets > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > `log' > > > > > /Users/multimedia/Desktop/rest_org/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/model.rb:12:in > > > > `before_eval' > > > > > > > > 34) > > > > ActiveRecord::StatementInvalid in 'A User abstract class should have > valid > > > > associations' > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > FIELDS > > > > FROM users > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > `log' > > > > ./spec/models/authenticated_base_spec.rb:7:in `new' > > > > ./spec/models/authenticated_base_spec.rb:7: > > > > > > > > 35) > > > > ActiveRecord::StatementInvalid in 'An existing user should > authenticate with > > > > new or reset password' > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > FIELDS > > > > FROM users > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > `log' > > > > ./spec/models/authenticated_base_spec.rb:14: > > > > > > > > 36) > > > > ActiveRecord::StatementInvalid in 'An existing user should not rehash > > > > password on login change' > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > FIELDS > > > > FROM users > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > `log' > > > > ./spec/models/authenticated_base_spec.rb:14: > > > > > > > > 37) > > > > ActiveRecord::StatementInvalid in 'An existing user should remember > token' > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > FIELDS > > > > FROM users > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > `log' > > > > ./spec/models/authenticated_base_spec.rb:14: > > > > > > > > 38) > > > > ActiveRecord::StatementInvalid in 'An existing user should increment > hit > > > > counter' > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > FIELDS > > > > FROM users > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > `log' > > > > ./spec/models/authenticated_base_spec.rb:14: > > > > > > > > 39) > > > > ActiveRecord::StatementInvalid in 'An existing user should forget > token' > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > FIELDS > > > > FROM users > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > `log' > > > > ./spec/models/authenticated_base_spec.rb:14: > > > > > > > > 40) > > > > ActiveRecord::StatementInvalid in 'An existing user should be > remembered for > > > > a period' > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > FIELDS > > > > FROM users > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > `log' > > > > ./spec/models/authenticated_base_spec.rb:14: > > > > > > > > 41) > > > > NoMethodError in 'A new user should create' > > > > undefined method `should_change' for > > > > > # > > > > ./spec/models/authenticated_base_spec.rb:59: > > > > > > > > 42) > > > > NoMethodError in 'A new user should require login' > > > > undefined method `should_not_change' for > > > > > # > > > > ./spec/models/authenticated_base_spec.rb:63: > > > > > > > > 43) > > > > NoMethodError in 'A new user should require password' > > > > undefined method `should_not_change' for > > > > > # > > > > ./spec/models/authenticated_base_spec.rb:68: > > > > > > > > 44) > > > > NoMethodError in 'A new user should require password confirmation' > > > > undefined method `should_not_change' for > > > > > # > > > > ./spec/models/authenticated_base_spec.rb:73: > > > > > > > > 45) > > > > NoMethodError in 'A new user should require email' > > > > undefined method `should_not_change' for > > > > > # > > > > ./spec/models/authenticated_base_spec.rb:78: > > > > > > > > 46) > > > > ActiveRecord::StatementInvalid in 'A User should have valid > associations' > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > FIELDS > > > > FROM users > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > `log' > > > > ./spec/models/user_spec.rb:7:in `new' > > > > ./spec/models/user_spec.rb:7: > > > > > > > > 47) > > > > ActiveRecord::StatementInvalid in 'A User should protect against > updates to > > > > secure attributes' > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > FIELDS > > > > FROM users > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > `log' > > > > ./spec/models/user_spec.rb:7:in `new' > > > > ./spec/models/user_spec.rb:7: > > > > > > > > 48) > > > > NoMethodError in '/assets/edit.rhtml should render edit form' > > > > undefined method `should_have_tag' for > > > > # > > > > ./spec/views/assets/edit_rhtml_spec.rb:36: > > > > > > > > 49) > > > > NoMethodError in '/assets/index.rhtml should render list of assets' > > > > undefined method `should_have_tag' for > > > > # > > > > ./spec/views/assets/index_rhtml_spec.rb:49: > > > > > > > > 50) > > > > NoMethodError in '/assets/new.rhtml should render new form' > > > > undefined method `should_have_tag' for > > > > # > > > > ./spec/views/assets/new_rhtml_spec.rb:39: > > > > > > > > 51) > > > > NoMethodError in '/users/edit.rhtml should render edit form' > > > > undefined method `should_have_tag' for > > > > # > > > > ./spec/views/users/edit_rhtml_spec.rb:21: > > > > > > > > 52) > > > > NameError in '/users/new.rhtml should render new form' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/views/users/new_rhtml_spec.rb:10: > > > > > > > > 53) > > > > NameError in '/users/show.rhtml should render attributes in

' > > > > undefined local variable or method `mock_user' for [Dynamically > generated > > > > class for RSpec example]:# > > > > ./spec/views/users/show_rhtml_spec.rb:7: > > > > > > > > Finished in 2.492637 seconds > > > > > > > > 117 examples, 53 failures > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From court3nay at gmail.com Tue Jun 12 06:40:59 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 12 Jun 2007 03:40:59 -0700 Subject: [rspec-users] rspec 1.0.x and liquid? In-Reply-To: <4b430c8f0706120239o76ea330ax45c8051a9548a0ce@mail.gmail.com> References: <4b430c8f0706120239o76ea330ax45c8051a9548a0ce@mail.gmail.com> Message-ID: <4b430c8f0706120340hefeb022sf6b10caf62c0680f@mail.gmail.com> rspec thinks that response.should render_template comes AFTER the get :show Thanks to Dylan (abcde) for this gotcha. Also solves my should_redirect problems :) On 6/12/07, Courtenay wrote: > Is anyone else using liquid with the > 1 rspec? This seems to fail: > > > it 'should render show' do > response.should render_template('buyers/show') > get :show, :id => 1 > end > > > with an error like > > 1) > NoMethodError in '/buyer GET should render show' > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.first_render > /rails/store/trunk/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/render_template.rb:12:in > `matches?' > spec/controllers/buyer_controller_spec.rb:57: > spec/controllers/buyer_controller_spec.rb:63: > > > should render_template is looking for > > 11: def matches?(response) > 12: @actual = response.rendered_file(!expected.include?('/')) > 13: actual == expected > 14: end > > > TestResponse.rendered_file looks like > > 208: def rendered_file(with_controller=false) > 209: unless template.first_render.nil? > 210: unless with_controller > 211: template.first_render > > > so TestResponse is missing 'template'. Any clues? > > > > Courtenay > > http://blog.caboo.se > http://entp.com > From dchelimsky at gmail.com Tue Jun 12 07:36:53 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Jun 2007 06:36:53 -0500 Subject: [rspec-users] should_change In-Reply-To: <1D3F44FF-5202-48B5-A7A4-4F96EF46D01A@gmail.com> References: <1D3F44FF-5202-48B5-A7A4-4F96EF46D01A@gmail.com> Message-ID: <57c63afe0706120436k64b40251i38de6c772b5bd6aa@mail.gmail.com> On 6/12/07, Jonathan Linowes wrote: > Hi, > I'm wondering if I'm using should_change correctly. > Here's what I'm doing > http://pastie.caboo.se/69704 You've got this: should change(SelectOption.find(:all), :size).by(4) The problem is that the result of SelectOption.find(:all) is an argument to #change, so it is only evaluated once. You can get what you're looking for like this: should change(SelectOption, :count).by(4) or this: should change { SelectOption.find(:all).size }.by(4) David > thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Jun 12 07:45:32 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Jun 2007 06:45:32 -0500 Subject: [rspec-users] rdebug spec ? In-Reply-To: <8BE26717-9EC7-42AC-AC01-829BDE82D61E@parkerhill.com> References: <466e3ff7.1917c45d.7b08.5bbc@mx.google.com> <8BE26717-9EC7-42AC-AC01-829BDE82D61E@parkerhill.com> Message-ID: <57c63afe0706120445x328fee11s1606d61afa450cad@mail.gmail.com> On 6/12/07, Jonathan Linowes wrote: > ruby-debug works nice, I can put the breakpoint in my app rather than > the spec examples. > thanks > > On Jun 12, 2007, at 2:40 AM, James Deville wrote: > > > Since this appears to be for Rails, get ruby-debug instead. Then > > you just > > have to put 'debugger' in where you want to enter your code. It > > works great. > > > > Otherwise, it may still work, but it will probably require > > configuration. rdebug is the command that gets installed with ruby-debug, so we're all talking about the same thing. To run a single spec file, just do this: rdebug ./spec/models/select_option_spec.rb You can put 'debugger' in your files or not. It's up to you. In practice sometimes I do, sometimes I don't. Cheers, David > > > > The other option is to see what rdebug's version of the -I switch > > is. For > > ruby (command line) -I followed by the library path makes that > > library get > > loaded. > > > > -----Original Message----- > > From: rspec-users-bounces at rubyforge.org > > [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of Jonathan > > Linowes > > Sent: Monday, June 11, 2007 11:23 PM > > To: rspec-users > > Subject: [rspec-users] rdebug spec ? > > > > Can you run rdebug on specs? > > > > I get errors when I try: > > > > $ rdebug spec ./spec/models/select_option_spec.rb > > ./spec: Is a directory - ./spec (Errno::EISDIR) > > from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ > > rdebug:136:in `debug_load' > > from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ > > rdebug:136 > > from /opt/local/bin/rdebug:16:in `load' > > from /opt/local/bin/rdebug:16 > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Jun 12 07:51:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Jun 2007 06:51:01 -0500 Subject: [rspec-users] rspec 1.0.x and liquid? In-Reply-To: <4b430c8f0706120340hefeb022sf6b10caf62c0680f@mail.gmail.com> References: <4b430c8f0706120239o76ea330ax45c8051a9548a0ce@mail.gmail.com> <4b430c8f0706120340hefeb022sf6b10caf62c0680f@mail.gmail.com> Message-ID: <57c63afe0706120451o1eb6505cvc6f2e60450c50912@mail.gmail.com> On 6/12/07, Courtenay wrote: > rspec thinks that response.should render_template comes AFTER the get :show Yeah - there was a time when RSpec supported should_render before or after the action. This was an attempt to make things more 'mockish', which was cool, but the code was bloody invasive (lots of rails monkey patching) and kept breaking every time there was a new changeset committed to Rails Edge. So we (I) gave it up and now these only work after the action. Perhaps we should alias it with have_rendered: response.should have_rendered('some/template') WDYT? David > > Thanks to Dylan (abcde) for this gotcha. > Also solves my should_redirect problems :) > > On 6/12/07, Courtenay wrote: > > Is anyone else using liquid with the > 1 rspec? This seems to fail: > > > > > > it 'should render show' do > > response.should render_template('buyers/show') > > get :show, :id => 1 > > end > > > > > > with an error like > > > > 1) > > NoMethodError in '/buyer GET should render show' > > You have a nil object when you didn't expect it! > > The error occurred while evaluating nil.first_render > > /rails/store/trunk/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/render_template.rb:12:in > > `matches?' > > spec/controllers/buyer_controller_spec.rb:57: > > spec/controllers/buyer_controller_spec.rb:63: > > > > > > should render_template is looking for > > > > 11: def matches?(response) > > 12: @actual = response.rendered_file(!expected.include?('/')) > > 13: actual == expected > > 14: end > > > > > > TestResponse.rendered_file looks like > > > > 208: def rendered_file(with_controller=false) > > 209: unless template.first_render.nil? > > 210: unless with_controller > > 211: template.first_render > > > > > > so TestResponse is missing 'template'. Any clues? > > > > > > > > Courtenay > > > > http://blog.caboo.se > > http://entp.com > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From win at wincent.com Tue Jun 12 08:53:57 2007 From: win at wincent.com (Wincent Colaiuta) Date: Tue, 12 Jun 2007 14:53:57 +0200 Subject: [rspec-users] rspec 1.0.x and liquid? In-Reply-To: <57c63afe0706120451o1eb6505cvc6f2e60450c50912@mail.gmail.com> References: <4b430c8f0706120239o76ea330ax45c8051a9548a0ce@mail.gmail.com> <4b430c8f0706120340hefeb022sf6b10caf62c0680f@mail.gmail.com> <57c63afe0706120451o1eb6505cvc6f2e60450c50912@mail.gmail.com> Message-ID: El 12/6/2007, a las 13:51, David Chelimsky escribi?: > Yeah - there was a time when RSpec supported should_render before or > after the action. This was an attempt to make things more 'mockish', > which was cool, but the code was bloody invasive (lots of rails > monkey patching) and kept breaking every time there was a new > changeset committed to Rails Edge. So we (I) gave it up and now these > only work after the action. > > Perhaps we should alias it with have_rendered: > > response.should have_rendered('some/template') > > WDYT? I think that's an excellent idea. Much less scope for confusion. Cheers, Wincent From james.deville at gmail.com Tue Jun 12 10:29:31 2007 From: james.deville at gmail.com (James Deville) Date: Tue, 12 Jun 2007 07:29:31 -0700 Subject: [rspec-users] rdebug spec ? In-Reply-To: <57c63afe0706120445x328fee11s1606d61afa450cad@mail.gmail.com> References: <466e3ff7.1917c45d.7b08.5bbc@mx.google.com> <8BE26717-9EC7-42AC-AC01-829BDE82D61E@parkerhill.com> <57c63afe0706120445x328fee11s1606d61afa450cad@mail.gmail.com> Message-ID: <466eae07.5367eb0a.1bae.2617@mx.google.com> Good to know, I thought they were completely separate. -----Original Message----- From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of David Chelimsky Sent: Tuesday, June 12, 2007 4:46 AM To: rspec-users Subject: Re: [rspec-users] rdebug spec ? On 6/12/07, Jonathan Linowes wrote: > ruby-debug works nice, I can put the breakpoint in my app rather than > the spec examples. > thanks > > On Jun 12, 2007, at 2:40 AM, James Deville wrote: > > > Since this appears to be for Rails, get ruby-debug instead. Then > > you just > > have to put 'debugger' in where you want to enter your code. It > > works great. > > > > Otherwise, it may still work, but it will probably require > > configuration. rdebug is the command that gets installed with ruby-debug, so we're all talking about the same thing. To run a single spec file, just do this: rdebug ./spec/models/select_option_spec.rb You can put 'debugger' in your files or not. It's up to you. In practice sometimes I do, sometimes I don't. Cheers, David > > > > The other option is to see what rdebug's version of the -I switch > > is. For > > ruby (command line) -I followed by the library path makes that > > library get > > loaded. > > > > -----Original Message----- > > From: rspec-users-bounces at rubyforge.org > > [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of Jonathan > > Linowes > > Sent: Monday, June 11, 2007 11:23 PM > > To: rspec-users > > Subject: [rspec-users] rdebug spec ? > > > > Can you run rdebug on specs? > > > > I get errors when I try: > > > > $ rdebug spec ./spec/models/select_option_spec.rb > > ./spec: Is a directory - ./spec (Errno::EISDIR) > > from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ > > rdebug:136:in `debug_load' > > from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ > > rdebug:136 > > from /opt/local/bin/rdebug:16:in `load' > > from /opt/local/bin/rdebug:16 > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Jun 12 10:33:24 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Jun 2007 09:33:24 -0500 Subject: [rspec-users] rdebug spec ? In-Reply-To: <466eae07.5367eb0a.1bae.2617@mx.google.com> References: <466e3ff7.1917c45d.7b08.5bbc@mx.google.com> <8BE26717-9EC7-42AC-AC01-829BDE82D61E@parkerhill.com> <57c63afe0706120445x328fee11s1606d61afa450cad@mail.gmail.com> <466eae07.5367eb0a.1bae.2617@mx.google.com> Message-ID: <57c63afe0706120733q4c6823dfge968ecbae859dbb9@mail.gmail.com> On 6/12/07, James Deville wrote: > Good to know, I thought they were completely separate. FYI - http://viewvc.rubyforge.mmmultiworks.com/cgi/viewvc.cgi/trunk/bin/rdebug?root=ruby-debug&view=log Cheers, David > > > -----Original Message----- > From: rspec-users-bounces at rubyforge.org > [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of David Chelimsky > Sent: Tuesday, June 12, 2007 4:46 AM > To: rspec-users > Subject: Re: [rspec-users] rdebug spec ? > > On 6/12/07, Jonathan Linowes wrote: > > ruby-debug works nice, I can put the breakpoint in my app rather than > > the spec examples. > > thanks > > > > On Jun 12, 2007, at 2:40 AM, James Deville wrote: > > > > > Since this appears to be for Rails, get ruby-debug instead. Then > > > you just > > > have to put 'debugger' in where you want to enter your code. It > > > works great. > > > > > > Otherwise, it may still work, but it will probably require > > > configuration. > > rdebug is the command that gets installed with ruby-debug, so we're > all talking about the same thing. To run a single spec file, just do > this: > > rdebug ./spec/models/select_option_spec.rb > > You can put 'debugger' in your files or not. It's up to you. In > practice sometimes I do, sometimes I don't. > > Cheers, > David > > > > > > > > The other option is to see what rdebug's version of the -I switch > > > is. For > > > ruby (command line) -I followed by the library path makes that > > > library get > > > loaded. > > > > > > -----Original Message----- > > > From: rspec-users-bounces at rubyforge.org > > > [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of Jonathan > > > Linowes > > > Sent: Monday, June 11, 2007 11:23 PM > > > To: rspec-users > > > Subject: [rspec-users] rdebug spec ? > > > > > > Can you run rdebug on specs? > > > > > > I get errors when I try: > > > > > > $ rdebug spec ./spec/models/select_option_spec.rb > > > ./spec: Is a directory - ./spec (Errno::EISDIR) > > > from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ > > > rdebug:136:in `debug_load' > > > from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ > > > rdebug:136 > > > from /opt/local/bin/rdebug:16:in `load' > > > from /opt/local/bin/rdebug:16 > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From james.deville at gmail.com Tue Jun 12 11:03:09 2007 From: james.deville at gmail.com (James Deville) Date: Tue, 12 Jun 2007 08:03:09 -0700 Subject: [rspec-users] rdebug spec ? In-Reply-To: <8BE26717-9EC7-42AC-AC01-829BDE82D61E@parkerhill.com> References: <466e3ff7.1917c45d.7b08.5bbc@mx.google.com> <8BE26717-9EC7-42AC-AC01-829BDE82D61E@parkerhill.com> Message-ID: <466eb5ee.606ed976.7b08.3836@mx.google.com> I've enjoyed it. Sometimes it's also nice to drop the breakpoint in the spec to inspect the response object. Glad I could help. JD -----Original Message----- From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of Jonathan Linowes Sent: Tuesday, June 12, 2007 1:39 AM To: rspec-users Subject: Re: [rspec-users] rdebug spec ? ruby-debug works nice, I can put the breakpoint in my app rather than the spec examples. thanks On Jun 12, 2007, at 2:40 AM, James Deville wrote: > Since this appears to be for Rails, get ruby-debug instead. Then > you just > have to put 'debugger' in where you want to enter your code. It > works great. > > Otherwise, it may still work, but it will probably require > configuration. > > The other option is to see what rdebug's version of the -I switch > is. For > ruby (command line) -I followed by the library path makes that > library get > loaded. > > -----Original Message----- > From: rspec-users-bounces at rubyforge.org > [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of Jonathan > Linowes > Sent: Monday, June 11, 2007 11:23 PM > To: rspec-users > Subject: [rspec-users] rdebug spec ? > > Can you run rdebug on specs? > > I get errors when I try: > > $ rdebug spec ./spec/models/select_option_spec.rb > ./spec: Is a directory - ./spec (Errno::EISDIR) > from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ > rdebug:136:in `debug_load' > from /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.3/bin/ > rdebug:136 > from /opt/local/bin/rdebug:16:in `load' > from /opt/local/bin/rdebug:16 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users From francois.beausoleil at gmail.com Tue Jun 12 15:36:32 2007 From: francois.beausoleil at gmail.com (=?UTF-8?Q?Fran=C3=A7ois_Beausoleil?=) Date: Tue, 12 Jun 2007 15:36:32 -0400 Subject: [rspec-users] authentication, controller specs. I think I'm missing something simple .... In-Reply-To: <1181520960.16605.155.camel@localhost> References: <1181419529.16605.136.camel@localhost> <1181429027.16605.147.camel@localhost> <1181520960.16605.155.camel@localhost> Message-ID: <41d5fadf0706121236r5cbe8bcbj481e211b38f80904@mail.gmail.com> Hi, 2007/6/10, Rick Tessner : > Nope, no difference there. Joe's explanation of Enumerable#find vs. the > find method that rails uses makes sense and certainly explains the > error. > > Not sure yet how to work around this one ... You have to mock #find on the Array instance itself. things_proxy = [@thing] things_proxy.stub!(:find).and_return(things_proxy) @current_user = mock_model(User, :things => things_proxy) Hope that helps ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From omen.king at gmail.com Tue Jun 12 13:26:25 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Tue, 12 Jun 2007 13:26:25 -0400 Subject: [rspec-users] RSpec In-Reply-To: <4b430c8f0706120332y395d103cwefb20ac67d09111a@mail.gmail.com> References: <8d961d900705260304n5fe70858mf39aef06d648328@mail.gmail.com> <8d961d900705260901h3e86b4cauacba95be7c0ebc11@mail.gmail.com> <8d961d900705260938n539dba57k4de53a995b76f68f@mail.gmail.com> <4b430c8f0705261428w17b88a2bwb2d2e8b7fab4b451@mail.gmail.com> <4b430c8f0706120332y395d103cwefb20ac67d09111a@mail.gmail.com> Message-ID: Good to know, I'll be hacking away at it. On 6/12/07, Courtenay wrote: > > The app is now updated to 1.0.4 or thereabouts. > > On 5/26/07, Omen King wrote: > > He's really lazy, > > > > I've updated the spec_helper.rb and translated the spec. > > I'm getting different errors now such as: > > > > 1) > > NoMethodError in 'Requesting /assets/1;edit using GET should render > > edit.rhtml' > > undefined method `render?' for > > # > > ./spec/controllers/user_assets_controller_spec.rb:201: > > > > and > > > > 5) > > NoMethodError in '/users/edit.rhtml should render edit form' > > undefined method `matches?' for # > > ./spec/views/users/edit_rhtml_spec.rb:21: > > > > I'm not too certain why it isn't seeing matches but I'll have to do more > > digging. > > > > I love caboo.se! > > > > > > > > > > On 5/26/07, Courtenay wrote: > > > Heh. The author is lazy and hasn't upgraded his sample apps to latest > > rspec. > > > Also, you didn't load the database schema; > > > > > > rake db:migrate > > > > > > Patches are, of course, always welcome. > > > > > > Courtenay (the lazy author) > > > http://blog.caboo.se > > > > > > > > > On 5/26/07, aslak hellesoy < aslak.hellesoy at gmail.com> wrote: > > > > The app you downloaded is not compatible with rspec 1.0. Please > > > > contact the app authors or upgrade it yourself. See upgrading on the > > > > rspec website. > > > > > > > > On 5/26/07, Omen King wrote: > > > > > So I can run rake spec. I've gotten errors and I not too sure what > I'm > > > > > looking at. > > > > > > > > > > Lets take a look at error 1: > > > > > =================================================== > > > > > specify "should render new" do > > > > > controller.should_render :new > > > > > get :new > > > > > end > > > > > > > > > > 1) > > > > > NoMethodError in '/session/new GET should render new' > > > > > undefined method `should_render' for > # > > > > > ./spec/controllers/session_controller_spec.rb:7: > > > > > =================================================== > > > > > Is it trying to called a method called 'should_render' for > > > > > session_controller of session_controller_spec? > > > > > > > > > > 2) > > > > > NameError in '/session POST without remember me should > authenticate > > user' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:15: > > > > > > > > > > 3) > > > > > NameError in '/session POST without remember me should login user' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:15: > > > > > > > > > > 4) > > > > > NameError in '/session POST without remember me should not > remember > > me' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:15: > > > > > > > > > > 5) > > > > > NameError in '/session POST without remember me should redirect to > > root' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:15: > > > > > > > > > > 6) > > > > > NameError in '/session POST with remember me should remember me' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:44: > > > > > > > > > > 7) > > > > > NameError in '/session POST with remember me should create cookie' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:44: > > > > > > > > > > 8) > > > > > NameError in '/session POST when invalid should authenticate user' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:72: > > > > > > > > > > 9) > > > > > NameError in '/session POST when invalid should login user' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:72: > > > > > > > > > > 10) > > > > > NameError in '/session POST when invalid should not remember me' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:72: > > > > > > > > > > 11) > > > > > NameError in '/session POST when invalid should render new' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:72: > > > > > > > > > > 12) > > > > > NameError in '/session DELETE should get current user' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:102: > > > > > > > > > > 13) > > > > > NameError in '/session DELETE should forget current user' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:102: > > > > > > > > > > 14) > > > > > NameError in '/session DELETE should delete token on logout' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:102: > > > > > > > > > > 15) > > > > > NameError in '/session DELETE should reset session' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:102: > > > > > > > > > > 16) > > > > > NameError in '/session DELETE should redirect to root' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/controllers/session_controller_spec.rb:102: > > > > > > > > > > 17) > > > > > NoMethodError in 'Requesting /assets using GET should render > > index.rhtml' > > > > > undefined method `should_render' for > > # > > > > > ./spec/controllers/user_assets_controller_spec.rb:25: > > > > > > > > > > 18) > > > > > NoMethodError in 'Requesting /assets/1 using GET should render > > show.rhtml' > > > > > undefined method `should_render' for > > # > > > > > ./spec/controllers/user_assets_controller_spec.rb:93: > > > > > > > > > > 19) > > > > > NoMethodError in 'Requesting /assets/new using GET should render > > new.rhtml' > > > > > undefined method `should_render' for > > # > > > > > > > ./spec/controllers/user_assets_controller_spec.rb:159: > > > > > > > > > > 20) > > > > > NoMethodError in 'Requesting /assets/1;edit using GET should > render > > > > > edit.rhtml' > > > > > undefined method `should_render' for > > # > > > > > > > ./spec/controllers/user_assets_controller_spec.rb:201: > > > > > > > > > > 21) > > > > > NoMethodError in 'Requesting /users using GET should render > > index.rhtml' > > > > > undefined method `should_render' for # > > > > > ./spec/controllers/users_controller_spec.rb:49: > > > > > > > > > > 22) > > > > > NoMethodError in 'Requesting /users/1 using GET should render > > show.rhtml' > > > > > undefined method `should_render' for # > > > > > ./spec/controllers/users_controller_spec.rb:112: > > > > > > > > > > 23) > > > > > NoMethodError in 'Requesting /users/new using GET should render > > new.rhtml' > > > > > undefined method `should_render' for # > > > > > ./spec/controllers/users_controller_spec.rb:175: > > > > > > > > > > 24) > > > > > ActiveRecord::StatementInvalid in 'Requesting /users/1;edit using > GET > > should > > > > > fail if current user doesn't match' > > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > > FIELDS > > > > > FROM users > > > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > > `log' > > > > > ./spec/controllers/users_controller_spec.rb:209:in > > `new' > > > > > ./spec/controllers/users_controller_spec.rb:209: > > > > > > > > > > 25) > > > > > NoMethodError in 'Requesting /users/1;edit using GET should render > > > > > edit.rhtml' > > > > > undefined method `should_render' for # > > > > > ./spec/controllers/users_controller_spec.rb:221: > > > > > > > > > > 26) > > > > > NoMethodError in 'the UserAssetsHelper should return user login > name' > > > > > undefined method `should_eql' for "JoeLogin":String > > > > > ./spec/helpers/user_assets_helper_spec.rb:11: > > > > > > > > > > 27) > > > > > NameError in 'the generated url helpers for UserAssetsController > > should > > > > > return assets path given no arguments' > > > > > undefined local variable or method `controller' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > (eval):2:in `assets_path' > > > > > ./spec/helpers/user_assets_url_helpers_spec.rb:24: > > > > > > > > > > 28) > > > > > NameError in 'the generated url helpers for UserAssetsController > > should > > > > > return assets path given explicit argument' > > > > > undefined local variable or method `controller' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > (eval):2:in `assets_path' > > > > > ./spec/helpers/user_assets_url_helpers_spec.rb:28: > > > > > > > > > > 29) > > > > > NameError in 'the generated url helpers for UserAssetsController > > should > > > > > return asset path' > > > > > undefined local variable or method `controller' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > (eval):2:in `asset_path' > > > > > ./spec/helpers/user_assets_url_helpers_spec.rb:32: > > > > > > > > > > 30) > > > > > NameError in 'the generated url helpers for UserAssetsController > > should > > > > > return edit_asset path' > > > > > undefined local variable or method `controller' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > (eval):2:in `edit_asset_path' > > > > > ./spec/helpers/user_assets_url_helpers_spec.rb:36: > > > > > > > > > > 31) > > > > > NameError in 'the generated url helpers for UserAssetsController > > should > > > > > return new_asset path' > > > > > undefined local variable or method `controller' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > (eval):2:in `new_asset_path' > > > > > ./spec/helpers/user_assets_url_helpers_spec.rb:40: > > > > > > > > > > 32) > > > > > NameError in 'the generated url helpers for UserAssetsController > > should > > > > > return asset_attachable path' > > > > > undefined local variable or method `controller' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > (eval):2:in `asset_attachable_path' > > > > > ./spec/helpers/user_assets_url_helpers_spec.rb:44: > > > > > > > > > > 33) > > > > > ActiveRecord::StatementInvalid in 'Given a generated asset_spec.rb > > with > > > > > fixtures loaded fixtures should load two Assets' > > > > > ActiveRecord::StatementInvalid: Mysql::Error: #42S02Table > > > > > 'sample_test.assets' doesn't exist: DELETE FROM assets: DELETE > FROM > > assets > > > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > > `log' > > > > > > > > /Users/multimedia/Desktop/rest_org/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/model.rb:12:in > > > > > `before_eval' > > > > > > > > > > 34) > > > > > ActiveRecord::StatementInvalid in 'A User abstract class should > have > > valid > > > > > associations' > > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > > FIELDS > > > > > FROM users > > > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > > `log' > > > > > ./spec/models/authenticated_base_spec.rb:7:in `new' > > > > > ./spec/models/authenticated_base_spec.rb:7: > > > > > > > > > > 35) > > > > > ActiveRecord::StatementInvalid in 'An existing user should > > authenticate with > > > > > new or reset password' > > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > > FIELDS > > > > > FROM users > > > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > > `log' > > > > > ./spec/models/authenticated_base_spec.rb:14: > > > > > > > > > > 36) > > > > > ActiveRecord::StatementInvalid in 'An existing user should not > rehash > > > > > password on login change' > > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > > FIELDS > > > > > FROM users > > > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > > `log' > > > > > ./spec/models/authenticated_base_spec.rb:14: > > > > > > > > > > 37) > > > > > ActiveRecord::StatementInvalid in 'An existing user should > remember > > token' > > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > > FIELDS > > > > > FROM users > > > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > > `log' > > > > > ./spec/models/authenticated_base_spec.rb:14: > > > > > > > > > > 38) > > > > > ActiveRecord::StatementInvalid in 'An existing user should > increment > > hit > > > > > counter' > > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > > FIELDS > > > > > FROM users > > > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > > `log' > > > > > ./spec/models/authenticated_base_spec.rb:14: > > > > > > > > > > 39) > > > > > ActiveRecord::StatementInvalid in 'An existing user should forget > > token' > > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > > FIELDS > > > > > FROM users > > > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > > `log' > > > > > ./spec/models/authenticated_base_spec.rb:14: > > > > > > > > > > 40) > > > > > ActiveRecord::StatementInvalid in 'An existing user should be > > remembered for > > > > > a period' > > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > > FIELDS > > > > > FROM users > > > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > > `log' > > > > > ./spec/models/authenticated_base_spec.rb:14: > > > > > > > > > > 41) > > > > > NoMethodError in 'A new user should create' > > > > > undefined method `should_change' for > > > > > > > # > > > > > ./spec/models/authenticated_base_spec.rb:59: > > > > > > > > > > 42) > > > > > NoMethodError in 'A new user should require login' > > > > > undefined method `should_not_change' for > > > > > > > # > > > > > ./spec/models/authenticated_base_spec.rb:63: > > > > > > > > > > 43) > > > > > NoMethodError in 'A new user should require password' > > > > > undefined method `should_not_change' for > > > > > > > # > > > > > ./spec/models/authenticated_base_spec.rb:68: > > > > > > > > > > 44) > > > > > NoMethodError in 'A new user should require password confirmation' > > > > > undefined method `should_not_change' for > > > > > > > # > > > > > ./spec/models/authenticated_base_spec.rb:73: > > > > > > > > > > 45) > > > > > NoMethodError in 'A new user should require email' > > > > > undefined method `should_not_change' for > > > > > > > # > > > > > ./spec/models/authenticated_base_spec.rb:78: > > > > > > > > > > 46) > > > > > ActiveRecord::StatementInvalid in 'A User should have valid > > associations' > > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > > FIELDS > > > > > FROM users > > > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > > `log' > > > > > ./spec/models/user_spec.rb:7:in `new' > > > > > ./spec/models/user_spec.rb:7: > > > > > > > > > > 47) > > > > > ActiveRecord::StatementInvalid in 'A User should protect against > > updates to > > > > > secure attributes' > > > > > Mysql::Error: #42S02Table 'sample_test.users' doesn't exist: SHOW > > FIELDS > > > > > FROM users > > > > > > > /Users/multimedia/Desktop/rest_org/config/../lib/ar_extensions.rb:27:in > > > > > `log' > > > > > ./spec/models/user_spec.rb:7:in `new' > > > > > ./spec/models/user_spec.rb:7: > > > > > > > > > > 48) > > > > > NoMethodError in '/assets/edit.rhtml should render edit form' > > > > > undefined method `should_have_tag' for > > > > > # > > > > > ./spec/views/assets/edit_rhtml_spec.rb:36: > > > > > > > > > > 49) > > > > > NoMethodError in '/assets/index.rhtml should render list of > assets' > > > > > undefined method `should_have_tag' for > > > > > # > > > > > ./spec/views/assets/index_rhtml_spec.rb:49: > > > > > > > > > > 50) > > > > > NoMethodError in '/assets/new.rhtml should render new form' > > > > > undefined method `should_have_tag' for > > > > > # > > > > > ./spec/views/assets/new_rhtml_spec.rb:39: > > > > > > > > > > 51) > > > > > NoMethodError in '/users/edit.rhtml should render edit form' > > > > > undefined method `should_have_tag' for > > > > > # > > > > > ./spec/views/users/edit_rhtml_spec.rb:21: > > > > > > > > > > 52) > > > > > NameError in '/users/new.rhtml should render new form' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/views/users/new_rhtml_spec.rb:10: > > > > > > > > > > 53) > > > > > NameError in '/users/show.rhtml should render attributes in

' > > > > > undefined local variable or method `mock_user' for [Dynamically > > generated > > > > > class for RSpec example]:# > > > > > ./spec/views/users/show_rhtml_spec.rb:7: > > > > > > > > > > Finished in 2.492637 seconds > > > > > > > > > > 117 examples, 53 failures > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070612/fd8a4565/attachment-0001.html From cwdinfo at gmail.com Tue Jun 12 21:10:07 2007 From: cwdinfo at gmail.com (s.ross) Date: Tue, 12 Jun 2007 18:10:07 -0700 Subject: [rspec-users] rSpec'ing Plugins In-Reply-To: References: <1181419529.16605.136.camel@localhost> <1181429027.16605.147.camel@localhost> Message-ID: <4385F002-AE76-4781-B864-B857D2F39287@gmail.com> I'm refactoring some of my code into a plugin and while it passes the base specs (as though it were part of the Rails app), I'd prefer that the plugin's specs live in the vendor/plugins/myplugin directory. Here's where I'm getting stuck. The plugin is MVC so instead of touching one part of Rails, it relies on several (model, view, controller) to work. That means to spec it requires rspec_on_rails. So, my questions are: 1. Is anyone doing this? 2. Was it worth the effort or is Test::Unit easier for this kind of thing? I'd be happy if I could even get a model spec to pass, but I keep getting version mismatches between spec and rspec_on_rails even though I've done fresh gem install and plugin installs. Any thoughts appreciated. I'd far prefer to use only rSpec on this project. Thanks From edward.og at gmail.com Tue Jun 12 21:23:27 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Tue, 12 Jun 2007 21:23:27 -0400 Subject: [rspec-users] standard location for spec helpers Message-ID: <466F470F.2000900@gmail.com> Is there a standard location for spec helpers (as in bits of code that help write specs)? I'm mocking/stubing-out portions of ActiveSalesforce, a remote-database abstraction layer so my specs won't have to rely on a remote connection, but I'm not sure where I should be putting this helper lib. I was thinking of just sticking it in spec/ but I was curious if there's a standard place for it. Thanks! From luislavena at gmail.com Tue Jun 12 21:23:44 2007 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 12 Jun 2007 22:23:44 -0300 Subject: [rspec-users] rSpec'ing Plugins In-Reply-To: <4385F002-AE76-4781-B864-B857D2F39287@gmail.com> References: <1181419529.16605.136.camel@localhost> <1181429027.16605.147.camel@localhost> <4385F002-AE76-4781-B864-B857D2F39287@gmail.com> Message-ID: <71166b3b0706121823m22686dcegab6ab06cc9c61b40@mail.gmail.com> On 6/12/07, s.ross wrote: > I'm refactoring some of my code into a plugin and while it passes the > base specs (as though it were part of the Rails app), I'd prefer that > the plugin's specs live in the vendor/plugins/myplugin directory. > > Here's where I'm getting stuck. The plugin is MVC so instead of > touching one part of Rails, it relies on several (model, view, > controller) to work. That means to spec it requires rspec_on_rails. > So, my questions are: > > 1. Is anyone doing this? Yes, at least the M with plugins playing with Models. I just created a spec folder, a spec_helper.rb inside of it and some Fixtured Models, Database schema. I used that approach to pluginize some code of one application. Specs inside the plugin will be independent of models located in your application, so: app/models/user.rb will not clash with #{my_plugin}/spec/fixtures/models/user.rb in that way, I isolate the plugin functionality and his behavior. This is the pastie for my spec_helper inside plugin/spec folder: http://pastie.caboo.se/69984 > 2. Was it worth the effort or is Test::Unit easier for this kind of > thing? > > I'd be happy if I could even get a model spec to pass, but I keep > getting version mismatches between spec and rspec_on_rails even > though I've done fresh gem install and plugin installs. > I don't know about that, I'm stuck at 0.9.4 gem + plugins until migrate some of these applications. > Any thoughts appreciated. I'd far prefer to use only rSpec on this > project. -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi From pergesu at gmail.com Tue Jun 12 21:24:49 2007 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 12 Jun 2007 19:24:49 -0600 Subject: [rspec-users] rSpec'ing Plugins In-Reply-To: <4385F002-AE76-4781-B864-B857D2F39287@gmail.com> References: <1181419529.16605.136.camel@localhost> <1181429027.16605.147.camel@localhost> <4385F002-AE76-4781-B864-B857D2F39287@gmail.com> Message-ID: <810a540e0706121824p2ba08334t46a2bbdb082cf9e@mail.gmail.com> On 6/12/07, s.ross wrote: > I'm refactoring some of my code into a plugin and while it passes the > base specs (as though it were part of the Rails app), I'd prefer that > the plugin's specs live in the vendor/plugins/myplugin directory. > > Here's where I'm getting stuck. The plugin is MVC so instead of > touching one part of Rails, it relies on several (model, view, > controller) to work. That means to spec it requires rspec_on_rails. > So, my questions are: > > 1. Is anyone doing this? > 2. Was it worth the effort or is Test::Unit easier for this kind of > thing? > > I'd be happy if I could even get a model spec to pass, but I keep > getting version mismatches between spec and rspec_on_rails even > though I've done fresh gem install and plugin installs. > > Any thoughts appreciated. I'd far prefer to use only rSpec on this > project. > > Thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > You might want to check out the rspec_plugin generator - http://agilewebdevelopment.com/plugins/rspec_plugin Pat From pergesu at gmail.com Tue Jun 12 21:28:27 2007 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 12 Jun 2007 19:28:27 -0600 Subject: [rspec-users] standard location for spec helpers In-Reply-To: <466F470F.2000900@gmail.com> References: <466F470F.2000900@gmail.com> Message-ID: <810a540e0706121828v3112519i3a492d37909aa008@mail.gmail.com> On 6/12/07, Edward Ocampo-Gooding wrote: > Is there a standard location for spec helpers (as in bits of code that help > write specs)? > > I'm mocking/stubing-out portions of ActiveSalesforce, a remote-database > abstraction layer so my specs won't have to rely on a remote connection, but I'm > not sure where I should be putting this helper lib. I was thinking of just > sticking it in spec/ but I was curious if there's a standard place for it. > > Thanks! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I created a spec/lib dir and throw my spec helper files in there. Then I require them in spec_helper.rb Pat From cwdinfo at gmail.com Tue Jun 12 21:29:35 2007 From: cwdinfo at gmail.com (s.ross) Date: Tue, 12 Jun 2007 18:29:35 -0700 Subject: [rspec-users] rSpec'ing Plugins In-Reply-To: <71166b3b0706121823m22686dcegab6ab06cc9c61b40@mail.gmail.com> References: <1181419529.16605.136.camel@localhost> <1181429027.16605.147.camel@localhost> <4385F002-AE76-4781-B864-B857D2F39287@gmail.com> <71166b3b0706121823m22686dcegab6ab06cc9c61b40@mail.gmail.com> Message-ID: Thanks, this is a great starting point. Steve On Jun 12, 2007, at 6:23 PM, Luis Lavena wrote: > On 6/12/07, s.ross wrote: >> I'm refactoring some of my code into a plugin and while it passes the >> base specs (as though it were part of the Rails app), I'd prefer that >> the plugin's specs live in the vendor/plugins/myplugin directory. >> >> Here's where I'm getting stuck. The plugin is MVC so instead of >> touching one part of Rails, it relies on several (model, view, >> controller) to work. That means to spec it requires rspec_on_rails. >> So, my questions are: >> >> 1. Is anyone doing this? > > Yes, at least the M with plugins playing with Models. > > I just created a spec folder, a spec_helper.rb inside of it and some > Fixtured Models, Database schema. > > I used that approach to pluginize some code of one application. > > Specs inside the plugin will be independent of models located in your > application, so: > > app/models/user.rb will not clash with #{my_plugin}/spec/fixtures/ > models/user.rb > > in that way, I isolate the plugin functionality and his behavior. > > This is the pastie for my spec_helper inside plugin/spec folder: > > http://pastie.caboo.se/69984 > > >> 2. Was it worth the effort or is Test::Unit easier for this kind of >> thing? >> >> I'd be happy if I could even get a model spec to pass, but I keep >> getting version mismatches between spec and rspec_on_rails even >> though I've done fresh gem install and plugin installs. >> > > I don't know about that, I'm stuck at 0.9.4 gem + plugins until > migrate some of these applications. > >> Any thoughts appreciated. I'd far prefer to use only rSpec on this >> project. > > -- > Luis Lavena > Multimedia systems > - > Leaders are made, they are not born. They are made by hard effort, > which is the price which all of us must pay to achieve any goal that > is worthwhile. > Vince Lombardi > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Steve Ross sross at calicowebdev.com http://www.calicowebdev.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070612/4a503c1f/attachment.html From dchelimsky at gmail.com Tue Jun 12 21:31:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 12 Jun 2007 20:31:40 -0500 Subject: [rspec-users] standard location for spec helpers In-Reply-To: <810a540e0706121828v3112519i3a492d37909aa008@mail.gmail.com> References: <466F470F.2000900@gmail.com> <810a540e0706121828v3112519i3a492d37909aa008@mail.gmail.com> Message-ID: <57c63afe0706121831s6766a9c7p79bcf6a34539d091@mail.gmail.com> On 6/12/07, Pat Maddox wrote: > On 6/12/07, Edward Ocampo-Gooding wrote: > > Is there a standard location for spec helpers (as in bits of code that help > > write specs)? > > > > I'm mocking/stubing-out portions of ActiveSalesforce, a remote-database > > abstraction layer so my specs won't have to rely on a remote connection, but I'm > > not sure where I should be putting this helper lib. I was thinking of just > > sticking it in spec/ but I was curious if there's a standard place for it. > > > > Thanks! > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > I created a spec/lib dir and throw my spec helper files in there. > Then I require them in spec_helper.rb FYI - From some other threads on this list, there seems to be an emerging convention that spec/lib is where specs for stuff in the lib directory go and shared stuff (helpers, shared behaviours, etc) go in spec/shared. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From edward.og at gmail.com Tue Jun 12 21:33:27 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Tue, 12 Jun 2007 21:33:27 -0400 Subject: [rspec-users] standard location for spec helpers In-Reply-To: <57c63afe0706121831s6766a9c7p79bcf6a34539d091@mail.gmail.com> References: <466F470F.2000900@gmail.com> <810a540e0706121828v3112519i3a492d37909aa008@mail.gmail.com> <57c63afe0706121831s6766a9c7p79bcf6a34539d091@mail.gmail.com> Message-ID: <466F4967.4070805@gmail.com> > FYI - From some other threads on this list, there seems to be an > emerging convention that spec/lib is where specs for stuff in the lib > directory go and shared stuff (helpers, shared behaviours, etc) go in > spec/shared. Right on. Thanks guys! From mailing_lists at railsnewbie.com Wed Jun 13 15:13:56 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 13 Jun 2007 15:13:56 -0400 Subject: [rspec-users] Using Rcov with rspec_on_rails Message-ID: Running the defualt task which comes with rspec gives me the following: ======================================================= euclid% rake spec:rcov (in /Users/smtlaissezfaire/Sites/rails/changelog) ................................*..*..*...................*............. ................................... Finished in 5.751487 seconds 107 examples, 0 failures, 4 not implemented No file to analyze was found. All the files loaded by rcov matched one of the following expressions, and were thus ignored: [/\A\/opt\/local\/lib/, /\btc_[^.]*.rb/, /_test\.rb\z/, /\btest\//, /\bvendor\//, /\A\/opt\/local\/lib\/ruby\/gems\/1\.8\/gems\/rcov\-0\.8\.0\.2\/lib\/ rcov\/report\.rb\z/, /spec/, /\bvendor\//, /\bconfig\//, /\benvironment\//] You can solve this by doing one or more of the following: * rename the files not to be ignored so they don't match the above regexps * use --include-file to give a list of patterns for files not to be ignored * use --exclude-only to give the new list of regexps to match against * structure your code as follows: test/test_*.rb for the test cases lib/**/*.rb for the target source code whose coverage you want making sure that the test/test_*.rb files are loading from lib/, e.g. by using the -Ilib command-line argument, adding $:.unshift File.join(File.dirname(__FILE__), "..", "lib") to test/test_*.rb, or running rcov via a Rakefile (read the RDoc documentation or README.rake in the source distribution). ======================================================= Is there something obvious that I'm not doing? I have the latest rcov gem installed, as well as the rails_rcov gem installed. Thanks for the help, Scott From work at ashleymoran.me.uk Thu Jun 14 11:44:18 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 14 Jun 2007 16:44:18 +0100 Subject: [rspec-users] Can't run RSpec files in TextMate Message-ID: Hi Not sure if this is the place to ask this or not. I've upgraded to RSpec 1.0.5, installed the latest TextMate bundle, but whenever I do "Run Behaviour Descriptions in selected files/directories" I get this: /Users/ashleymoran/Library/Application Support/TextMate/Pristine Copy/ Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:18:in `run_files': private method `split' called for nil:NilClass (NoMethodError) from / tmp/temp_textmate.ii9VqG:4 If I try the "Run Behaviour Description" I get this: /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require': no such file to load -- cgi (MissingSourceFile) from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/ custom_require.rb:27:in `require' from /opt/local/lib/ruby/gems/1.8/ gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/ lib/active_support/dependencies.rb:342:in `new_constants_in' from / opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/ active_support/dependencies.rb:495:in `require' from /opt/local/lib/ ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb: 1 from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb: 32:in `gem_original_require' from /opt/local/lib/ruby/vendor_ruby/1.8/ rubygems/custom_require.rb:32:in `require' from /opt/local/lib/ruby/ gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb: 495:in `require' ... 34 levels... from /Users/ashleymoran/Library/ Application Support/TextMate/Pristine Copy/Bundles/RSpec.tmbundle/ Support/lib/spec_mate.rb:46:in `chdir' from /Users/ashleymoran/ Library/Application Support/TextMate/Pristine Copy/Bundles/ RSpec.tmbundle/Support/lib/spec_mate.rb:46:in `run' from /Users/ ashleymoran/Library/Application Support/TextMate/Pristine Copy/ Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:25:in `run_file' from /tmp/temp_textmate.f8ruvl:4 However, doing a "Run Focused Example" works fine! I've seen reports of similar problems but I can't figure out what's going on. Can anyone help? Thanks Ashley From work at ashleymoran.me.uk Thu Jun 14 12:09:42 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 14 Jun 2007 17:09:42 +0100 Subject: [rspec-users] Can't run RSpec files in TextMate In-Reply-To: References: Message-ID: Sorry I was just making noise - it's started working now. No idea why but I'm happy... Ashley On 14 Jun 2007, at 16:44, Ashley Moran wrote: > Hi > > Not sure if this is the place to ask this or not. I've upgraded to > RSpec 1.0.5, installed the latest TextMate bundle, but whenever I do > "Run Behaviour Descriptions in selected files/directories" I get this: > > /Users/ashleymoran/Library/Application Support/TextMate/Pristine Copy/ > Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:18:in `run_files': > private method `split' called for nil:NilClass (NoMethodError) from / > tmp/temp_textmate.ii9VqG:4 > > If I try the "Run Behaviour Description" I get this: > > /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in > `gem_original_require': no such file to load -- cgi > (MissingSourceFile) from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/ > custom_require.rb:27:in `require' from /opt/local/lib/ruby/gems/1.8/ > gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in > `require' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/ > lib/active_support/dependencies.rb:342:in `new_constants_in' from / > opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/ > active_support/dependencies.rb:495:in `require' from /opt/local/lib/ > ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb: > 1 from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb: > 32:in `gem_original_require' from /opt/local/lib/ruby/vendor_ruby/1.8/ > rubygems/custom_require.rb:32:in `require' from /opt/local/lib/ruby/ > gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb: > 495:in `require' ... 34 levels... from /Users/ashleymoran/Library/ > Application Support/TextMate/Pristine Copy/Bundles/RSpec.tmbundle/ > Support/lib/spec_mate.rb:46:in `chdir' from /Users/ashleymoran/ > Library/Application Support/TextMate/Pristine Copy/Bundles/ > RSpec.tmbundle/Support/lib/spec_mate.rb:46:in `run' from /Users/ > ashleymoran/Library/Application Support/TextMate/Pristine Copy/ > Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:25:in `run_file' > from /tmp/temp_textmate.f8ruvl:4 > > However, doing a "Run Focused Example" works fine! > > I've seen reports of similar problems but I can't figure out what's > going on. Can anyone help? > > Thanks > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From joshknowles at gmail.com Thu Jun 14 13:04:40 2007 From: joshknowles at gmail.com (Josh Knowles) Date: Thu, 14 Jun 2007 10:04:40 -0700 Subject: [rspec-users] Can't run RSpec files in TextMate In-Reply-To: References: Message-ID: On 6/14/07, Ashley Moran wrote: > > Hi > > Not sure if this is the place to ask this or not. I've upgraded to > RSpec 1.0.5, installed the latest TextMate bundle, but whenever I do > "Run Behaviour Descriptions in selected files/directories" I get this: > > /Users/ashleymoran/Library/Application Support/TextMate/Pristine Copy/ > Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:18:in `run_files': > private method `split' called for nil:NilClass (NoMethodError) from / > tmp/temp_textmate.ii9VqG:4 I haven't had time to debug yet, but wanted to throw out that I'm seeing this same behavior when running some files consistently, but only appears on other files intermittently. -- Josh Knowles joshknowles at gmail.com http://joshknowles.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070614/63ac57be/attachment.html From ingo at ingoweiss.com Thu Jun 14 13:27:46 2007 From: ingo at ingoweiss.com (Ingo Weiss) Date: Thu, 14 Jun 2007 13:27:46 -0400 Subject: [rspec-users] Can't run RSpec files in TextMate In-Reply-To: References: Message-ID: <4927516B-0FA8-41F6-9F01-0E49AD573457@ingoweiss.com> Great it works for you! However I still get this when I run 'Run Behaviour Description': /Library/Application Support/TextMate/Bundles/RSpec.tmbundle/Support/ lib/spec_mate.rb:2:in `require': No such file to load -- rubygems (LoadError) from /Library/Application Support/TextMate/Bundles/ RSpec.tmbundle/Support/lib/spec_mate.rb:2 from /tmp/ temp_textmate.CCT9dt:3:in `require' from /tmp/temp_textmate.CCT9dt:3 Ingo On Jun 14, 2007, at 12:09 PM, Ashley Moran wrote: > Sorry I was just making noise - it's started working now. No idea > why but I'm happy... > > Ashley > > > On 14 Jun 2007, at 16:44, Ashley Moran wrote: > >> Hi >> >> Not sure if this is the place to ask this or not. I've upgraded to >> RSpec 1.0.5, installed the latest TextMate bundle, but whenever I do >> "Run Behaviour Descriptions in selected files/directories" I get >> this: >> >> /Users/ashleymoran/Library/Application Support/TextMate/Pristine >> Copy/ >> Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:18:in `run_files': >> private method `split' called for nil:NilClass (NoMethodError) from / >> tmp/temp_textmate.ii9VqG:4 >> >> If I try the "Run Behaviour Description" I get this: >> >> /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in >> `gem_original_require': no such file to load -- cgi >> (MissingSourceFile) from /opt/local/lib/ruby/vendor_ruby/1.8/ >> rubygems/ >> custom_require.rb:27:in `require' from /opt/local/lib/ruby/gems/1.8/ >> gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in >> `require' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/ >> lib/active_support/dependencies.rb:342:in `new_constants_in' from / >> opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/ >> active_support/dependencies.rb:495:in `require' from /opt/local/lib/ >> ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ >> routing.rb: >> 1 from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/ >> custom_require.rb: >> 32:in `gem_original_require' from /opt/local/lib/ruby/vendor_ruby/ >> 1.8/ >> rubygems/custom_require.rb:32:in `require' from /opt/local/lib/ruby/ >> gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb: >> 495:in `require' ... 34 levels... from /Users/ashleymoran/Library/ >> Application Support/TextMate/Pristine Copy/Bundles/RSpec.tmbundle/ >> Support/lib/spec_mate.rb:46:in `chdir' from /Users/ashleymoran/ >> Library/Application Support/TextMate/Pristine Copy/Bundles/ >> RSpec.tmbundle/Support/lib/spec_mate.rb:46:in `run' from /Users/ >> ashleymoran/Library/Application Support/TextMate/Pristine Copy/ >> Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:25:in `run_file' >> from /tmp/temp_textmate.f8ruvl:4 >> >> However, doing a "Run Focused Example" works fine! >> >> I've seen reports of similar problems but I can't figure out what's >> going on. Can anyone help? >> >> Thanks >> Ashley >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From omen.king at gmail.com Thu Jun 14 15:30:42 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Thu, 14 Jun 2007 15:30:42 -0400 Subject: [rspec-users] rspec will_paginate Message-ID: Hi Rspec-Users, I'm not sure if I am correctly specing my index since I'm using will_paginate. params[:filter_by] will filter the paginate list accordingly. Tickets Controller: def index @tickets = Ticket.filter_status_by(params[:filter_by],params[:page]) end Ticket Model: def self.filter_status_by(status, page, per_page = 10) conditions = {:status => false} if status == "unsolved" conditions = {:status => true} if status == "solved" return Ticket.paginate(:page => page, :per_page => per_page, :conditions => conditions) end describe TicketsController, "handling GET /tickets" do before do @tickets = mock_model(Ticket) Ticket.stub!(:find).and_return([@ticket]) end def do_get get :index end it "should be successful" do do_get response.should be_success end it "should render index template" do do_get response.should render_template('index') end it "should find all pagniated tickets" do @tickets = Ticket.paginate :per_page => 10 Ticket.should_receive(:filter_status_by).with(nil,nil).and_return(@tickets) do_get end it "should find solved pagniated tickets" do @tickets = Ticket.paginate :per_page => 10, :conditions => {:status => true} Ticket.should_receive(:filter_status_by).with('solved',nil).and_return(@tickets) get :index, :filter_by => 'solved' end it "should find unsolved pagniated tickets" do @tickets = Ticket.paginate :per_page => 10, :conditions => {:status => false} Ticket.should_receive(:filter_status_by).with('unsolved',nil).and_return(@tickets) get :index, :filter_by => 'unsolved' end it "should assign the found tickets for the view" do do_get assigns[:tickets].should == [@tickets] end end 1) 'TicketsController handling GET /tickets should assign the found tickets for the view' FAILED expected [#], got [nil] (using ==) ./spec/controllers/tickets_controller_spec.rb:71: script/spec:4: Finished in 0.207992 seconds 13 examples, 1 failure Any suggestions or criticisms about my rspec? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070614/e421636a/attachment.html From ingo at ingoweiss.com Thu Jun 14 16:43:01 2007 From: ingo at ingoweiss.com (Ingo Weiss) Date: Thu, 14 Jun 2007 16:43:01 -0400 Subject: [rspec-users] problem getting started with stubbing in rails controller specs In-Reply-To: <4927516B-0FA8-41F6-9F01-0E49AD573457@ingoweiss.com> References: <4927516B-0FA8-41F6-9F01-0E49AD573457@ingoweiss.com> Message-ID: Hi, I am getting started with writing controller specs with rspec/rails, and seem to have trouble fully grasping the concept of mocks and stubs. I can't figure out what's wrong with the following. This is the action I want to spec: def index @stations = Station.find(:all, :order => 'name') end and this is my spec: describe "GET to index" do controller_name :stations before(:each) do @mock_station = mock_model(Station) @mock_stations = [@mock_station] Station.stub!(:find).and_return(@mock_stations) get 'index', :locale => 'en' end it "should find stations" do Station.should_receive(:find).with(:all).and_return (@mock_stations) end end It fails with this error: Spec::Mocks::MockExpectationError in 'GET to index should find stations' Station expected :find with (:all) once, but received it 0 times ./spec/controllers/stations_controller_spec.rb:22: I can see in the log that the database is not hit for Station.find (:all), so the stubbing seems to have worked. Guess I'm stuck. Thanks for any hint to get me going again! Ingo From dylanegan at gmail.com Thu Jun 14 17:57:33 2007 From: dylanegan at gmail.com (Dylan Egan) Date: Fri, 15 Jun 2007 07:57:33 +1000 Subject: [rspec-users] rspec will_paginate In-Reply-To: References: Message-ID: > before do > @tickets = mock_model(Ticket) > Ticket.stub!(:find).and_return([@ticket]) > end Try Ticket.stub!(:filter_status_by).and_return([@tickets]) From anthony at digitalphenom.com Thu Jun 14 20:48:52 2007 From: anthony at digitalphenom.com (Anthony Carlos) Date: Thu, 14 Jun 2007 20:48:52 -0400 Subject: [rspec-users] problem getting started with stubbing in rails controller specs Message-ID: <52BF9052-EC49-4E93-8084-E6C7928940EA@digitalphenom.com> Hello, Ingo! I'm copying your question to a new e-mail instead of replying to try to keep message threads separate. Have you tried setting up your expectation before issuing the get statement? For example, take this out of the setup block: get 'index', :locale => 'en' and move it after: Station.should_receive(:find).with(:all).and_return(@mock_stations) I set-up inter-object expectations before exercising the controller action. Does this help? -Anthony PS: If you could be more specific about which concepts about mocks and stubs are confusing you, I'd be happy to try and help.l ---------- Hi, I am getting started with writing controller specs with rspec/rails, and seem to have trouble fully grasping the concept of mocks and stubs. I can't figure out what's wrong with the following. This is the action I want to spec: def index @stations = Station.find(:all, :order => 'name') end and this is my spec: describe "GET to index" do controller_name :stations before(:each) do @mock_station = mock_model(Station) @mock_stations = [@mock_station] Station.stub!(:find).and_return(@mock_stations) get 'index', :locale => 'en' end it "should find stations" do Station.should_receive(:find).with(:all).and_return (@mock_stations) end end It fails with this error: Spec::Mocks::MockExpectationError in 'GET to index should find stations' Station expected :find with (:all) once, but received it 0 times ./spec/controllers/stations_controller_spec.rb:22: I can see in the log that the database is not hit for Station.find (:all), so the stubbing seems to have worked. Guess I'm stuck. Thanks for any hint to get me going again! Ingo _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users From work at ashleymoran.me.uk Fri Jun 15 05:53:18 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 15 Jun 2007 10:53:18 +0100 Subject: [rspec-users] Is it still possible to use should_have_rjs Message-ID: Hi I've come back to a Rails project after about a month doing other work, and there's a lot of changes. I was on the 0.7 branch before and I've upgraded to RSpec 1.0.5. I used the spec translator, fixed the cases where it barfed on unusual line contents, and all my model and controller specs now pass. But I'm getting 53 failures on my view specs, all along the lines of: should have visual effect Unknown RJS statement type effect /Users/ashleymoran/Documents/Development/YourMoney/trunk/src/spec/ views/admin/add_dealer_rjs_view_spec.rb:33 31 32 it "should have visual effect" do 33 response.should have_rjs(:effect, :blind_down, "add_dealer") 34 end 35 I'm trying to revert these to should_have_rjs but I've looked through the RSpec source and it seems should_have_rjs was silently removed between 0.8 and 0.9. At least I can't find any reference to it in the 0.9.4 source or the 1.0.5 source. Am I missing something? I really need should_have_rjs- those 53 failures represent about 20% of all my view specs. Thanks Ashley From port001 at gmail.com Fri Jun 15 07:03:38 2007 From: port001 at gmail.com (Ian Leitch) Date: Fri, 15 Jun 2007 12:03:38 +0100 Subject: [rspec-users] Problems with RCov and Rails Message-ID: Hey list, I'm trying to use the rcov integration that rspec provides in my Rails application. As per the documentation on the website, I've created the following rake task: lib/tasks/specs_with_rcov.rake: require 'spec/rake/spectask' desc "Run all specs with rcov" Spec::Rake::SpecTask.new('specs_with_rcov') do |t| t.rcov = true end However... $ rake specs_with_rcov (in /Users/ian/Projects/systino/trunk) rake aborted! superclass mismatch for class Annotation /Users/ian/Projects/systino/trunk/rakefile:10 (See full trace by running task with --trace) ======= $ rake specs_with_rcov --trace (in /Users/ian/Projects/systino/trunk) rake aborted! superclass mismatch for class Annotation /Users/ian/Projects/systino/trunk/vendor/rails/railties/lib/tasks/annotations.rake:2 /Users/ian/Projects/systino/trunk/vendor/rails/railties/lib/tasks/rails.rb:4:in `load' /Users/ian/Projects/systino/trunk/vendor/rails/railties/lib/tasks/rails.rb:4 /Users/ian/Projects/systino/trunk/vendor/rails/railties/lib/tasks/rails.rb:4:in `each' /Users/ian/Projects/systino/trunk/vendor/rails/railties/lib/tasks/rails.rb:4 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `gem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `require' /Users/ian/Projects/systino/trunk/rakefile:10 /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1940:in `load' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1940:in `raw_load_rakefile' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1727:in `load_rakefile' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1726:in `load_rakefile' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1710:in `run' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in `run' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/bin/rake:7 /usr/local/bin/rake:16:in `load' /usr/local/bin/rake:16 ======= The Annotation class inherits a Struct instance which I thought may be conflicting with a Struct class provided by RSpec, however it doesn't, nor does RSpec contain an Annotation class. I'm afraid this bug is beyond me. Has anyone else seen it? $ script/about About your application's environment Ruby version 1.8.6 (powerpc-darwin8.9.0) RubyGems version 0.9.4 Rails version 1.2.3 Active Record version 1.15.3 Action Pack version 1.13.3 Action Web Service version 1.2.3 Action Mailer version 1.3.3 Active Support version 1.4.2 Edge Rails revision 184 Application root /Users/ian/Projects/systino/trunk Environment development Database adapter mysql Database schema version 26 Cheers Ian From justnothing at tiscali.co.uk Fri Jun 15 07:34:27 2007 From: justnothing at tiscali.co.uk (David Green) Date: Fri, 15 Jun 2007 04:34:27 -0700 (PDT) Subject: [rspec-users] dynamic specs Message-ID: <11137640.post@talk.nabble.com> I'd like to test that my model attributes are properly protected against mass assignment, something like: it "should NOT update :balance on mass assignment" do @account.attributes = {:balance => 1000} @account.balance.should_not == 1000 end instead of doing each attribute manually however, I'd like to automate it so I can pass a list of attributes which CAN be assigned that way and let the code figure out what should be protected. Here's what I have so far : http://pastie.caboo.se/70685 the problem is, I can't figure out how to make "protected attributes" reusable. I'd like to be able to pass it a different class name and list of allowed attributes at run time, but AFAIK, shared behaviours can't be sent parameters. I tried using instance variables, which I initialize in 'mass assignments' before() method, but they're only available to the actual spec (lines 6-8), not the code that generates the dynamic specs (lines 3-9) can anyone think how I might get round this? thanks dave -- View this message in context: http://www.nabble.com/dynamic-specs-tf3927280.html#a11137640 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Fri Jun 15 07:42:05 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 15 Jun 2007 06:42:05 -0500 Subject: [rspec-users] Is it still possible to use should_have_rjs In-Reply-To: References: Message-ID: <57c63afe0706150442n14a8bfefxcf57aff2e39c2e2f@mail.gmail.com> On 6/15/07, Ashley Moran wrote: > Hi > > I've come back to a Rails project after about a month doing other > work, and there's a lot of changes. I was on the 0.7 branch before > and I've upgraded to RSpec 1.0.5. I used the spec translator, fixed > the cases where it barfed on unusual line contents, and all my model > and controller specs now pass. But I'm getting 53 failures on my view > specs, all along the lines of: > > should have visual effect > Unknown RJS statement type effect > /Users/ashleymoran/Documents/Development/YourMoney/trunk/src/spec/ > views/admin/add_dealer_rjs_view_spec.rb:33 > 31 > 32 it "should have visual effect" do > 33 response.should have_rjs(:effect, :blind_down, "add_dealer") > 34 end > 35 > > I'm trying to revert these to should_have_rjs but I've looked through > the RSpec source and it seems should_have_rjs was silently removed > between 0.8 and 0.9. At least I can't find any reference to it in > the 0.9.4 source or the 1.0.5 source. Am I missing something? You're not missing anything. I switched from a direct port of ARTS to wrapping assert_select_rjs in 0.9. Neither library covers the full breadth of rjs statements and I went w/ the wrapper because it meant that rspec would reap the benefits of improvements to assert_select_rjs. Sadly, it seems as though the only improvements to assert_select_rjs have been those that I've personally contributed to Rails, and they haven't covered every situation. As for your immediate problem, Spec::Rails provides access to Test::Unit assertions for free. I'd recommend that you install the ARTS plugin (from which should_have_rjs was ported) and use it directly as/is (assert_rjs) right in your examples. It won't be as pleasing syntactically, but at least it should work for you. http://glu.ttono.us/articles/2006/05/29/guide-test-driven-rjs-with-arts There are a couple of things that ARTS didn't cover that we had added to RSpec. Those you'll have to do manually with any of these: response.should have_text("full text of the response") response.should have_text(/regexp representing a substring of the response/) response.body.should == "full text of the response" response.body.should =~ /regexp representing a substring of the response/ In terms of a longer term solution for rspec, I'm open to suggestions. ARTS and assert_select_rjs both make assumptions about what options are available, which means they both need to be updated as new options appear. I had hoped that this would be maintained in rails, but it doesn't appear to be happening. We could resurrect ARTS in RSpec, but that would mean either coming up with a new matcher (include_rjs?) as not to break existing specs that use "should have_rjs.", and it would put more of a burden on Spec::Rails to keep up with additions to rjs. Other ideas? David > I > really need should_have_rjs- those 53 failures represent about 20% of > all my view specs. > > Thanks > Ashley > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jun 15 07:50:23 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 15 Jun 2007 06:50:23 -0500 Subject: [rspec-users] dynamic specs In-Reply-To: <11137640.post@talk.nabble.com> References: <11137640.post@talk.nabble.com> Message-ID: <57c63afe0706150450y40ee9710m5e8e273a5f9c0673@mail.gmail.com> On 6/15/07, David Green wrote: > > I'd like to test that my model attributes are properly protected against mass > assignment, something like: > > it "should NOT update :balance on mass assignment" do > @account.attributes = {:balance => 1000} > @account.balance.should_not == 1000 > end > > instead of doing each attribute manually however, I'd like to automate it so > I can pass a list of attributes which CAN be assigned that way and let the > code figure out what should be protected. Here's what I have so far : > > http://pastie.caboo.se/70685 > > the problem is, I can't figure out how to make "protected attributes" > reusable. I'd like to be able to pass it a different class name and list of > allowed attributes at run time, but AFAIK, shared behaviours can't be sent > parameters. I tried using instance variables, which I initialize in 'mass > assignments' before() method, but they're only available to the actual spec > (lines 6-8), not the code that generates the dynamic specs (lines 3-9) > > can anyone think how I might get round this? I can't think of a good way to do it with the existing tool-set, however it does bring up an interesting idea. Check this out and let me know what you think: http://pastie.caboo.se/70700 It's not currently supported, but it solves the problem of parameterizing shared behaviours a bit more explicitly than the current magic of setting instance variables in before(:each). WDYT? > > thanks > dave > > > -- > View this message in context: http://www.nabble.com/dynamic-specs-tf3927280.html#a11137640 > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jun 15 08:11:36 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 15 Jun 2007 07:11:36 -0500 Subject: [rspec-users] dynamic specs In-Reply-To: <57c63afe0706150450y40ee9710m5e8e273a5f9c0673@mail.gmail.com> References: <11137640.post@talk.nabble.com> <57c63afe0706150450y40ee9710m5e8e273a5f9c0673@mail.gmail.com> Message-ID: <57c63afe0706150511t72badbb8hc00e61b28d51c129@mail.gmail.com> On 6/15/07, David Chelimsky wrote: > On 6/15/07, David Green wrote: > > > > I'd like to test that my model attributes are properly protected against mass > > assignment, something like: > > > > it "should NOT update :balance on mass assignment" do > > @account.attributes = {:balance => 1000} > > @account.balance.should_not == 1000 > > end > > > > instead of doing each attribute manually however, I'd like to automate it so > > I can pass a list of attributes which CAN be assigned that way and let the > > code figure out what should be protected. Here's what I have so far : > > > > http://pastie.caboo.se/70685 > > > > the problem is, I can't figure out how to make "protected attributes" > > reusable. I'd like to be able to pass it a different class name and list of > > allowed attributes at run time, but AFAIK, shared behaviours can't be sent > > parameters. I tried using instance variables, which I initialize in 'mass > > assignments' before() method, but they're only available to the actual spec > > (lines 6-8), not the code that generates the dynamic specs (lines 3-9) > > > > can anyone think how I might get round this? > > I can't think of a good way to do it with the existing tool-set, > however it does bring up an interesting idea. Check this out and let > me know what you think: > > http://pastie.caboo.se/70700 > > It's not currently supported, but it solves the problem of > parameterizing shared behaviours a bit more explicitly than the > current magic of setting instance variables in before(:each). Actually, looking at implementing this, it would require a complete redesign of shared behaviours, and I don't see that happening any time soon. > > WDYT? > > > > > thanks > > dave > > > > > > -- > > View this message in context: http://www.nabble.com/dynamic-specs-tf3927280.html#a11137640 > > Sent from the rspec-users mailing list archive at Nabble.com. > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From justnothing at tiscali.co.uk Fri Jun 15 09:08:21 2007 From: justnothing at tiscali.co.uk (David Green) Date: Fri, 15 Jun 2007 06:08:21 -0700 (PDT) Subject: [rspec-users] dynamic specs In-Reply-To: <57c63afe0706150511t72badbb8hc00e61b28d51c129@mail.gmail.com> References: <11137640.post@talk.nabble.com> <57c63afe0706150450y40ee9710m5e8e273a5f9c0673@mail.gmail.com> <57c63afe0706150511t72badbb8hc00e61b28d51c129@mail.gmail.com> Message-ID: <11139116.post@talk.nabble.com> David Chelimsky-2 wrote: > >> >> I can't think of a good way to do it with the existing tool-set, >> however it does bring up an interesting idea. Check this out and let >> me know what you think: >> >> http://pastie.caboo.se/70700 >> >> It's not currently supported, but it solves the problem of >> parameterizing shared behaviours a bit more explicitly than the >> current magic of setting instance variables in before(:each). > > Actually, looking at implementing this, it would require a complete > redesign of shared behaviours, and I don't see that happening any time > soon. > >> >> WDYT? >> > shame. that would have been perfect. I'd have a go at it myself but don't think my programming quite up to standard (yet). Thanks anyway -- View this message in context: http://www.nabble.com/dynamic-specs-tf3927280.html#a11139116 Sent from the rspec-users mailing list archive at Nabble.com. From work at ashleymoran.me.uk Fri Jun 15 11:55:25 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 15 Jun 2007 16:55:25 +0100 Subject: [rspec-users] Is it still possible to use should_have_rjs In-Reply-To: <57c63afe0706150442n14a8bfefxcf57aff2e39c2e2f@mail.gmail.com> References: <57c63afe0706150442n14a8bfefxcf57aff2e39c2e2f@mail.gmail.com> Message-ID: On 15 Jun 2007, at 12:42, David Chelimsky wrote: > You're not missing anything. I switched from a direct port of ARTS to > wrapping assert_select_rjs in 0.9. Neither library covers the full > breadth of rjs statements and I went w/ the wrapper because it meant > that rspec would reap the benefits of improvements to > assert_select_rjs. Sadly, it seems as though the only improvements to > assert_select_rjs have been those that I've personally contributed to > Rails, and they haven't covered every situation. Hmm, surely RJS testing is a pretty essential part of Rails, seeing how everyone's going Web2.0-crazy? I'm surprised assert_select_rjs doesn't cover everything. > As for your immediate problem, Spec::Rails provides access to > Test::Unit assertions for free. I'd recommend that you install the > ARTS plugin (from which should_have_rjs was ported) and use it > directly as/is (assert_rjs) right in your examples. It won't be as > pleasing syntactically, but at least it should work for you. > > http://glu.ttono.us/articles/2006/05/29/guide-test-driven-rjs-with- > arts Thanks for the link. I tried this: describe "A rendered add_dealer view" do before(:each) do render 'admin/add_dealer' end it "should have visual effect" do assert_rjs(:effect, :blind_down, "add_dealer") end end But it doesn't work: should have visual effect ActionView::Helpers::JavaScriptProxy#to_str should return String /Users/ashleymoran/Documents/Development/YourMoney/trunk/src/ config/../vendor/plugins/arts/lib/arts.rb:98 :in `index' /Users/ashleymoran/Documents/Development/YourMoney/trunk/src/ config/../vendor/plugins/arts/lib/arts.rb:98 :in `assert_response_contains' /Users/ashleymoran/Documents/Development/YourMoney/trunk/src/ config/../vendor/plugins/arts/lib/arts.rb:12 :in `assert_rjs' ./spec/views/admin/add_dealer_rjs_view_spec.rb:33 96 97 def assert_response_contains(str, message) 98 assert @response.body.to_s.index(str), message 99 end 100 My naive attempt to fix it... module ActionView module Helpers class JavaScriptProxy def to_str to_s end end end end achieves nothing. (Probably because it's completely wrong.) Any ideas on this one? > There are a couple of things that ARTS didn't cover that we had added > to RSpec. Those you'll have to do manually with any of these: > > response.should have_text("full text of the response") > response.should have_text(/regexp representing a substring of the > response/) > response.body.should == "full text of the response" > response.body.should =~ /regexp representing a substring of the > response/ > > In terms of a longer term solution for rspec, I'm open to suggestions. > ARTS and assert_select_rjs both make assumptions about what options > are available, which means they both need to be updated as new options > appear. I had hoped that this would be maintained in rails, but it > doesn't appear to be happening. Hmm, surely a framework feature without a means to test it is next to useless? Or maybe I am being a too demanding (I'm known for it). > We could resurrect ARTS in RSpec, but that would mean either coming up > with a new matcher (include_rjs?) as not to break existing specs that > use "should have_rjs.", and it would put more of a burden on > Spec::Rails to keep up with additions to rjs. Is there any way to be clever with have_rjs and decide where to pass the request based on the type of match? That way you could use ARTS as a prop and migrate test support to assert_select_rjs as and when things as included? I haven't written any custom matchers yet - don't know much about the new style specs thanks to lack of time spent coding - so again I'm probably being naive. Ashley From ingo at ingoweiss.com Fri Jun 15 13:22:43 2007 From: ingo at ingoweiss.com (Ingo Weiss) Date: Fri, 15 Jun 2007 13:22:43 -0400 Subject: [rspec-users] problem getting started with stubbing in rails controller specs In-Reply-To: <52BF9052-EC49-4E93-8084-E6C7928940EA@digitalphenom.com> References: <52BF9052-EC49-4E93-8084-E6C7928940EA@digitalphenom.com> Message-ID: <6953B85F-9475-49B5-8CB6-7BDBBF5A5D45@ingoweiss.com> Ah, I see how it makes sense to do it in this order. However, the error does not go away when I state the expectation before issuing the request. I will keep investigating... Ingo On Jun 14, 2007, at 8:48 PM, Anthony Carlos wrote: > Hello, Ingo! > > I'm copying your question to a new e-mail instead of replying to try > to keep message threads separate. > > Have you tried setting up your expectation before issuing the get > statement? For example, take this out of the setup block: > get 'index', :locale => 'en' > > and move it after: > Station.should_receive(:find).with(:all).and_return(@mock_stations) > > I set-up inter-object expectations before exercising the controller > action. > > Does this help? > > -Anthony > > PS: If you could be more specific about which concepts about mocks > and stubs are confusing you, I'd be happy to try and help.l > > ---------- > > Hi, > > I am getting started with writing controller specs with rspec/rails, > and seem to have trouble fully grasping the concept of mocks and > stubs. I can't figure out what's wrong with the following. This is > the action I want to spec: > > def index > @stations = Station.find(:all, :order => 'name') > end > > and this is my spec: > > > describe "GET to index" do > controller_name :stations > > before(:each) do > @mock_station = mock_model(Station) > @mock_stations = [@mock_station] > Station.stub!(:find).and_return(@mock_stations) > get 'index', :locale => 'en' > end > > it "should find stations" do > Station.should_receive(:find).with(:all).and_return > (@mock_stations) > end > > end > > > It fails with this error: > > Spec::Mocks::MockExpectationError in 'GET to index should find > stations' > Station expected :find with (:all) once, but received it 0 times > ./spec/controllers/stations_controller_spec.rb:22: > > I can see in the log that the database is not hit for Station.find > (:all), so the stubbing seems to have worked. Guess I'm stuck. Thanks > for any hint to get me going again! > > Ingo > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From anthony at digitalphenom.com Fri Jun 15 14:46:08 2007 From: anthony at digitalphenom.com (Anthony Carlos) Date: Fri, 15 Jun 2007 14:46:08 -0400 Subject: [rspec-users] problem getting started with stubbing in rails controller specs In-Reply-To: <6953B85F-9475-49B5-8CB6-7BDBBF5A5D45@ingoweiss.com> References: <52BF9052-EC49-4E93-8084-E6C7928940EA@digitalphenom.com> <6953B85F-9475-49B5-8CB6-7BDBBF5A5D45@ingoweiss.com> Message-ID: Ingo: I cannot find any documentation on the :all parameter to the "with" clause. Can you try it without the "with" clause? Station.should_receive(:find).and_return(@mock_stations) See if it goes through and let me know what happens. -Anthony On Jun 15, 2007, at 1:22 PM, Ingo Weiss wrote: > Ah, I see how it makes sense to do it in this order. However, the > error does not go away when I state the expectation before issuing > the request. I will keep investigating... > > Ingo > > > On Jun 14, 2007, at 8:48 PM, Anthony Carlos wrote: > >> Hello, Ingo! >> >> I'm copying your question to a new e-mail instead of replying to try >> to keep message threads separate. >> >> Have you tried setting up your expectation before issuing the get >> statement? For example, take this out of the setup block: >> get 'index', :locale => 'en' >> >> and move it after: >> Station.should_receive(:find).with(:all).and_return(@mock_stations) >> >> I set-up inter-object expectations before exercising the controller >> action. >> >> Does this help? >> >> -Anthony >> >> PS: If you could be more specific about which concepts about mocks >> and stubs are confusing you, I'd be happy to try and help.l >> >> ---------- >> >> Hi, >> >> I am getting started with writing controller specs with rspec/rails, >> and seem to have trouble fully grasping the concept of mocks and >> stubs. I can't figure out what's wrong with the following. This is >> the action I want to spec: >> >> def index >> @stations = Station.find(:all, :order => 'name') >> end >> >> and this is my spec: >> >> >> describe "GET to index" do >> controller_name :stations >> >> before(:each) do >> @mock_station = mock_model(Station) >> @mock_stations = [@mock_station] >> Station.stub!(:find).and_return(@mock_stations) >> get 'index', :locale => 'en' >> end >> >> it "should find stations" do >> Station.should_receive(:find).with(:all).and_return >> (@mock_stations) >> end >> >> end >> >> >> It fails with this error: >> >> Spec::Mocks::MockExpectationError in 'GET to index should find >> stations' >> Station expected :find with (:all) once, but received it 0 times >> ./spec/controllers/stations_controller_spec.rb:22: >> >> I can see in the log that the database is not hit for Station.find >> (:all), so the stubbing seems to have worked. Guess I'm stuck. Thanks >> for any hint to get me going again! >> >> Ingo >> >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ingo at ingoweiss.com Fri Jun 15 14:53:20 2007 From: ingo at ingoweiss.com (Ingo Weiss) Date: Fri, 15 Jun 2007 14:53:20 -0400 Subject: [rspec-users] problem getting started with stubbing in rails controller specs In-Reply-To: References: <52BF9052-EC49-4E93-8084-E6C7928940EA@digitalphenom.com> <6953B85F-9475-49B5-8CB6-7BDBBF5A5D45@ingoweiss.com> Message-ID: Thanks so much, Anthony, this works! I thought that .with(:all) would set the expectation that 'find' is called with the :all parameter like this: Station.find(:all) but apparently that is not what's happening Ingo On Jun 15, 2007, at 2:46 PM, Anthony Carlos wrote: > Ingo: > > I cannot find any documentation on the :all parameter to the "with" > clause. Can you try it without the "with" clause? > > Station.should_receive(:find).and_return(@mock_stations) > > See if it goes through and let me know what happens. > > -Anthony > > > On Jun 15, 2007, at 1:22 PM, Ingo Weiss wrote: > >> Ah, I see how it makes sense to do it in this order. However, the >> error does not go away when I state the expectation before issuing >> the request. I will keep investigating... >> >> Ingo >> >> >> On Jun 14, 2007, at 8:48 PM, Anthony Carlos wrote: >> >>> Hello, Ingo! >>> >>> I'm copying your question to a new e-mail instead of replying to try >>> to keep message threads separate. >>> >>> Have you tried setting up your expectation before issuing the get >>> statement? For example, take this out of the setup block: >>> get 'index', :locale => 'en' >>> >>> and move it after: >>> Station.should_receive(:find).with(:all).and_return(@mock_stations) >>> >>> I set-up inter-object expectations before exercising the controller >>> action. >>> >>> Does this help? >>> >>> -Anthony >>> >>> PS: If you could be more specific about which concepts about mocks >>> and stubs are confusing you, I'd be happy to try and help.l >>> >>> ---------- >>> >>> Hi, >>> >>> I am getting started with writing controller specs with rspec/rails, >>> and seem to have trouble fully grasping the concept of mocks and >>> stubs. I can't figure out what's wrong with the following. This is >>> the action I want to spec: >>> >>> def index >>> @stations = Station.find(:all, :order => 'name') >>> end >>> >>> and this is my spec: >>> >>> >>> describe "GET to index" do >>> controller_name :stations >>> >>> before(:each) do >>> @mock_station = mock_model(Station) >>> @mock_stations = [@mock_station] >>> Station.stub!(:find).and_return(@mock_stations) >>> get 'index', :locale => 'en' >>> end >>> >>> it "should find stations" do >>> Station.should_receive(:find).with(:all).and_return >>> (@mock_stations) >>> end >>> >>> end >>> >>> >>> It fails with this error: >>> >>> Spec::Mocks::MockExpectationError in 'GET to index should find >>> stations' >>> Station expected :find with (:all) once, but received it 0 times >>> ./spec/controllers/stations_controller_spec.rb:22: >>> >>> I can see in the log that the database is not hit for Station.find >>> (:all), so the stubbing seems to have worked. Guess I'm stuck. >>> Thanks >>> for any hint to get me going again! >>> >>> Ingo >>> >>> >>> >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From philodespotos at gmail.com Fri Jun 15 16:16:59 2007 From: philodespotos at gmail.com (Kyle Hargraves) Date: Fri, 15 Jun 2007 15:16:59 -0500 Subject: [rspec-users] problem getting started with stubbing in rails controller specs In-Reply-To: References: <52BF9052-EC49-4E93-8084-E6C7928940EA@digitalphenom.com> <6953B85F-9475-49B5-8CB6-7BDBBF5A5D45@ingoweiss.com> Message-ID: On Jun 15, 2007, at 1:53 PM, Ingo Weiss wrote: > Thanks so much, Anthony, this works! > > I thought that .with(:all) would set the expectation that 'find' is > called with the :all parameter like this: > > Station.find(:all) > > but apparently that is not what's happening > > Ingo It is indeed expecting 'find' to be called with(:all), but you aren't doing so: @stations = Station.find(:all, :order => 'name') All of the parameters are taken into account. IIRC you can't use with (:all, any_args) either, though I might be wrong. Kyle From tom at experthuman.com Fri Jun 15 16:21:14 2007 From: tom at experthuman.com (Tom Stuart) Date: Fri, 15 Jun 2007 21:21:14 +0100 Subject: [rspec-users] problem getting started with stubbing in rails controller specs In-Reply-To: References: <52BF9052-EC49-4E93-8084-E6C7928940EA@digitalphenom.com> <6953B85F-9475-49B5-8CB6-7BDBBF5A5D45@ingoweiss.com> Message-ID: <37A97336-B42C-4A32-BA69-8AFDBFBE9E54@experthuman.com> On 15 Jun 2007, at 19:53, Ingo Weiss wrote: > I thought that .with(:all) would set the expectation that 'find' is > called with the :all parameter like this: > > Station.find(:all) > > but apparently that is not what's happening That is what .with(:all) does, but in your controller you're doing @stations = Station.find(:all, :order => 'name') i.e. .with(:all, :order => 'name'), so it's no surprise the spec fails! :-) Cheers, -Tom From patrick at limited-overload.de Fri Jun 15 16:43:40 2007 From: patrick at limited-overload.de (Patrick Lenz) Date: Fri, 15 Jun 2007 22:43:40 +0200 Subject: [rspec-users] problem getting started with stubbing in rails controller specs In-Reply-To: References: <52BF9052-EC49-4E93-8084-E6C7928940EA@digitalphenom.com> <6953B85F-9475-49B5-8CB6-7BDBBF5A5D45@ingoweiss.com> Message-ID: On Jun 15, 2007, at 10:16 PM, Kyle Hargraves wrote: > It is indeed expecting 'find' to be called with(:all), but you aren't > doing so: > > @stations = Station.find(:all, :order => 'name') > > All of the parameters are taken into account. IIRC you can't use with > (:all, any_args) either, though I might be wrong. You should actually be able to invoke it this way: Station.should_receive(:find).with(:all, anything).and_return (@mock_stations) Best, Patrick From francois.beausoleil at gmail.com Fri Jun 15 21:35:56 2007 From: francois.beausoleil at gmail.com (=?UTF-8?Q?Fran=C3=A7ois_Beausoleil?=) Date: Fri, 15 Jun 2007 21:35:56 -0400 Subject: [rspec-users] shared descriptions -- a couple of issues In-Reply-To: <57c63afe0706051639jbe72369nd8be92e11628c593@mail.gmail.com> References: <57c63afe0705101027y5b91054cwbfcd18619f8b003b@mail.gmail.com> <7075BF68-D674-47C1-A8DA-FC6EC339431E@mydigitallife.com> <41d5fadf0706040855t7a6663ddwe3893b5208d38f87@mail.gmail.com> <57c63afe0706040904x1987f941t7ce8efc816f40835@mail.gmail.com> <41d5fadf0706041209p36000edbr36d439b6e8547eaf@mail.gmail.com> <57c63afe0706050442m7b2be917u380d7ce969355c7f@mail.gmail.com> <41d5fadf0706050738n8e3cf13m93adeb79644c7ca9@mail.gmail.com> <57c63afe0706051639jbe72369nd8be92e11628c593@mail.gmail.com> Message-ID: <41d5fadf0706151835x743b0ddege7523bdddf481947@mail.gmail.com> Hello David, 2007/6/5, David Chelimsky : > Your wait is over. I just released it. Might take a couple of hours > for mirrors to get resolved, but you should be able to get it later > today. Okay, I upgraded to 1.0.5, and I still get the error: $ script/spec spec/ /home/francois/src/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:11:in `add_shared_behaviour': Shared Behaviour 'All controllers' already exists (ArgumentError) from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/extensions/kernel.rb:36:in `register_behaviour' from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/extensions/kernel.rb:24:in `describe' from ./spec//views/assets/../../xl_suite/spec_helpers.rb:96 from /home/francois/src/vendor/plugins/plugin_dependencies/lib/plugin_dependencies/extensions/kernel.rb:14:in `gem_original_require_without_plugins' from /home/francois/src/vendor/plugins/plugin_dependencies/lib/plugin_dependencies/extensions/kernel.rb:14:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' from /home/francois/src/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:495:in `require' from /home/francois/src/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in' ... 15 levels... from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:84:in `load_specs' from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:22:in `run' from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in `run' from script/spec:4 I tried to use trunk at 2097 and I get the same error. rspec and rspec_on_rails are installed as plugins in vendor/plugins, and I removed the rspec gem from my system. rake spec reports the same problem. In summary: $ script/spec spec/models/asset_spec.rb => Works $ script/spec spec/models/ => Works $ script/spec spec/views/assets/ => Works $ script/spec spec/views => Fails $ rake spec => Fails Am I doing something wrong ? Thanks ! -- Fran?ois Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ From edgargonzalez at gmail.com Sat Jun 16 12:29:25 2007 From: edgargonzalez at gmail.com (Edgar Gonzalez) Date: Sat, 16 Jun 2007 12:29:25 -0400 Subject: [rspec-users] Specs don't find modules when using the secure_actions or ssl_requirement plugin Message-ID: Hello, I'm trying the secure_actions plugin (or ssl_requirements) I'm installed the plugin, and added the include in application controller: class ApplicationController < ActionController::Base include ExceptionNotifiable include AuthenticatedSystem include SecureActions ... but when I try to run the specs I got this error: /home/edgar/sandboxes/sugarstats/config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:477:in `const_missing': uninitialized constant ApplicationController::SecureActions (NameError) the same behavior if I try with ssl_requirement plugin any clue? -- Edgar Gonz?lez Gonz?lez E-mail: edgargonzalez at gmail.com -- From mailing_lists at railsnewbie.com Sat Jun 16 12:59:22 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 16 Jun 2007 12:59:22 -0400 Subject: [rspec-users] Problems with RCov and Rails In-Reply-To: References: Message-ID: <8CD56E74-186B-413D-8F3F-4661399A7E77@railsnewbie.com> Why not use the the built in task, rake spec:rcov ? Scott On Jun 15, 2007, at 7:03 AM, Ian Leitch wrote: > Hey list, > > I'm trying to use the rcov integration that rspec provides in my Rails > application. As per the documentation on the website, I've created > the following rake task: > > lib/tasks/specs_with_rcov.rake: > > require 'spec/rake/spectask' > > desc "Run all specs with rcov" > Spec::Rake::SpecTask.new('specs_with_rcov') do |t| > t.rcov = true > end > > However... > > $ rake specs_with_rcov > (in /Users/ian/Projects/systino/trunk) > rake aborted! > superclass mismatch for class Annotation > /Users/ian/Projects/systino/trunk/rakefile:10 > (See full trace by running task with --trace) > > ======= > > $ rake specs_with_rcov --trace > (in /Users/ian/Projects/systino/trunk) > rake aborted! > superclass mismatch for class Annotation > /Users/ian/Projects/systino/trunk/vendor/rails/railties/lib/tasks/ > annotations.rake:2 > /Users/ian/Projects/systino/trunk/vendor/rails/railties/lib/tasks/ > rails.rb:4:in > `load' > /Users/ian/Projects/systino/trunk/vendor/rails/railties/lib/tasks/ > rails.rb:4 > /Users/ian/Projects/systino/trunk/vendor/rails/railties/lib/tasks/ > rails.rb:4:in > `each' > /Users/ian/Projects/systino/trunk/vendor/rails/railties/lib/tasks/ > rails.rb:4 > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in > `gem_original_require' > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in > `require' > /Users/ian/Projects/systino/trunk/rakefile:10 > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1940:in > `load' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1940:in > `raw_load_rakefile' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1727:in > `load_rakefile' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in > `standard_exception_handling' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1726:in > `load_rakefile' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1710:in `run' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in > `standard_exception_handling' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in `run' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/bin/rake:7 > /usr/local/bin/rake:16:in `load' > /usr/local/bin/rake:16 > > ======= > > The Annotation class inherits a Struct instance which I thought may be > conflicting with a Struct class provided by RSpec, however it doesn't, > nor does RSpec contain an Annotation class. I'm afraid this bug is > beyond me. Has anyone else seen it? > > $ script/about > About your application's environment > Ruby version 1.8.6 (powerpc-darwin8.9.0) > RubyGems version 0.9.4 > Rails version 1.2.3 > Active Record version 1.15.3 > Action Pack version 1.13.3 > Action Web Service version 1.2.3 > Action Mailer version 1.3.3 > Active Support version 1.4.2 > Edge Rails revision 184 > Application root /Users/ian/Projects/systino/trunk > Environment development > Database adapter mysql > Database schema version 26 > > Cheers > Ian > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sun Jun 17 11:54:35 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 17 Jun 2007 10:54:35 -0500 Subject: [rspec-users] Specs don't find modules when using the secure_actions or ssl_requirement plugin In-Reply-To: References: Message-ID: <57c63afe0706170854g19c4a7eaqa777dda7f259e3da@mail.gmail.com> On 6/16/07, Edgar Gonzalez wrote: > Hello, > > I'm trying the secure_actions plugin (or ssl_requirements) > > I'm installed the plugin, and added the include in application controller: > > class ApplicationController < ActionController::Base > include ExceptionNotifiable > include AuthenticatedSystem > include SecureActions > ... > > but when I try to run the specs I got this error: > > /home/edgar/sandboxes/sugarstats/config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:477:in > `const_missing': uninitialized constant > ApplicationController::SecureActions (NameError) > > the same behavior if I try with ssl_requirement plugin > > any clue? Maybe they're not getting loaded. Try requiring them in spec_helper.rb. require 'secure_actions' > > -- > Edgar Gonz?lez Gonz?lez > E-mail: edgargonzalez at gmail.com > -- > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Jun 17 12:09:16 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 17 Jun 2007 11:09:16 -0500 Subject: [rspec-users] shared descriptions -- a couple of issues In-Reply-To: <41d5fadf0706151835x743b0ddege7523bdddf481947@mail.gmail.com> References: <57c63afe0705101027y5b91054cwbfcd18619f8b003b@mail.gmail.com> <7075BF68-D674-47C1-A8DA-FC6EC339431E@mydigitallife.com> <41d5fadf0706040855t7a6663ddwe3893b5208d38f87@mail.gmail.com> <57c63afe0706040904x1987f941t7ce8efc816f40835@mail.gmail.com> <41d5fadf0706041209p36000edbr36d439b6e8547eaf@mail.gmail.com> <57c63afe0706050442m7b2be917u380d7ce969355c7f@mail.gmail.com> <41d5fadf0706050738n8e3cf13m93adeb79644c7ca9@mail.gmail.com> <57c63afe0706051639jbe72369nd8be92e11628c593@mail.gmail.com> <41d5fadf0706151835x743b0ddege7523bdddf481947@mail.gmail.com> Message-ID: <57c63afe0706170909i1c82f0a7jd384d59aeb787f93@mail.gmail.com> On 6/15/07, Fran?ois Beausoleil wrote: > Hello David, > > 2007/6/5, David Chelimsky : > > Your wait is over. I just released it. Might take a couple of hours > > for mirrors to get resolved, but you should be able to get it later > > today. > > Okay, I upgraded to 1.0.5, and I still get the error: > > $ script/spec spec/ > /home/francois/src/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:11:in > `add_shared_behaviour': Shared Behaviour 'All controllers' already > exists (ArgumentError) > from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/extensions/kernel.rb:36:in > `register_behaviour' > from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/extensions/kernel.rb:24:in > `describe' > from ./spec//views/assets/../../xl_suite/spec_helpers.rb:96 > from /home/francois/src/vendor/plugins/plugin_dependencies/lib/plugin_dependencies/extensions/kernel.rb:14:in > `gem_original_require_without_plugins' > from /home/francois/src/vendor/plugins/plugin_dependencies/lib/plugin_dependencies/extensions/kernel.rb:14:in > `gem_original_require' > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `require' > from /home/francois/src/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:495:in > `require' > from /home/francois/src/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:342:in > `new_constants_in' > ... 15 levels... > from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:84:in > `load_specs' > from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:22:in > `run' > from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in > `run' > from script/spec:4 > > I tried to use trunk at 2097 and I get the same error. rspec and > rspec_on_rails are installed as plugins in vendor/plugins, and I > removed the rspec gem from my system. rake spec reports the same > problem. > > In summary: > > $ script/spec spec/models/asset_spec.rb => Works > $ script/spec spec/models/ => Works > $ script/spec spec/views/assets/ => Works > $ script/spec spec/views => Fails > $ rake spec => Fails > > Am I doing something wrong ? No - you're OK. There's a bug. I can tell you how to patch it to get it to work - I'll be getting a better version committed to svn today or tomorrow: Change line 10 in behaviour.rb (in vendor/plugins/rspec/lib/spec/dsl) from this: return if found_behaviour and behaviour.description[:spec_path] == found_behaviour.description[:spec_path] to this: return if found_behaviour and File.expand_path(behaviour.description[:spec_path]) == File.expand_path(found_behaviour.description[:spec_path]) Cheers, David > > Thanks ! > -- > Fran?ois Beausoleil > http://blog.teksol.info/ > http://piston.rubyforge.org/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From edgargonzalez at gmail.com Sun Jun 17 12:14:31 2007 From: edgargonzalez at gmail.com (Edgar Gonzalez) Date: Sun, 17 Jun 2007 12:14:31 -0400 Subject: [rspec-users] Specs don't find modules when using the secure_actions or ssl_requirement plugin In-Reply-To: <57c63afe0706170854g19c4a7eaqa777dda7f259e3da@mail.gmail.com> References: <57c63afe0706170854g19c4a7eaqa777dda7f259e3da@mail.gmail.com> Message-ID: Thanks for answer David I'll do that with no success :-/ even I try with full path If I put the require 'secure_actions' in ApplicationController: require 'secure_action' class ApplicationController < ActionController::Base ... the specs run fine, but I think this is not the right approach - modify the application in order to specs run On 6/17/07, David Chelimsky wrote: > On 6/16/07, Edgar Gonzalez wrote: > > Hello, > > > > I'm trying the secure_actions plugin (or ssl_requirements) > > > > I'm installed the plugin, and added the include in application controller: > > > > class ApplicationController < ActionController::Base > > include ExceptionNotifiable > > include AuthenticatedSystem > > include SecureActions > > ... > > > > but when I try to run the specs I got this error: > > > > /home/edgar/sandboxes/sugarstats/config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:477:in > > `const_missing': uninitialized constant > > ApplicationController::SecureActions (NameError) > > > > the same behavior if I try with ssl_requirement plugin > > > > any clue? > > Maybe they're not getting loaded. Try requiring them in spec_helper.rb. > > require 'secure_actions' > > > > > -- > > Edgar Gonz?lez Gonz?lez > > E-mail: edgargonzalez at gmail.com > > -- > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Edgar Gonz?lez Gonz?lez E-mail: edgargonzalez at gmail.com http://lacaraoscura.com http://rubycorner.com http://to2blogs.com -- From dchelimsky at gmail.com Sun Jun 17 23:59:14 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 17 Jun 2007 22:59:14 -0500 Subject: [rspec-users] shared descriptions -- a couple of issues In-Reply-To: <57c63afe0706170909i1c82f0a7jd384d59aeb787f93@mail.gmail.com> References: <7075BF68-D674-47C1-A8DA-FC6EC339431E@mydigitallife.com> <41d5fadf0706040855t7a6663ddwe3893b5208d38f87@mail.gmail.com> <57c63afe0706040904x1987f941t7ce8efc816f40835@mail.gmail.com> <41d5fadf0706041209p36000edbr36d439b6e8547eaf@mail.gmail.com> <57c63afe0706050442m7b2be917u380d7ce969355c7f@mail.gmail.com> <41d5fadf0706050738n8e3cf13m93adeb79644c7ca9@mail.gmail.com> <57c63afe0706051639jbe72369nd8be92e11628c593@mail.gmail.com> <41d5fadf0706151835x743b0ddege7523bdddf481947@mail.gmail.com> <57c63afe0706170909i1c82f0a7jd384d59aeb787f93@mail.gmail.com> Message-ID: <57c63afe0706172059gd85c0acya3c6c5d6efacc2f8@mail.gmail.com> On 6/17/07, David Chelimsky wrote: > On 6/15/07, Fran?ois Beausoleil wrote: > > Hello David, > > > > 2007/6/5, David Chelimsky : > > > Your wait is over. I just released it. Might take a couple of hours > > > for mirrors to get resolved, but you should be able to get it later > > > today. > > > > Okay, I upgraded to 1.0.5, and I still get the error: > > > > $ script/spec spec/ > > /home/francois/src/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:11:in > > `add_shared_behaviour': Shared Behaviour 'All controllers' already > > exists (ArgumentError) > > from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/extensions/kernel.rb:36:in > > `register_behaviour' > > from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/extensions/kernel.rb:24:in > > `describe' > > from ./spec//views/assets/../../xl_suite/spec_helpers.rb:96 > > from /home/francois/src/vendor/plugins/plugin_dependencies/lib/plugin_dependencies/extensions/kernel.rb:14:in > > `gem_original_require_without_plugins' > > from /home/francois/src/vendor/plugins/plugin_dependencies/lib/plugin_dependencies/extensions/kernel.rb:14:in > > `gem_original_require' > > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > > `require' > > from /home/francois/src/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:495:in > > `require' > > from /home/francois/src/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:342:in > > `new_constants_in' > > ... 15 levels... > > from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:84:in > > `load_specs' > > from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:22:in > > `run' > > from /home/francois/src/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in > > `run' > > from script/spec:4 > > > > I tried to use trunk at 2097 and I get the same error. rspec and > > rspec_on_rails are installed as plugins in vendor/plugins, and I > > removed the rspec gem from my system. rake spec reports the same > > problem. > > > > In summary: > > > > $ script/spec spec/models/asset_spec.rb => Works > > $ script/spec spec/models/ => Works > > $ script/spec spec/views/assets/ => Works > > $ script/spec spec/views => Fails > > $ rake spec => Fails > > > > Am I doing something wrong ? > > No - you're OK. There's a bug. I can tell you how to patch it to get > it to work - I'll be getting a better version committed to svn today > or tomorrow: > > Change line 10 in behaviour.rb (in vendor/plugins/rspec/lib/spec/dsl) from this: > > return if found_behaviour and behaviour.description[:spec_path] == > found_behaviour.description[:spec_path] > > to this: > > return if found_behaviour and > File.expand_path(behaviour.description[:spec_path]) == > File.expand_path(found_behaviour.description[:spec_path]) I committed a fix for this to r2097, so it will be in the next release. > > Cheers, > David > > > > > Thanks ! > > -- > > Fran?ois Beausoleil > > http://blog.teksol.info/ > > http://piston.rubyforge.org/ > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > From port001 at gmail.com Mon Jun 18 09:41:36 2007 From: port001 at gmail.com (Ian Leitch) Date: Mon, 18 Jun 2007 14:41:36 +0100 Subject: [rspec-users] Something like rcov but more explicit? Message-ID: Hey list, Does anything exist that can show me which lines are explicitly tested? RCov is great, but it doesn't really give a sense of _actual_ coverage, indeed, there is no guarantee that functions executed were in fact called as the result of a line being tested. I know nothing of the rspec internals, but would a simple list of executed lines be a relatively simple feature to add? Cheers Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070618/5567e433/attachment.html From aslak.hellesoy at gmail.com Mon Jun 18 13:51:11 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 18 Jun 2007 19:51:11 +0200 Subject: [rspec-users] Something like rcov but more explicit? In-Reply-To: References: Message-ID: <8d961d900706181051s7ca175d1gc000fb1710cd110d@mail.gmail.com> On 6/18/07, Ian Leitch wrote: > Hey list, > > Does anything exist that can show me which lines are explicitly tested? RCov > is great, but it doesn't really give a sense of _actual_ coverage, indeed, > there is no guarantee that functions executed were in fact called as the > result of a line being tested. > Why do you care whether a line was executed directly (spec->code) or indirectly (spec->code->code->code)? > I know nothing of the rspec internals, but would a simple list of executed > lines be a relatively simple feature to add? > That would be hard I think. Feel free to investigate it. I would rather recommend you use RSpec's --heckle switch if you want to know how good your examples are. Coverage is overrated. See http://seattlerb.rubyforge.org/heckle/ for more info. Aslak > Cheers > Ian > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From barjunk at attglobal.net Mon Jun 18 18:06:57 2007 From: barjunk at attglobal.net (barsalou) Date: Mon, 18 Jun 2007 14:06:57 -0800 Subject: [rspec-users] Testing for cross site scripting, etc. Message-ID: <20070618140657.8bokw24dssko8gko@lcgalaska.com> Being new to testing and ruby, are there "standard" tests that can be done that test for things like cross site scripting and friends? If not, anyone have ideas on what I might do about testing those sorts of things? I'll be using rails, also. Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From court3nay at gmail.com Mon Jun 18 19:51:55 2007 From: court3nay at gmail.com (Courtenay) Date: Mon, 18 Jun 2007 16:51:55 -0700 Subject: [rspec-users] Testing for cross site scripting, etc. In-Reply-To: <20070618140657.8bokw24dssko8gko@lcgalaska.com> References: <20070618140657.8bokw24dssko8gko@lcgalaska.com> Message-ID: <4b430c8f0706181651t673f99dbxa6211a9b23378cbe@mail.gmail.com> i have a plugin called "dumbass". It just greps through your views and looks for things like <%= user.name %> which should be <%=h user.name %> The name comes from the word I called myself when I found I'd forgotten to do that over and over in one app. script/plugin install svn://caboo.se/plugins/court3nay/dumbass run it with rake dumbass I'm eager to find other simple ways of detecting vulnerabilities. I actually have another plugin/script (spider_test) which is a rails integration test; it spiders over your whole app looking for errors. One of its features is to randomly fill in your forms (a weak form of fuzzing). I would really like to expand that so that it pushes sql injection and XSS and other types of security issues. Is that what you meant? On 6/18/07, barsalou wrote: > Being new to testing and ruby, are there "standard" tests that can be > done that test for things like cross site scripting and friends? > > If not, anyone have ideas on what I might do about testing those sorts > of things? > > I'll be using rails, also. > > Mike B. > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Mon Jun 18 19:56:13 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 19 Jun 2007 01:56:13 +0200 Subject: [rspec-users] Testing for cross site scripting, etc. In-Reply-To: <20070618140657.8bokw24dssko8gko@lcgalaska.com> References: <20070618140657.8bokw24dssko8gko@lcgalaska.com> Message-ID: <8d961d900706181656i2354ae21l4c2ebbf8f5a5d6a8@mail.gmail.com> On 6/19/07, barsalou wrote: > Being new to testing and ruby, are there "standard" tests that can be > done that test for things like cross site scripting and friends? > I suppose you mean http://en.wikipedia.org/wiki/Cross-site_scripting (XSS) XSS happens *in* the browser, where Ruby doesn't run (yet), so I'm not sure how you think RSpec is relevant. Unless you want to use Watir or Selenium-RC, which allows you to talk to a browser from Ruby (and RSpec) > If not, anyone have ideas on what I might do about testing those sorts > of things? > Can you be more specific about what you want to verify? Aslak > I'll be using rails, also. > > Mike B. > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From court3nay at gmail.com Mon Jun 18 20:23:37 2007 From: court3nay at gmail.com (Courtenay) Date: Mon, 18 Jun 2007 17:23:37 -0700 Subject: [rspec-users] Testing for cross site scripting, etc. In-Reply-To: <8d961d900706181656i2354ae21l4c2ebbf8f5a5d6a8@mail.gmail.com> References: <20070618140657.8bokw24dssko8gko@lcgalaska.com> <8d961d900706181656i2354ae21l4c2ebbf8f5a5d6a8@mail.gmail.com> Message-ID: <4b430c8f0706181723o3ae007a7nc96a705480538e3c@mail.gmail.com> On 6/18/07, aslak hellesoy wrote: > On 6/19/07, barsalou wrote: > > Being new to testing and ruby, are there "standard" tests that can be > > done that test for things like cross site scripting and friends? > > > > I suppose you mean http://en.wikipedia.org/wiki/Cross-site_scripting (XSS) > > XSS happens *in* the browser, where Ruby doesn't run (yet), so I'm not > sure how you think RSpec is relevant. Unless you want to use Watir or > Selenium-RC, which allows you to talk to a browser from Ruby (and > RSpec) I'd say they want to assert, in the views, that user-generated input does not render script tags. Like if I set my user info to be it should appear in the view as <script>alert and so on. Maybe in the view spec @user.stub!(:info).and_return('') response.should not_have_tag('script') Right? From jed.hurt at gmail.com Mon Jun 18 20:45:42 2007 From: jed.hurt at gmail.com (Jed Hurt) Date: Mon, 18 Jun 2007 18:45:42 -0600 Subject: [rspec-users] BlackBox testing Message-ID: I am porting SWX (swxformat.org) to Ruby. It's a data exchange format that assembles data structures into native SWF bytecode. Here's my dilemma: The original SWX implementation (PHP) tests a lot of methods that wouldn't be included in the public API (if PHP properly supported encapsulation that is). The PHP implementation really only includes a single public method?writeSWF. Basically, you pass writeSWF a data structure, and it returns SWF bytecode. Pretty simple on the surface, but the actual SwfCompiler class is monolithic ( http://svn1.cvsdude.com/osflash/swx/trunk/php/SwfCompiler.php ). Here's my question: I lean towards protecting as many methods of my classes as possible. Protect first, then make public if it becomes necessary to do so. Following the original implementation, my only public method would be SwfCompiler#write_swf. But how can I drive my implementation by specifying only one method? I'd have to blindly write a couple hundred lines of protected methods before I implemented any examples. What is the common prescription to overcome such a scenario? From dchelimsky at gmail.com Mon Jun 18 21:08:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 18 Jun 2007 20:08:13 -0500 Subject: [rspec-users] BlackBox testing In-Reply-To: References: Message-ID: <57c63afe0706181808l3d2202c6u4c667c40b3d4eca1@mail.gmail.com> On 6/18/07, Jed Hurt wrote: > I am porting SWX (swxformat.org) to Ruby. It's a data exchange format > that assembles data structures into native SWF bytecode. > > Here's my dilemma: The original SWX implementation (PHP) tests a lot > of methods that wouldn't be included in the public API (if PHP > properly supported encapsulation that is). The PHP implementation > really only includes a single public method?writeSWF. Basically, you > pass writeSWF a data structure, and it returns SWF bytecode. > > Pretty simple on the surface, but the actual SwfCompiler class is > monolithic ( http://svn1.cvsdude.com/osflash/swx/trunk/php/SwfCompiler.php > ). That's the beauty of porting stuff - you get to redesign it as you go. I'd take the opportunity to improve the design and break it up into a few smaller classes that do targeted parts of the job. You can pass mock instances of them in on the constructor in your rspec examples to describe how the main object uses the helper objects, and then make things public on the helper objects. Unless they're maintaining state (which they probably shouldn't) you run no risk by having them public on those objects. And then you get the benefit of focusing on little bits as you go. Cheers, David > > Here's my question: I lean towards protecting as many methods of my > classes as possible. Protect first, then make public if it becomes > necessary to do so. Following the original implementation, my only > public method would be SwfCompiler#write_swf. > > But how can I drive my implementation by specifying only one method? > I'd have to blindly write a couple hundred lines of protected methods > before I implemented any examples. > > What is the common prescription to overcome such a scenario? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Tue Jun 19 02:51:45 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 19 Jun 2007 08:51:45 +0200 Subject: [rspec-users] Testing for cross site scripting, etc. In-Reply-To: <4b430c8f0706181723o3ae007a7nc96a705480538e3c@mail.gmail.com> References: <20070618140657.8bokw24dssko8gko@lcgalaska.com> <8d961d900706181656i2354ae21l4c2ebbf8f5a5d6a8@mail.gmail.com> <4b430c8f0706181723o3ae007a7nc96a705480538e3c@mail.gmail.com> Message-ID: <8d961d900706182351p79d15f3flf5405dd3ef35a511@mail.gmail.com> On 6/19/07, Courtenay wrote: > On 6/18/07, aslak hellesoy wrote: > > On 6/19/07, barsalou wrote: > > > Being new to testing and ruby, are there "standard" tests that can be > > > done that test for things like cross site scripting and friends? > > > > > > > I suppose you mean http://en.wikipedia.org/wiki/Cross-site_scripting (XSS) > > > > XSS happens *in* the browser, where Ruby doesn't run (yet), so I'm not > > sure how you think RSpec is relevant. Unless you want to use Watir or > > Selenium-RC, which allows you to talk to a browser from Ruby (and > > RSpec) > > I'd say they want to assert, in the views, that user-generated input > does not render script tags. > > Like if I set my user info to be it > should appear in the view as <script>alert and so on. > > Maybe in the view spec > > @user.stub!(:info).and_return('') > response.should not_have_tag('script') > Oh I see. Your example sounds like a good way to prevent against it. Aslak > Right? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From JScruggs at thoughtworks.com Tue Jun 19 10:30:37 2007 From: JScruggs at thoughtworks.com (Jake Scruggs) Date: Tue, 19 Jun 2007 09:30:37 -0500 Subject: [rspec-users] Problems translating should_render from 0.8.2 to 1.0.5 Message-ID: An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070619/40b0b0ce/attachment.html From court3nay at gmail.com Tue Jun 19 16:26:51 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 19 Jun 2007 13:26:51 -0700 Subject: [rspec-users] Problems translating should_render from 0.8.2 to 1.0.5 In-Reply-To: References: Message-ID: <4b430c8f0706191326v4e95a512g610313d8ae14ddc2@mail.gmail.com> On 6/19/07, Jake Scruggs wrote: > I'm working on a large Rails site and we want to move from RSpec 0.8.2 to > the latest and greatest. So we ran the translator and yet we're having a > lot of trouble translating should_render. > > I found this on the web: > > We will NOT be supporting the following in the new syntax: > controller.should_render > controller.should_redirect_to > > You will be able to use instead: > response.should render_template > response.should render_text > response.should redirect_to > > But the problem I have is that render_template doesn't have the > functionality that we used in lots of our should_render expectations. A lot > of our should renders specify an action and and a controller, so now the > change over is slow (we have to figure out which file is being rendered > instead), but the big problem is that when testing actions that render a > partial (mostly for ajax calls) we need to test the locals that get passed > into the template. > > here's a typical spec: > specify "the :start_date should equal the date passed in" do > @mock_event_calendar_data = mock('Mock event_calendar_data') > > EventCalendarData.should_receive(:new).and_return(@mock_event_calendar_data) > date = Date.today > controller.should_render :partial => 'calendar', :locals => {:start_date > => date, :event_calendar_data => @mock_event_calendar_data} > get 'ajax_calendar', :date => Date.today.strftime("%B-%d-%Y") > end first, move the should_render to AFTER the get call. From barjunk at attglobal.net Tue Jun 19 17:39:58 2007 From: barjunk at attglobal.net (barsalou) Date: Tue, 19 Jun 2007 13:39:58 -0800 Subject: [rspec-users] Testing for cross site scripting, etc. Message-ID: <20070619133958.ce3x9xe9wkoc0swk@lcgalaska.com> Responding to: From court3nay at gmail.com Mon Jun 18 20:23:37 2007 From: court3nay at gmail.com (Courtenay) Date: Mon, 18 Jun 2007 17:23:37 -0700 Subject: [rspec-users] Testing for cross site scripting, etc. In-Reply-To: <8d961d900706181656i2354ae21l4c2ebbf8f5a5d6a8 at mail.gmail.com> References: <20070618140657.8bokw24dssko8gko at lcgalaska.com> <8d961d900706181656i2354ae21l4c2ebbf8f5a5d6a8 at mail.gmail.com> Message-ID: <4b430c8f0706181723o3ae007a7nc96a705480538e3c at mail.gmail.com> On 6/18/07, aslak hellesoy wrote: > On 6/19/07, barsalou wrote: > > Being new to testing and ruby, are there "standard" tests that can be > > done that test for things like cross site scripting and friends? > > > > I suppose you mean http://en.wikipedia.org/wiki/Cross-site_scripting (XSS) > > XSS happens *in* the browser, where Ruby doesn't run (yet), so I'm not > sure how you think RSpec is relevant. Unless you want to use Watir or > Selenium-RC, which allows you to talk to a browser from Ruby (and > RSpec) I'd say they want to assert, in the views, that user-generated input does not render script tags. Like if I set my user info to be it should appear in the view as <script>alert and so on. Maybe in the view spec @user.stub!(:info).and_return('') response.should not_have_tag('script') Right? This is exactly the kind of thing I was looking for. I do have a question though. Do the two lines above really test anything? or were you just showing an example of what I might do? Also, the fact that you wrote the dumbass plugin makes me wonder why <%=h user.name =%> is needed? I get what your doing, but why doesn't escaping happen in the form? Aren't there protections already built-in, especially in rails, to escape form fields? Can you do this same sort of thing for SQL injection problem as well? Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From court3nay at gmail.com Tue Jun 19 18:14:34 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 19 Jun 2007 15:14:34 -0700 Subject: [rspec-users] Testing for cross site scripting, etc. In-Reply-To: <20070619133958.ce3x9xe9wkoc0swk@lcgalaska.com> References: <20070619133958.ce3x9xe9wkoc0swk@lcgalaska.com> Message-ID: <4b430c8f0706191514i44568529y1fba15b1bb8b5b1f@mail.gmail.com> On 6/19/07, barsalou wrote: > On 6/18/07, aslak hellesoy wrote: > > On 6/19/07, barsalou wrote: > > > Being new to testing and ruby, are there "standard" tests that can be > > > done that test for things like cross site scripting and friends? > > > > > > > I suppose you mean http://en.wikipedia.org/wiki/Cross-site_scripting (XSS) > > > > XSS happens *in* the browser, where Ruby doesn't run (yet), so I'm not > > sure how you think RSpec is relevant. Unless you want to use Watir or > > Selenium-RC, which allows you to talk to a browser from Ruby (and > > RSpec) > > I'd say they want to assert, in the views, that user-generated input > does not render script tags. > > Like if I set my user info to be it > should appear in the view as <script>alert and so on. > > Maybe in the view spec > > @user.stub!(:info).and_return('') > response.should not_have_tag('script') > > Do the two lines above really test anything? or were you just showing > an example of what I might do? They're an approximate example. Your code will look slightly different. > Also, the fact that you wrote the dumbass plugin makes me wonder why > <%=h user.name =%> is needed? I get what your doing, but why doesn't > escaping happen in the form? Aren't there protections already > built-in, especially in rails, to escape form fields? That's what <%=h is. Html escaping. It's easy to forget. Note there is no trailing = > Can you do this same sort of thing for SQL injection problem as well? Mike B. Rails has inbuilt injection safety, provided you follow the suggested practise. I suggest you read up on it before we revoke your rails license: http://manuals.rubyonrails.com/read/chapter/40 :) From bkeepers at gmail.com Wed Jun 20 04:02:49 2007 From: bkeepers at gmail.com (Brandon Keepers) Date: Wed, 20 Jun 2007 11:02:49 +0300 Subject: [rspec-users] RSpec getting too intimate? Message-ID: <3A35D404-1EC2-45E6-ABF7-7FB68C0BDFEA@gmail.com> I have a new blog post about some thoughts that I've had as I've been using rspec lately. I would love to hear your thoughts: http://opensoul.org/2007/6/20/rspec-is-getting-too-intimate-with- my-code Brandon From jonathan at parkerhill.com Wed Jun 20 04:38:31 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Wed, 20 Jun 2007 04:38:31 -0400 Subject: [rspec-users] RSpec getting too intimate? In-Reply-To: <3A35D404-1EC2-45E6-ABF7-7FB68C0BDFEA@gmail.com> References: <3A35D404-1EC2-45E6-ABF7-7FB68C0BDFEA@gmail.com> Message-ID: my first reaction: Thank You :) On Jun 20, 2007, at 4:02 AM, Brandon Keepers wrote: > I have a new blog post about some thoughts that I've had as I've been > using rspec lately. I would love to hear your thoughts: > > http://opensoul.org/2007/6/20/rspec-is-getting-too-intimate-with- > my-code > > Brandon > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From port001 at gmail.com Wed Jun 20 07:10:04 2007 From: port001 at gmail.com (Ian Leitch) Date: Wed, 20 Jun 2007 12:10:04 +0100 Subject: [rspec-users] Something like rcov but more explicit? In-Reply-To: <8d961d900706181051s7ca175d1gc000fb1710cd110d@mail.gmail.com> References: <8d961d900706181051s7ca175d1gc000fb1710cd110d@mail.gmail.com> Message-ID: On 18/06/07, aslak hellesoy wrote: > > On 6/18/07, Ian Leitch wrote: > > Hey list, > > > > Does anything exist that can show me which lines are explicitly tested? > RCov > > is great, but it doesn't really give a sense of _actual_ coverage, > indeed, > > there is no guarantee that functions executed were in fact called as the > > result of a line being tested. > > > > Why do you care whether a line was executed directly (spec->code) or > indirectly (spec->code->code->code)? Just because a spec executed a function coincidentally and it generates some kind of error (most likely semantic), there is no guarantee that the code that made the call will also trip up. Therefore, rcov doesn't really tell me to what extent my code base is explicitly tested. > I know nothing of the rspec internals, but would a simple list of executed > > lines be a relatively simple feature to add? > > > > That would be hard I think. Feel free to investigate it. I would > rather recommend you use RSpec's --heckle switch if you want to know > how good your examples are. Coverage is overrated. > > See http://seattlerb.rubyforge.org/heckle/ for more info. Thanks, I'll give Heckle a look. Aslak > > > Cheers > > Ian > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070620/f0857b3f/attachment.html From aslak.hellesoy at gmail.com Wed Jun 20 08:01:36 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 20 Jun 2007 14:01:36 +0200 Subject: [rspec-users] Something like rcov but more explicit? In-Reply-To: References: <8d961d900706181051s7ca175d1gc000fb1710cd110d@mail.gmail.com> Message-ID: <8d961d900706200501j121424b2mc5894bace8adeb20@mail.gmail.com> On 6/20/07, Ian Leitch wrote: > On 18/06/07, aslak hellesoy wrote: > > On 6/18/07, Ian Leitch wrote: > > > Hey list, > > > > > > Does anything exist that can show me which lines are explicitly tested? > RCov > > > is great, but it doesn't really give a sense of _actual_ coverage, > indeed, > > > there is no guarantee that functions executed were in fact called as the > > > result of a line being tested. > > > > > > > Why do you care whether a line was executed directly (spec->code) or > > indirectly (spec->code->code->code)? > > > Just because a spec executed a function coincidentally and it generates some > kind of error (most likely semantic), there is no guarantee that the code > that made the call will also trip up. Are you saying that an 'explicit' call to that method would give you confidence about how the code that made the call will behave? In the scenario you're describing this 'intermediate' code isn't even involved. Maybe I'm misunderstanding what you're trying to do. Some sample code would help. I'm also sceptical about having a goal along the lines of "all methods in our code must be invoked explicitly by specs". It's a very low level (too low level IMO) way of approaching the overall behaviour of your app. Aslak > Therefore, rcov doesn't really tell me > to what extent my code base is explicitly tested. > > > > I know nothing of the rspec internals, but would a simple list of > executed > > > lines be a relatively simple feature to add? > > > > > > > That would be hard I think. Feel free to investigate it. I would > > rather recommend you use RSpec's --heckle switch if you want to know > > how good your examples are. Coverage is overrated. > > > > See http://seattlerb.rubyforge.org/heckle/ for more info. > > Thanks, I'll give Heckle a look. > > > Aslak > > > > > Cheers > > > Ian > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From moses.hohman at gmail.com Wed Jun 20 11:19:30 2007 From: moses.hohman at gmail.com (Moses Hohman) Date: Wed, 20 Jun 2007 08:19:30 -0700 Subject: [rspec-users] Testing for cross site scripting, etc. In-Reply-To: <4b430c8f0706191514i44568529y1fba15b1bb8b5b1f@mail.gmail.com> References: <20070619133958.ce3x9xe9wkoc0swk@lcgalaska.com> <4b430c8f0706191514i44568529y1fba15b1bb8b5b1f@mail.gmail.com> Message-ID: <425146b90706200819p2643aeb7v364a105042f304e2@mail.gmail.com> We wrote a custom rspec matcher for this, example: response.should contain_escaped("user name") The custom matcher first checks that the escaped text appears in the page (so you know you're actually checking for something that is really there) and then checks that the unescaped text does not appear in the page. It also makes sure that the text you've provided actually contains something that can be escaped in it, again failing on bogus examples. I'd be happy to release it somehow. Failing that here's the code for it: module CDD module CustomRspecMatchers class ContainEscaped include ERB::Util attr_reader :failure_message def initialize(unescaped) @unescaped = unescaped @escaped = html_escape(@unescaped) end def matches?(response) if @escaped == @unescaped @failure_message = "no HTML in \"#{@unescaped}\"" return false elsif response.body =~ %r(#{Regexp.escape(@unescaped)}) @failure_message = "unescaped \"#{@unescaped}\" found in page" return false elsif response.body !~ %r(#{Regexp.escape(@escaped)}) @failure_message = "escaped \"#{@unescaped}\" not found in page" return false else return true end end def negative_failure_message raise "you can't use should_not with the contain_escaped matcher" end end def contain_escaped(unescaped) ContainEscaped.new(unescaped) end end end That's just sitting inside spec_helper.rb, and then of course we include CDD::CustomRspecMatchers (I guess that should be CustomRSpecMatchers) inside the Spec::Runner.configure do block. Any improvement suggestions welcome. CDD is the name of our company (www.collaborativedrug.com), in case that wasn't clear. Moses On 6/19/07, Courtenay wrote: > > On 6/19/07, barsalou wrote: > > On 6/18/07, aslak hellesoy wrote: > > > On 6/19/07, barsalou wrote: > > > > Being new to testing and ruby, are there "standard" tests that can > be > > > > done that test for things like cross site scripting and friends? > > > > > > > > > > I suppose you mean http://en.wikipedia.org/wiki/Cross-site_scripting(XSS) > > > > > > XSS happens *in* the browser, where Ruby doesn't run (yet), so I'm not > > > sure how you think RSpec is relevant. Unless you want to use Watir or > > > Selenium-RC, which allows you to talk to a browser from Ruby (and > > > RSpec) > > > > I'd say they want to assert, in the views, that user-generated input > > does not render script tags. > > > > Like if I set my user info to be it > > should appear in the view as <script>alert and so on. > > > > Maybe in the view spec > > > > @user.stub!(:info).and_return('') > > response.should not_have_tag('script') > > > > Do the two lines above really test anything? or were you just showing > > an example of what I might do? > > They're an approximate example. Your code will look slightly different. > > > Also, the fact that you wrote the dumbass plugin makes me wonder why > > <%=h user.name =%> is needed? I get what your doing, but why doesn't > > escaping happen in the form? Aren't there protections already > > built-in, especially in rails, to escape form fields? > > That's what <%=h is. Html escaping. It's easy to forget. Note there > is no trailing = > > > Can you do this same sort of thing for SQL injection problem as > well? Mike B. > > Rails has inbuilt injection safety, provided you follow the suggested > practise. I suggest you read up on it before we revoke your rails > license: http://manuals.rubyonrails.com/read/chapter/40 :) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070620/9946d971/attachment-0001.html From scott at tynerblain.com Wed Jun 20 15:04:16 2007 From: scott at tynerblain.com (Scott Sehlhorst) Date: Wed, 20 Jun 2007 14:04:16 -0500 Subject: [rspec-users] Something like rcov but more explicit? In-Reply-To: <8d961d900706200501j121424b2mc5894bace8adeb20@mail.gmail.com> References: <8d961d900706181051s7ca175d1gc000fb1710cd110d@mail.gmail.com> <8d961d900706200501j121424b2mc5894bace8adeb20@mail.gmail.com> Message-ID: <4f34789a0706201204ja114b5cw64ac5482ec8b8219@mail.gmail.com> > > I'm also sceptical about having a goal along the lines of "all methods in > our code must be invoked explicitly by specs". It's a very low level (too > low level IMO) way of approaching the overall behaviour of your app. > > Aslak I would also add that it violates some principals of encapsulation. If you expose an object to perform an action, then an rspec test should interact with that object to test those actions. And only those actions exposed by the object. Unit tests should be the vehicle for testing any methods relied upon by the "outer object" to accomplish the action. I am very new to rspec (and rails), but my interpretation of BDD is that it should honor principles of encapsulation, and unit testing should be used for low-level testing. If this is not the spirit of rspec, I would love to know how other people approach it - then I can fix my misperceptions. my two cents Scott Sehlhorst http://tynerblain.com/blog -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070620/3f2eb2e4/attachment.html From port001 at gmail.com Wed Jun 20 16:29:48 2007 From: port001 at gmail.com (Ian Leitch) Date: Wed, 20 Jun 2007 21:29:48 +0100 Subject: [rspec-users] Something like rcov but more explicit? In-Reply-To: <4f34789a0706201204ja114b5cw64ac5482ec8b8219@mail.gmail.com> References: <8d961d900706181051s7ca175d1gc000fb1710cd110d@mail.gmail.com> <8d961d900706200501j121424b2mc5894bace8adeb20@mail.gmail.com> <4f34789a0706201204ja114b5cw64ac5482ec8b8219@mail.gmail.com> Message-ID: I appreciate that testing every single line off code isn't the approach of BDD, and indeed that isn't my goal, although at the same time I'd like to be able to "see" with coverage reports just to what extent the code base is explicitly tested. Say I had ViewA that uses HelperA and ViewB that uses HelperB, ViewA and HelperA both have specs, as does ViewB, however HelperB does not. With an rcov coverage report this isn't visible, what I'm after is something that can tell me "HelperB was executed during the running of ViewB, but its behavior was not explicitly specified." It'd like to look into seeing if this is possible with rspec, I'll have to try convince my boss to allow me to devote some time to it. Cheers Ian On 20/06/07, Scott Sehlhorst wrote: > > I'm also sceptical about having a goal along the lines of "all methods in > > our code must be invoked explicitly by specs". It's a very low level (too > > low level IMO) way of approaching the overall behaviour of your app. > > > > Aslak > > > I would also add that it violates some principals of encapsulation. If > you expose an object to perform an action, then an rspec test should > interact with that object to test those actions. And only those actions > exposed by the object. Unit tests should be the vehicle for testing any > methods relied upon by the "outer object" to accomplish the action. > > I am very new to rspec (and rails), but my interpretation of BDD is that > it should honor principles of encapsulation, and unit testing should be used > for low-level testing. If this is not the spirit of rspec, I would love to > know how other people approach it - then I can fix my misperceptions. > > my two cents > Scott Sehlhorst > http://tynerblain.com/blog > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070620/c3f6e8a0/attachment.html From aslak.hellesoy at gmail.com Wed Jun 20 18:23:22 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 21 Jun 2007 00:23:22 +0200 Subject: [rspec-users] Something like rcov but more explicit? In-Reply-To: References: <8d961d900706181051s7ca175d1gc000fb1710cd110d@mail.gmail.com> <8d961d900706200501j121424b2mc5894bace8adeb20@mail.gmail.com> <4f34789a0706201204ja114b5cw64ac5482ec8b8219@mail.gmail.com> Message-ID: <8d961d900706201523t79347a90n1cecb3e7ad82406a@mail.gmail.com> On 6/20/07, Ian Leitch wrote: > I appreciate that testing every single line off code isn't the approach of > BDD, and indeed that isn't my goal, although at the same time I'd like to be > able to "see" with coverage reports just to what extent the code base is > explicitly tested. > > Say I had ViewA that uses HelperA and ViewB that uses HelperB, ViewA and > HelperA both have specs, as does ViewB, however HelperB does not. With an > rcov coverage report this isn't visible, what I'm after is something that > can tell me "HelperB was executed during the running of ViewB, but its > behavior was not explicitly specified." > If you want to verify how well tested your code is you should look into branch coverage (RCov first, then Heckle). It's irrelevant where a method invocation originates from. Aslak > It'd like to look into seeing if this is possible with rspec, I'll have to > try convince my boss to allow me to devote some time to it. > > Cheers > Ian > > > On 20/06/07, Scott Sehlhorst wrote: > > > > > > > I'm also sceptical about having a goal along the lines of "all methods > in our code must be invoked explicitly by specs". It's a very low level (too > low level IMO) way of approaching the overall behaviour of your app. > > > > > > Aslak > > > > > > I would also add that it violates some principals of encapsulation. If > you expose an object to perform an action, then an rspec test should > interact with that object to test those actions. And only those actions > exposed by the object. Unit tests should be the vehicle for testing any > methods relied upon by the "outer object" to accomplish the action. > > > > I am very new to rspec (and rails), but my interpretation of BDD is that > it should honor principles of encapsulation, and unit testing should be used > for low-level testing. If this is not the spirit of rspec, I would love to > know how other people approach it - then I can fix my misperceptions. > > > > my two cents > > Scott Sehlhorst > > http://tynerblain.com/blog > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From barjunk at attglobal.net Wed Jun 20 18:27:17 2007 From: barjunk at attglobal.net (barsalou) Date: Wed, 20 Jun 2007 14:27:17 -0800 Subject: [rspec-users] Rspec for the svn-less Message-ID: <20070620142717.n70yw2whwk004w8o@lcgalaska.com> Here is a short bash script I wrote to install rspec if your just using the tarballs like me. I probably should have written it in ruby, but there it is: #!/bin/bash RSPEC=rspec-1.0.4-pre-release.tgz RSPECRAILS=rspec_on_rails-1.0.4-pre-release.tgz [ -z "$1" ] && { echo echo "You must include a pathname" echo exit 1 } if [ -d $1/vendor/plugins ]; then cd $1/vendor/plugins else echo "path: $1/vendor/plugins doesn't exist" exit 1 fi tar zxvf $RSPEC tar zxvf $RSPECRAILS mv `basename $RSPEC -pre-release.tgz` rspec mv `basename $RSPECRAILS -pre-release.tgz` rspec_on_rails cd ../../ script/generate rspec ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From dchelimsky at gmail.com Wed Jun 20 18:32:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 20 Jun 2007 17:32:40 -0500 Subject: [rspec-users] Rspec for the svn-less In-Reply-To: <20070620142717.n70yw2whwk004w8o@lcgalaska.com> References: <20070620142717.n70yw2whwk004w8o@lcgalaska.com> Message-ID: <57c63afe0706201532l21437847kd1668a1d53b92f76@mail.gmail.com> On 6/20/07, barsalou wrote: > Here is a short bash script I wrote to install rspec if your just using > the tarballs like me. I probably should have written it in ruby, but > there it is: > > #!/bin/bash > > RSPEC=rspec-1.0.4-pre-release.tgz > RSPECRAILS=rspec_on_rails-1.0.4-pre-release.tgz > [ -z "$1" ] && { > echo > echo "You must include a pathname" > echo > exit 1 > } > > if [ -d $1/vendor/plugins ]; then > cd $1/vendor/plugins > else > echo "path: $1/vendor/plugins doesn't exist" > exit 1 > fi > tar zxvf $RSPEC > tar zxvf $RSPECRAILS > mv `basename $RSPEC -pre-release.tgz` rspec > mv `basename $RSPECRAILS -pre-release.tgz` rspec_on_rails > > cd ../../ > script/generate rspec This works only for the pre-release versions that were not distributed publicly. How about getting rid of all the pre-release stuff and parameterizing the version? Otherwise - thanks! > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From barjunk at attglobal.net Wed Jun 20 19:36:27 2007 From: barjunk at attglobal.net (barsalou) Date: Wed, 20 Jun 2007 15:36:27 -0800 Subject: [rspec-users] Rspec for the svn-less In-Reply-To: <57c63afe0706201532l21437847kd1668a1d53b92f76@mail.gmail.com> References: <20070620142717.n70yw2whwk004w8o@lcgalaska.com> <57c63afe0706201532l21437847kd1668a1d53b92f76@mail.gmail.com> Message-ID: <20070620153627.zbfcrzznj4k80okk@lcgalaska.com> I'll redo it in ruby and post that. Mike B. Quoting David Chelimsky : > On 6/20/07, barsalou wrote: >> Here is a short bash script I wrote to install rspec if your just using >> the tarballs like me. I probably should have written it in ruby, but >> there it is: >> >> #!/bin/bash >> >> RSPEC=rspec-1.0.4-pre-release.tgz >> RSPECRAILS=rspec_on_rails-1.0.4-pre-release.tgz >> [ -z "$1" ] && { >> echo >> echo "You must include a pathname" >> echo >> exit 1 >> } >> >> if [ -d $1/vendor/plugins ]; then >> cd $1/vendor/plugins >> else >> echo "path: $1/vendor/plugins doesn't exist" >> exit 1 >> fi >> tar zxvf $RSPEC >> tar zxvf $RSPECRAILS >> mv `basename $RSPEC -pre-release.tgz` rspec >> mv `basename $RSPECRAILS -pre-release.tgz` rspec_on_rails >> >> cd ../../ >> script/generate rspec > > This works only for the pre-release versions that were not > distributed publicly. > > How about getting rid of all the pre-release stuff and parameterizing > the version? > > Otherwise - thanks! > >> >> >> ---------------------------------------------------------------- >> This message was sent using IMP, the Internet Messaging Program. >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From port001 at gmail.com Thu Jun 21 04:53:03 2007 From: port001 at gmail.com (Ian Leitch) Date: Thu, 21 Jun 2007 09:53:03 +0100 Subject: [rspec-users] should_receive stubs methods? Message-ID: Hey, I'm using rspec and rails and have a spec that tests if a before_filter is executed, I also have a spec that tests if a method called by the filter is executed. It appears however that when I should_receive something, it is no longer actually called when I fire the http request. I'm not sure how, or where exactly I should manually fire the filter, either before or after the http request sounds wrong. An option to should_receive that passes on the invocation would be helpful yet I see nothing relevant in the documentation. Cheers Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070621/4b692882/attachment.html From dchelimsky at gmail.com Thu Jun 21 08:38:30 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 21 Jun 2007 07:38:30 -0500 Subject: [rspec-users] should_receive stubs methods? In-Reply-To: References: Message-ID: <57c63afe0706210538t5a58a709y1a9cfcb3051b15d@mail.gmail.com> On 6/21/07, Ian Leitch wrote: > Hey, > > I'm using rspec and rails and have a spec that tests if a before_filter is > executed, I also have a spec that tests if a method called by the filter is > executed. It appears however that when I should_receive something, it is no > longer actually called when I fire the http request. I'm not sure how, or > where exactly I should manually fire the filter, either before or after the > http request sounds wrong. An option to should_receive that passes on the > invocation would be helpful yet I see nothing relevant in the documentation. Sorry Ian, but this is not supported, nor will it likely ever be supported in RSpec's mocking framework because it encourages coupling concepts together in examples. Expressing the expectation that this method gets called should be separate from examples that deal with the results of actually calling the method. If that doesn't make sense to you, please post the actual examples and code that you have and we can discuss them. Cheers, David > > Cheers > Ian > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jonathan at parkerhill.com Thu Jun 21 09:48:16 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Thu, 21 Jun 2007 09:48:16 -0400 Subject: [rspec-users] should_receive stubs methods? In-Reply-To: <57c63afe0706210538t5a58a709y1a9cfcb3051b15d@mail.gmail.com> References: <57c63afe0706210538t5a58a709y1a9cfcb3051b15d@mail.gmail.com> Message-ID: <9AFEB5C4-DBFA-4F21-B45E-DE6B8488FE4A@parkerhill.com> In the case where the filter sets a variable (e.g. @value) used in the controller action, you cannot mock the filter. You're then forced to mock any methods the filter calls. To address this I've tried to add a method in my spec that aggregates the filter mocks and stubs. The problem here is if the filter calls a method, and then the action calls the same one, I have to put things like .twice in the stub (the "should" usage count does not increment), which breaks the modularity. (Did someone say "getting too intimate"? :) linoj On Jun 21, 2007, at 8:38 AM, David Chelimsky wrote: > On 6/21/07, Ian Leitch wrote: >> Hey, >> >> I'm using rspec and rails and have a spec that tests if a >> before_filter is >> executed, I also have a spec that tests if a method called by the >> filter is >> executed. It appears however that when I should_receive something, >> it is no >> longer actually called when I fire the http request. I'm not sure >> how, or >> where exactly I should manually fire the filter, either before or >> after the >> http request sounds wrong. An option to should_receive that passes >> on the >> invocation would be helpful yet I see nothing relevant in the >> documentation. > > Sorry Ian, but this is not supported, nor will it likely ever be > supported in RSpec's mocking framework because it encourages coupling > concepts together in examples. Expressing the expectation that this > method gets called should be separate from examples that deal with the > results of actually calling the method. If that doesn't make sense to > you, please post the actual examples and code that you have and we can > discuss them. > > Cheers, > David > >> >> Cheers >> Ian >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Jun 21 09:51:26 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 21 Jun 2007 08:51:26 -0500 Subject: [rspec-users] should_receive stubs methods? In-Reply-To: <9AFEB5C4-DBFA-4F21-B45E-DE6B8488FE4A@parkerhill.com> References: <57c63afe0706210538t5a58a709y1a9cfcb3051b15d@mail.gmail.com> <9AFEB5C4-DBFA-4F21-B45E-DE6B8488FE4A@parkerhill.com> Message-ID: <57c63afe0706210651uc297f6ep9cd9604c8bf0807a@mail.gmail.com> On 6/21/07, Jonathan Linowes wrote: > In the case where the filter sets a variable (e.g. @value) used in > the controller action, you cannot mock the filter. You're then forced > to mock any methods the filter calls. > > To address this I've tried to add a method in my spec that aggregates > the filter mocks and stubs. The problem here is if the filter calls a > method, and then the action calls the same one, I have to put things > like .twice in the stub (the "should" usage count does not > increment), which breaks the modularity. (Did someone say "getting > too intimate"? :) Use stubs! or should_receive(:blah).any_number_of_times. > > linoj > > > On Jun 21, 2007, at 8:38 AM, David Chelimsky wrote: > > > On 6/21/07, Ian Leitch wrote: > >> Hey, > >> > >> I'm using rspec and rails and have a spec that tests if a > >> before_filter is > >> executed, I also have a spec that tests if a method called by the > >> filter is > >> executed. It appears however that when I should_receive something, > >> it is no > >> longer actually called when I fire the http request. I'm not sure > >> how, or > >> where exactly I should manually fire the filter, either before or > >> after the > >> http request sounds wrong. An option to should_receive that passes > >> on the > >> invocation would be helpful yet I see nothing relevant in the > >> documentation. > > > > Sorry Ian, but this is not supported, nor will it likely ever be > > supported in RSpec's mocking framework because it encourages coupling > > concepts together in examples. Expressing the expectation that this > > method gets called should be separate from examples that deal with the > > results of actually calling the method. If that doesn't make sense to > > you, please post the actual examples and code that you have and we can > > discuss them. > > > > Cheers, > > David > > > >> > >> Cheers > >> Ian > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tom at hobocentral.net Thu Jun 21 09:37:57 2007 From: tom at hobocentral.net (Tom Locke) Date: Thu, 21 Jun 2007 14:37:57 +0100 Subject: [rspec-users] (no subject) Message-ID: <279507FE-6F5D-427D-AD74-EF12AFDAD128@hobocentral.net> Hi, Not sure if this is the right place for general questions on BDD style, but here goes... I have a class which behaves almost like a big function - you always instantiate it with a bunch of args, and call one of a couple of methods to get the results back. BDD style seems to like a separate describe block for each instantiation of the class under test. In this case that would mean a ton of describe blocks, each with just one it "..." do block (terminology??). That seems rather verbose. What would the recommended style be? And the meta question - where should I go to educate myself on this stuff? Thanks Tom From tom at hobocentral.net Thu Jun 21 09:31:42 2007 From: tom at hobocentral.net (Tom Locke) Date: Thu, 21 Jun 2007 14:31:42 +0100 Subject: [rspec-users] Testing a Rails plugin Message-ID: <09FB1BA7-F3D7-43A6-BB44-C1EA3E097579@hobocentral.net> Hi OK it looks like I'm a convert to BDD :-) Well in principle at least - let's see how it turns out. I've just set up a test environment for the Hobo plugin according to this guide: http://www.pluginaweek.org/2006/11/24/plugin-tip-of-the-week- testing-your-plugins-the-right-way/ And then adapted the setup to work with RSpec In the plugin I now have: /spec /spec/unit -- all my specs are here in a hierarchy that mirrors my plugin's lib directory /spec/rails_root -- a complete Rails app, minus a few things /spec/spec.opts /spec/spec_helper.rb -- which looks like this: -------------- ENV['RAILS_ENV'] ||= 'mysql' require File.dirname(__FILE__) + '/rails_root/config/environment.rb' # Run the migrations ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate") require 'spec/rails' Spec::Runner.configure do |config| config.use_transactional_fixtures = true config.use_instantiated_fixtures = false config.fixture_path = File.dirname(__FILE__) + "/fixtures/" config.before(:each, :behaviour_type => :controller) do raise_controller_errors end end -------------- It all seems to be working, but I haven't kicked the tires to hard yet. Just thought I'd run this setup by you for comments. Tom From jmckible at gmail.com Thu Jun 21 10:24:16 2007 From: jmckible at gmail.com (Jordan McKible) Date: Thu, 21 Jun 2007 10:24:16 -0400 Subject: [rspec-users] it_should_behave_like Message-ID: <2f5c856e0706210724o3e72e75ej3469056be793e71a@mail.gmail.com> I'm trying to use it_should_behave_like, and something seems to be wonky with the syntax. When I add :shared=>true, the DSL complains that the next line is the fixture declaration: /vendor/plugins/rspec/lib/spec/dsl/behaviour_eval.rb:137:in `method_missing': undefined method `fixtures' for # (NoMethodError) Here's the spec http://pastie.caboo.se/72287 Am I using it_should_behave_like properly? Am I making a separate mistake? I have RSpec setup as a svn external (currently rev2101). Thanks, Jordan http://jordan.mckible.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070621/f5da66f8/attachment.html From jonathan at parkerhill.com Thu Jun 21 10:25:50 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Thu, 21 Jun 2007 10:25:50 -0400 Subject: [rspec-users] should_receive stubs methods? In-Reply-To: <57c63afe0706210651uc297f6ep9cd9604c8bf0807a@mail.gmail.com> References: <57c63afe0706210538t5a58a709y1a9cfcb3051b15d@mail.gmail.com> <9AFEB5C4-DBFA-4F21-B45E-DE6B8488FE4A@parkerhill.com> <57c63afe0706210651uc297f6ep9cd9604c8bf0807a@mail.gmail.com> Message-ID: cool! On Jun 21, 2007, at 9:51 AM, David Chelimsky wrote: > On 6/21/07, Jonathan Linowes wrote: >> In the case where the filter sets a variable (e.g. @value) used in >> the controller action, you cannot mock the filter. You're then forced >> to mock any methods the filter calls. >> >> To address this I've tried to add a method in my spec that aggregates >> the filter mocks and stubs. The problem here is if the filter calls a >> method, and then the action calls the same one, I have to put things >> like .twice in the stub (the "should" usage count does not >> increment), which breaks the modularity. (Did someone say "getting >> too intimate"? :) > > Use stubs! or should_receive(:blah).any_number_of_times. > >> >> linoj >> >> >> On Jun 21, 2007, at 8:38 AM, David Chelimsky wrote: >> >>> On 6/21/07, Ian Leitch wrote: >>>> Hey, >>>> >>>> I'm using rspec and rails and have a spec that tests if a >>>> before_filter is >>>> executed, I also have a spec that tests if a method called by the >>>> filter is >>>> executed. It appears however that when I should_receive something, >>>> it is no >>>> longer actually called when I fire the http request. I'm not sure >>>> how, or >>>> where exactly I should manually fire the filter, either before or >>>> after the >>>> http request sounds wrong. An option to should_receive that passes >>>> on the >>>> invocation would be helpful yet I see nothing relevant in the >>>> documentation. >>> >>> Sorry Ian, but this is not supported, nor will it likely ever be >>> supported in RSpec's mocking framework because it encourages >>> coupling >>> concepts together in examples. Expressing the expectation that this >>> method gets called should be separate from examples that deal >>> with the >>> results of actually calling the method. If that doesn't make >>> sense to >>> you, please post the actual examples and code that you have and >>> we can >>> discuss them. >>> >>> Cheers, >>> David >>> >>>> >>>> Cheers >>>> Ian >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Jun 21 10:26:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 21 Jun 2007 09:26:15 -0500 Subject: [rspec-users] (no subject) In-Reply-To: <279507FE-6F5D-427D-AD74-EF12AFDAD128@hobocentral.net> References: <279507FE-6F5D-427D-AD74-EF12AFDAD128@hobocentral.net> Message-ID: <57c63afe0706210726y2752f486t346c772dd3c7b532@mail.gmail.com> On 6/21/07, Tom Locke wrote: > Hi, > > Not sure if this is the right place for general questions on BDD > style, but here goes... > > I have a class which behaves almost like a big function - you always > instantiate it with a bunch of args, and call one of a couple of > methods to get the results back. > > BDD style seems to like a separate describe block for each > instantiation of the class under test. Only when you're describing that object in different starting states. If there's only one starting state, you can create one of them before(:each) example: before(:each) { @thing = Thing.new } > In this case that would mean a > ton of describe blocks, each with just one it "..." do block > (terminology??). That seems rather verbose. What would the > recommended style be? If you need the object in different starting states, you've got a few options. You could go w/ the context approach you described above in which you have a different description for each starting state. You could also make a helper method (or a couple of them) in a module: module ExampleHelpers def create_thing ... end end describe "Stuff" do include ExampleHelpers before(:each) { @thing = create_thing } ... end Another is to use a shared behaviour: describe "All Things", :shared => true do before(:each) { @thing = Thing.new(with, a, bunch, of, args) } end describe "One Thing" do it_should_behave_like "All Things" # now you can access @thing in each example end > And the meta question - where should I go to educate myself on this > stuff? This is a good place. Here are some blogs: http://blog.davidchelimsky.net http://blog.daveastels.com/ http://blog.aslakhellesoy.com/ http://dannorth.net/ Another list is testdrivendevelopment at yahoogroups.com. BDD started off as TDD with more focus on behaviour, but serious TDD'ers (who live on that list) know better (they were already focusing on behaviour). Cheers, David > > Thanks > > Tom > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Thu Jun 21 11:51:32 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 21 Jun 2007 16:51:32 +0100 Subject: [rspec-users] [JOB] Web Application Developer Message-ID: <34BD19EC-90BD-470C-B9CB-0D440792BD5C@ashleymoran.me.uk> Hi all, I work for Codeweavers.net - not to be confused with the US CodeWeavers of CrossOver fame. We produce enterprise software, mainly for the finance sector. We are looking for a developer to take on a young project that I started. I'm becoming the company's senior network admin for the next 12 months at least, so we need someone to eventually take over responsibility for the site. It's a pretty tidy project for the most part, thoroughly tested with RSpec and decent MVC separation. No legacy code here! We are looking for the following in candidates: * experience with OO programming and modelling * understanding of relational databases (we use PostgreSQL) * rabid enthusiasm for testing, BDD and automation Experience of FreeBSD and Mac OS X (from a Unix perspective) would be handy. Being a Capistrano whizz would be helpful. None of this is essential though; we are happy to take on a junior developer if you are enthusiastic and willing to take on new things. The job is permanent, full time, and on-site. If you are interested, please reply to this email and I will forward your details to the relevant parties. Ashley From tom at hobocentral.net Thu Jun 21 11:59:36 2007 From: tom at hobocentral.net (Tom Locke) Date: Thu, 21 Jun 2007 16:59:36 +0100 Subject: [rspec-users] (no subject) In-Reply-To: <57c63afe0706210726y2752f486t346c772dd3c7b532@mail.gmail.com> References: <279507FE-6F5D-427D-AD74-EF12AFDAD128@hobocentral.net> <57c63afe0706210726y2752f486t346c772dd3c7b532@mail.gmail.com> Message-ID: <7C4FC1A6-C14B-4792-BC9C-3E3BB8F0C2E5@hobocentral.net> Thanks David, I'm not sure this covers my situation though - I'll give a bit more detail The class I'm specing is the DRYML compiler -- yep I'm doing retroactive specing I'm afraid, which is maybe why things don't fit too neatly. You instantiate the class, passing the DRYML source, and then call process_src which converts the DRYML to regular ERB, and returns that as a string. At the moment I'm doing stuff like this: describe Template do it "should compile tag calls to method calls" do compile_dryml("").should == "<%= foo() %>" end it "should compile attributes as keyword parameters" do compile_dryml("").should == '<%= foo({:a => "1"}) %>' end end Those compile_dryml calls each instantiate a template with a different state. I really don't want to have a separate describe block for each example - there could be hundreds. Is this bad form? Tom From dchelimsky at gmail.com Thu Jun 21 12:15:06 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 21 Jun 2007 11:15:06 -0500 Subject: [rspec-users] (no subject) In-Reply-To: <7C4FC1A6-C14B-4792-BC9C-3E3BB8F0C2E5@hobocentral.net> References: <279507FE-6F5D-427D-AD74-EF12AFDAD128@hobocentral.net> <57c63afe0706210726y2752f486t346c772dd3c7b532@mail.gmail.com> <7C4FC1A6-C14B-4792-BC9C-3E3BB8F0C2E5@hobocentral.net> Message-ID: <57c63afe0706210915y1b2c6197v810730b72d2421c2@mail.gmail.com> On 6/21/07, Tom Locke wrote: > Thanks David, > > I'm not sure this covers my situation though - I'll give a bit more > detail > > The class I'm specing is the DRYML compiler -- yep I'm doing > retroactive specing I'm afraid, which is maybe why things don't fit > too neatly. > > You instantiate the class, passing the DRYML source, and then call > process_src which converts the DRYML to regular ERB, and returns that > as a string. > > At the moment I'm doing stuff like this: > > describe Template do > > it "should compile tag calls to method calls" do > compile_dryml("").should == "<%= foo() %>" > end > > it "should compile attributes as keyword parameters" do > compile_dryml("").should == '<%= foo({:a => "1"}) %>' > end > > end > > Those compile_dryml calls each instantiate a template with a > different state. I really don't want to have a separate describe > block for each example - there could be hundreds. Is this bad form? Not at all. Perfectly sane. > > Tom > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Thu Jun 21 12:30:13 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 21 Jun 2007 12:30:13 -0400 Subject: [rspec-users] include keyword in describe block Message-ID: <81CF55FB-209B-459A-A7BD-6CCB922FB84F@railsnewbie.com> How is using include in a describe block different than the typical "include" keyword in Ruby? Am I right in believing that the describe block is class_eval'ed? Scott From mailing_lists at railsnewbie.com Thu Jun 21 12:43:40 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 21 Jun 2007 12:43:40 -0400 Subject: [rspec-users] it_should_behave_like In-Reply-To: <2f5c856e0706210724o3e72e75ej3469056be793e71a@mail.gmail.com> References: <2f5c856e0706210724o3e72e75ej3469056be793e71a@mail.gmail.com> Message-ID: I think a shared describe block can only take two arguments: 1. a string - the name of the shared behavior 2. the parameter saying that it is shared (:shared => true) Let me know if I'm wrong on this. Scott On Jun 21, 2007, at 10:24 AM, Jordan McKible wrote: > I'm trying to use it_should_behave_like, and something seems to be > wonky with the syntax. When I add :shared=>true, the DSL complains > that the next line is the fixture declaration: > > /vendor/plugins/rspec/lib/spec > /dsl/behaviour_eval.rb:137:in `method_missing': undefined method > `fixtures' for # (NoMethodError) > > Here's the spec http://pastie.caboo.se/72287 > > Am I using it_should_behave_like properly? Am I making a separate > mistake? I have RSpec setup as a svn external (currently rev2101). > > Thanks, > Jordan > http://jordan.mckible.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Thu Jun 21 12:52:44 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 21 Jun 2007 12:52:44 -0400 Subject: [rspec-users] it_should_behave_like In-Reply-To: <2f5c856e0706210724o3e72e75ej3469056be793e71a@mail.gmail.com> References: <2f5c856e0706210724o3e72e75ej3469056be793e71a@mail.gmail.com> Message-ID: <073427F5-5C97-4B77-8E30-059361CD47CE@railsnewbie.com> What is the shared behavior between these two? Do you want a valid, saved, and accepted contract to act like an unaccepted contract? Abstract out what is common between them, and then use that as the shared description. See: http://pastie.caboo.se/72413 Best, Scott On Jun 21, 2007, at 10:24 AM, Jordan McKible wrote: > I'm trying to use it_should_behave_like, and something seems to be > wonky with the syntax. When I add :shared=>true, the DSL complains > that the next line is the fixture declaration: > > /vendor/plugins/rspec/lib/spec > /dsl/behaviour_eval.rb:137:in `method_missing': undefined method > `fixtures' for # (NoMethodError) > > Here's the spec http://pastie.caboo.se/72287 > > Am I using it_should_behave_like properly? Am I making a separate > mistake? I have RSpec setup as a svn external (currently rev2101). > > Thanks, > Jordan > http://jordan.mckible.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Jun 21 12:55:06 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 21 Jun 2007 11:55:06 -0500 Subject: [rspec-users] it_should_behave_like In-Reply-To: <073427F5-5C97-4B77-8E30-059361CD47CE@railsnewbie.com> References: <2f5c856e0706210724o3e72e75ej3469056be793e71a@mail.gmail.com> <073427F5-5C97-4B77-8E30-059361CD47CE@railsnewbie.com> Message-ID: <57c63afe0706210955x67f0fbabp1be9cb667f0901d2@mail.gmail.com> On 6/21/07, Scott Taylor wrote: > > What is the shared behavior between these two? Do you want a valid, > saved, and accepted contract to act like an unaccepted contract? > Abstract out what is common between them, and then use that as the > shared description. > > See: http://pastie.caboo.se/72413 FYI - fixtures in shared behaviours don't ever get called. Just declare them in the behaviours that use them. > > Best, > > Scott > > > On Jun 21, 2007, at 10:24 AM, Jordan McKible wrote: > > > I'm trying to use it_should_behave_like, and something seems to be > > wonky with the syntax. When I add :shared=>true, the DSL complains > > that the next line is the fixture declaration: > > > > /vendor/plugins/rspec/lib/spec > > /dsl/behaviour_eval.rb:137:in `method_missing': undefined method > > `fixtures' for # (NoMethodError) > > > > Here's the spec http://pastie.caboo.se/72287 > > > > Am I using it_should_behave_like properly? Am I making a separate > > mistake? I have RSpec setup as a svn external (currently rev2101). > > > > Thanks, > > Jordan > > http://jordan.mckible.com > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jmckible at gmail.com Thu Jun 21 13:01:11 2007 From: jmckible at gmail.com (Jordan McKible) Date: Thu, 21 Jun 2007 13:01:11 -0400 Subject: [rspec-users] it_should_behave_like In-Reply-To: <57c63afe0706210955x67f0fbabp1be9cb667f0901d2@mail.gmail.com> References: <2f5c856e0706210724o3e72e75ej3469056be793e71a@mail.gmail.com> <073427F5-5C97-4B77-8E30-059361CD47CE@railsnewbie.com> <57c63afe0706210955x67f0fbabp1be9cb667f0901d2@mail.gmail.com> Message-ID: <2f5c856e0706211001v691cf38cw2338cf6c26695113@mail.gmail.com> Scott, putting aside semantics of the spec for a second, the code you posted generated the same error for me. According to David, it would seem this is because fixtures aren't called in shared behaviors. So a shared context is really just an easy way of adding a bunch of specs to another context? Does it follow that shared contexts shouldn't use before/after methods either? On 6/21/07, David Chelimsky wrote: > > On 6/21/07, Scott Taylor wrote: > > > > What is the shared behavior between these two? Do you want a valid, > > saved, and accepted contract to act like an unaccepted contract? > > Abstract out what is common between them, and then use that as the > > shared description. > > > > See: http://pastie.caboo.se/72413 > > FYI - fixtures in shared behaviours don't ever get called. Just > declare them in the behaviours that use them. > > > > > Best, > > > > Scott > > > > > > On Jun 21, 2007, at 10:24 AM, Jordan McKible wrote: > > > > > I'm trying to use it_should_behave_like, and something seems to be > > > wonky with the syntax. When I add :shared=>true, the DSL complains > > > that the next line is the fixture declaration: > > > > > > /vendor/plugins/rspec/lib/spec > > > /dsl/behaviour_eval.rb:137:in `method_missing': undefined method > > > `fixtures' for # (NoMethodError) > > > > > > Here's the spec http://pastie.caboo.se/72287 > > > > > > Am I using it_should_behave_like properly? Am I making a separate > > > mistake? I have RSpec setup as a svn external (currently rev2101). > > > > > > Thanks, > > > Jordan > > > http://jordan.mckible.com > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070621/7a285d97/attachment.html From mailing_lists at railsnewbie.com Thu Jun 21 13:03:45 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 21 Jun 2007 13:03:45 -0400 Subject: [rspec-users] it_should_behave_like In-Reply-To: <57c63afe0706210955x67f0fbabp1be9cb667f0901d2@mail.gmail.com> References: <2f5c856e0706210724o3e72e75ej3469056be793e71a@mail.gmail.com> <073427F5-5C97-4B77-8E30-059361CD47CE@railsnewbie.com> <57c63afe0706210955x67f0fbabp1be9cb667f0901d2@mail.gmail.com> Message-ID: On Jun 21, 2007, at 12:55 PM, David Chelimsky wrote: > On 6/21/07, Scott Taylor wrote: >> >> What is the shared behavior between these two? Do you want a valid, >> saved, and accepted contract to act like an unaccepted contract? >> Abstract out what is common between them, and then use that as the >> shared description. >> >> See: http://pastie.caboo.se/72413 > > FYI - fixtures in shared behaviours don't ever get called. Just > declare them in the behaviours that use them. > Ah. Good to know. Jordan: One option is to add specification blocks in the shared behavior, and then define the instance variables per description, i.e.: http://pastie.caboo.se/72418 Scott From mailing_lists at railsnewbie.com Thu Jun 21 13:28:24 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 21 Jun 2007 13:28:24 -0400 Subject: [rspec-users] it_should_behave_like In-Reply-To: <2f5c856e0706211001v691cf38cw2338cf6c26695113@mail.gmail.com> References: <2f5c856e0706210724o3e72e75ej3469056be793e71a@mail.gmail.com> <073427F5-5C97-4B77-8E30-059361CD47CE@railsnewbie.com> <57c63afe0706210955x67f0fbabp1be9cb667f0901d2@mail.gmail.com> <2f5c856e0706211001v691cf38cw2338cf6c26695113@mail.gmail.com> Message-ID: <0E925EFA-7A68-4AFD-801D-EE129F7D8B97@railsnewbie.com> On Jun 21, 2007, at 1:01 PM, Jordan McKible wrote: > Scott, putting aside semantics of the spec for a second, the code > you posted generated the same error for me. According to David, it > would seem this is because fixtures aren't called in shared behaviors. > > Does it follow that shared contexts shouldn't use before/after > methods either? I would imagine that it could be done, although I don't know about the implementation of rspec with this detail (so it may be the case that the before and after methods override those defined in the shared behavior...). Even if the before and after methods don't override those in the shared behavior, I would image that you should only define instance variables which would be shared among all the specs. Scott From ed.howland at gmail.com Thu Jun 21 13:32:15 2007 From: ed.howland at gmail.com (Ed Howland) Date: Thu, 21 Jun 2007 12:32:15 -0500 Subject: [rspec-users] Sqlite3, in-memory db and rspec_server Message-ID: <3df642dd0706211032i648ac73ds3e574ded8929b4e8@mail.gmail.com> Hi everyone. I can't get the above(subject line) combination to work. If I use a standard sqlite3 file db for the test db, and spec_server all the specs on my models pass. If I use an in-memory db for the test db, script/spec w/o spec_server, they all pass. But if I use in-memory and spec_server I get the following error: 1) ActiveRecord::StatementInvalid in 'User should be valid' ActiveRecord::StatementInvalid ./spec/models/user_spec.rb:5:in `new' ./spec/models/user_spec.rb:5: ./script/spec_server:23:in `run' ./script/spec_server:44: Line 5 is the User.new in the before clause. I have tried this on various versions of things. RSpec 1.0.5, Ubuntu 6.04, Rails 1.2.3, Sqlite 3.2.8, sqlit3-ruby 1.2.1 (gem) And on Ubuntu 7.04, Sqlite 3.3.13 Same results. Any ideas? Thanks Ed -- Ed Howland http://greenprogrammer.blogspot.com "The information transmitted is intended only for the person or entity to which it is addressed and may contain proprietary, confidential and/or legally privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers." From mailing_lists at railsnewbie.com Thu Jun 21 14:33:43 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 21 Jun 2007 14:33:43 -0400 Subject: [rspec-users] Sqlite3, in-memory db and rspec_server In-Reply-To: <3df642dd0706211032i648ac73ds3e574ded8929b4e8@mail.gmail.com> References: <3df642dd0706211032i648ac73ds3e574ded8929b4e8@mail.gmail.com> Message-ID: <17EDD5D4-29FD-48C2-A508-9799D57C819E@railsnewbie.com> On Jun 21, 2007, at 1:32 PM, Ed Howland wrote: > Hi everyone. > > I can't get the above(subject line) combination to work. If I use a > standard sqlite3 file db for the test db, and spec_server all the > specs on my models pass. If I use an in-memory db for the test db, > script/spec w/o spec_server, they all pass. But if I use in-memory and > spec_server I get the following error: > 1) > ActiveRecord::StatementInvalid in 'User should be valid' > ActiveRecord::StatementInvalid > ./spec/models/user_spec.rb:5:in `new' > ./spec/models/user_spec.rb:5: > ./script/spec_server:23:in `run' > ./script/spec_server:44: > > Line 5 is the User.new in the before clause. > > I have tried this on various versions of things. RSpec 1.0.5, Ubuntu > 6.04, Rails 1.2.3, Sqlite 3.2.8, sqlit3-ruby 1.2.1 (gem) > And on Ubuntu 7.04, Sqlite 3.3.13 > > Same results. > Any ideas? I've had the same problem before, even using the in-memory plugin (by Geoffrey Grosenbach). If my memory serves me right, I believe that something like the following is going on: the DRB server performs certain actions (like creating the test database schema) only once. Normally the test database schema would be recreated after every Test::Unit class / RSpec Behavior. Since the database schema isn't recreated when using the drb server, the in memory database no longer exists (go figure) after a bit (say, after the first few specs), and Rails throws an exception. I'd be interesting in seeing a full trace. Maybe we can get to the bottom of this bug. Best, Scott From ed.howland at gmail.com Thu Jun 21 14:54:18 2007 From: ed.howland at gmail.com (Ed Howland) Date: Thu, 21 Jun 2007 13:54:18 -0500 Subject: [rspec-users] Sqlite3, in-memory db and rspec_server In-Reply-To: <17EDD5D4-29FD-48C2-A508-9799D57C819E@railsnewbie.com> References: <3df642dd0706211032i648ac73ds3e574ded8929b4e8@mail.gmail.com> <17EDD5D4-29FD-48C2-A508-9799D57C819E@railsnewbie.com> Message-ID: <3df642dd0706211154w73494ee4tff7293d6a4513db0@mail.gmail.com> On 6/21/07, Scott Taylor wrote: > > On Jun 21, 2007, at 1:32 PM, Ed Howland wrote: > > > Hi everyone. > > > > I can't get the above(subject line) combination to work. If I use a > > standard sqlite3 file db for the test db, and spec_server all the > > specs on my models pass. If I use an in-memory db for the test db, > > script/spec w/o spec_server, they all pass. But if I use in-memory and > > spec_server I get the following error: > > 1) > > ActiveRecord::StatementInvalid in 'User should be valid' > > ActiveRecord::StatementInvalid > > ./spec/models/user_spec.rb:5:in `new' > > ./spec/models/user_spec.rb:5: > > ./script/spec_server:23:in `run' > > ./script/spec_server:44: > > > > Line 5 is the User.new in the before clause. > > > > I have tried this on various versions of things. RSpec 1.0.5, Ubuntu > > 6.04, Rails 1.2.3, Sqlite 3.2.8, sqlit3-ruby 1.2.1 (gem) > > And on Ubuntu 7.04, Sqlite 3.3.13 > > > > Same results. > > Any ideas? > > I've had the same problem before, even using the in-memory plugin (by > Geoffrey Grosenbach). > > If my memory serves me right, I believe that something like the > following is going on: the DRB server performs certain actions (like > creating the test database schema) only once. Normally the test > database schema would be recreated after every Test::Unit class / > RSpec Behavior. Since the database schema isn't recreated when using > the drb server, the in memory database no longer exists (go figure) > after a bit (say, after the first few specs), and Rails throws an > exception. > > I'd be interesting in seeing a full trace. Maybe we can get to the > bottom of this bug. Here it is: rspec -b spec/models/user_spec.rb F 1) ActiveRecord::StatementInvalid in 'User should be valid' ActiveRecord::StatementInvalid /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/sqlite_adapter.rb:360:in `table_structure' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/object/misc.rb:23:in `returning' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/sqlite_adapter.rb:359:in `table_structure' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/sqlite_adapter.rb:210:in `columns' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:763:in `columns' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:2060:in `attributes_from_column_definition_without_lock' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/locking/optimistic.rb:45:in `attributes_from_column_definition' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1502:in `initialize_without_callbacks' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:225:in `initialize' ./spec/models/user_spec.rb:5:in `new' ./spec/models/user_spec.rb:5: ./script/../vendor/plugins/rspec/lib/spec/dsl/composite_proc_builder.rb:16:in `instance_eval' ./script/../vendor/plugins/rspec/lib/spec/dsl/composite_proc_builder.rb:16:in `proc' ./script/../vendor/plugins/rspec/lib/spec/dsl/composite_proc_builder.rb:11:in `collect' ./script/../vendor/plugins/rspec/lib/spec/dsl/composite_proc_builder.rb:11:in `proc' ./script/../vendor/plugins/rspec/lib/spec/dsl/example.rb:63:in `instance_eval' ./script/../vendor/plugins/rspec/lib/spec/dsl/example.rb:63:in `setup_example' ./script/../vendor/plugins/rspec/lib/spec/dsl/example.rb:22:in `run' /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout' ./script/../vendor/plugins/rspec/lib/spec/dsl/example.rb:21:in `run' ./script/../vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:77:in `run' ./script/../vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in `each' ./script/../vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in `run' ./script/../vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:45:in `run_behaviours' ./script/../vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:44:in `each' ./script/../vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:44:in `run_behaviours' ./script/../vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:27:in `run'./script/../vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in `run' ./script/spec_server:23:in `run' /usr/local/lib/ruby/1.8/drb/drb.rb:1555:in `__send__' /usr/local/lib/ruby/1.8/drb/drb.rb:1555:in `perform_without_block' /usr/local/lib/ruby/1.8/drb/drb.rb:1515:in `perform' /usr/local/lib/ruby/1.8/drb/drb.rb:1589:in `main_loop' /usr/local/lib/ruby/1.8/drb/drb.rb:1585:in `loop' /usr/local/lib/ruby/1.8/drb/drb.rb:1585:in `main_loop' /usr/local/lib/ruby/1.8/drb/drb.rb:1581:in `start' /usr/local/lib/ruby/1.8/drb/drb.rb:1581:in `main_loop' /usr/local/lib/ruby/1.8/drb/drb.rb:1430:in `run' /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `start' /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `run' /usr/local/lib/ruby/1.8/drb/drb.rb:1347:in `initialize' /usr/local/lib/ruby/1.8/drb/drb.rb:1627:in `new' /usr/local/lib/ruby/1.8/drb/drb.rb:1627:in `start_service' ./script/spec_server:44: Finished in 0.009507 seconds 1 example, 1 failure > > Best, > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Ed Howland http://greenprogrammer.blogspot.com "The information transmitted is intended only for the person or entity to which it is addressed and may contain proprietary, confidential and/or legally privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers." From dj at collectiveinsight.net Thu Jun 21 15:17:19 2007 From: dj at collectiveinsight.net (David James) Date: Thu, 21 Jun 2007 14:17:19 -0500 Subject: [rspec-users] Testing two interdependent ActiveRecord models In-Reply-To: <9EB53500-25A5-49C8-93B7-245CF48D34CB@collectiveinsight.net> References: <9EB53500-25A5-49C8-93B7-245CF48D34CB@collectiveinsight.net> Message-ID: <99304812-8508-47AF-ADAA-6FDA5C6FAD57@collectiveinsight.net> Dear geeky, pay-your-debt-up-front-instead-of-later testing guru (tell me I'm wrong!)... I would appreciate if you (twould take a look at my message from a few weeks ago, since I didn't get any replies. Any comments would appreciated -- even if they are "you are barking up the wrong tree" -- or "you should read article ____ so that you can rephrase / rethink your question" Thanks, David On Jun 8, 2007, at 9:05 AM, David James wrote: > Hello, > > In my app, I'd like to test two model object objects that interact > with each other. (In my example, a Person can have Contributions.) > I guess you could say that I'm testing ActiveRecord associations. > For example, a Person has zero or many Contributions. A Contribution > has one or more People. This is the very basic version, but I think > it will illustrate the dependency. (In practice, I'm interested in > testing these associations because there is some extra logic going on > that needs testing.) > > Here are my observations / questions: > 1. Since there are two models, it doesn't seem quite right to make a > unit test for this, does it? > 2. There is an interaction between the two models. What is a good > way to test the interaction? Do I put some of the testing in > person_spec.rb and some in contribution_spec.rb? Or do I create some > sort of "interaction" spec? > 3. I don't think that an integration test makes sense, because I > don't want to test the controller and views. > 4. I wonder if mocks or stubs would make sense. I don't think I need > to stub out a particular method (i.e. credit card processing), > though. I'm pretty new to mocking, any advice or perspective would > be helpful. > > I would appreciate any feedback -- testing philosophy, and maybe some > hand waving, if you like. :) > > I would also be open to a refactoring / redesign if that will help > with testing. > > Thanks, > -David > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070621/ee5db6cf/attachment.html From mailing_lists at railsnewbie.com Thu Jun 21 15:21:01 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 21 Jun 2007 15:21:01 -0400 Subject: [rspec-users] Sqlite3, in-memory db and rspec_server In-Reply-To: <3df642dd0706211154w73494ee4tff7293d6a4513db0@mail.gmail.com> References: <3df642dd0706211032i648ac73ds3e574ded8929b4e8@mail.gmail.com> <17EDD5D4-29FD-48C2-A508-9799D57C819E@railsnewbie.com> <3df642dd0706211154w73494ee4tff7293d6a4513db0@mail.gmail.com> Message-ID: Here is the method definition in which it bails out: def table_structure(table_name) returning structure = execute("PRAGMA table_info(# {table_name})") do raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty? end end I'm not sure why you the string "could not find..." was not included in the error. Maybe different versions of rails? (I notice the line numbers are different...so you probably aren't using trunk). Maybe I should look into modifying the DRB server to not run rake db:test:prepare (and leave this for later on in the process)? (Any tips from core members would be nice ; ) ) Also, I wonder if it would be useful to have something like fixture data which doesn't get loaded into the DB. That is, preset data specified in YAML, which could be reloaded to it's original state after every specification block, but which would never touch the DB on invokation. It would certainly be faster (even faster than in memory databases), and would work just fine for validating AR objects. Scott On Jun 21, 2007, at 2:54 PM, Ed Howland wrote: > On 6/21/07, Scott Taylor wrote: >> >> On Jun 21, 2007, at 1:32 PM, Ed Howland wrote: >> >>> Hi everyone. >>> >>> I can't get the above(subject line) combination to work. If I use a >>> standard sqlite3 file db for the test db, and spec_server all the >>> specs on my models pass. If I use an in-memory db for the test db, >>> script/spec w/o spec_server, they all pass. But if I use in- >>> memory and >>> spec_server I get the following error: >>> 1) >>> ActiveRecord::StatementInvalid in 'User should be valid' >>> ActiveRecord::StatementInvalid >>> ./spec/models/user_spec.rb:5:in `new' >>> ./spec/models/user_spec.rb:5: >>> ./script/spec_server:23:in `run' >>> ./script/spec_server:44: >>> >>> Line 5 is the User.new in the before clause. >>> >>> I have tried this on various versions of things. RSpec 1.0.5, Ubuntu >>> 6.04, Rails 1.2.3, Sqlite 3.2.8, sqlit3-ruby 1.2.1 (gem) >>> And on Ubuntu 7.04, Sqlite 3.3.13 >>> >>> Same results. >>> Any ideas? >> >> I've had the same problem before, even using the in-memory plugin (by >> Geoffrey Grosenbach). >> >> If my memory serves me right, I believe that something like the >> following is going on: the DRB server performs certain actions (like >> creating the test database schema) only once. Normally the test >> database schema would be recreated after every Test::Unit class / >> RSpec Behavior. Since the database schema isn't recreated when using >> the drb server, the in memory database no longer exists (go figure) >> after a bit (say, after the first few specs), and Rails throws an >> exception. >> >> I'd be interesting in seeing a full trace. Maybe we can get to the >> bottom of this bug. > > Here it is: > rspec -b spec/models/user_spec.rb > F > > 1) > ActiveRecord::StatementInvalid in 'User should be valid' > ActiveRecord::StatementInvalid > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ > active_record/connection_adapters/sqlite_adapter.rb:360:in > `table_structure' > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/ > active_support/core_ext/object/misc.rb:23:in > `returning' > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ > active_record/connection_adapters/sqlite_adapter.rb:359:in > `table_structure' > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ > active_record/connection_adapters/sqlite_adapter.rb:210:in > `columns' > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ > active_record/base.rb:763:in > `columns' > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ > active_record/base.rb:2060:in > `attributes_from_column_definition_without_lock' > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ > active_record/locking/optimistic.rb:45:in > `attributes_from_column_definition' > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ > active_record/base.rb:1502:in > `initialize_without_callbacks' > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ > active_record/callbacks.rb:225:in > `initialize' > ./spec/models/user_spec.rb:5:in `new' > ./spec/models/user_spec.rb:5: > ./script/../vendor/plugins/rspec/lib/spec/dsl/ > composite_proc_builder.rb:16:in > `instance_eval' > ./script/../vendor/plugins/rspec/lib/spec/dsl/ > composite_proc_builder.rb:16:in > `proc' > ./script/../vendor/plugins/rspec/lib/spec/dsl/ > composite_proc_builder.rb:11:in > `collect' > ./script/../vendor/plugins/rspec/lib/spec/dsl/ > composite_proc_builder.rb:11:in > `proc' > ./script/../vendor/plugins/rspec/lib/spec/dsl/example.rb:63:in > `instance_eval' > ./script/../vendor/plugins/rspec/lib/spec/dsl/example.rb:63:in > `setup_example' > ./script/../vendor/plugins/rspec/lib/spec/dsl/example.rb:22:in `run' > /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout' > ./script/../vendor/plugins/rspec/lib/spec/dsl/example.rb:21:in `run' > ./script/../vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:77:in `run' > ./script/../vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in > `each' > ./script/../vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in `run' > ./script/../vendor/plugins/rspec/lib/spec/runner/ > behaviour_runner.rb:45:in > `run_behaviours' > ./script/../vendor/plugins/rspec/lib/spec/runner/ > behaviour_runner.rb:44:in > `each' > ./script/../vendor/plugins/rspec/lib/spec/runner/ > behaviour_runner.rb:44:in > `run_behaviours' > ./script/../vendor/plugins/rspec/lib/spec/runner/ > behaviour_runner.rb:27:in > `run'./script/../vendor/plugins/rspec/lib/spec/runner/ > command_line.rb:17:in > `run' > ./script/spec_server:23:in `run' > /usr/local/lib/ruby/1.8/drb/drb.rb:1555:in `__send__' > /usr/local/lib/ruby/1.8/drb/drb.rb:1555:in `perform_without_block' > /usr/local/lib/ruby/1.8/drb/drb.rb:1515:in `perform' > /usr/local/lib/ruby/1.8/drb/drb.rb:1589:in `main_loop' > /usr/local/lib/ruby/1.8/drb/drb.rb:1585:in `loop' > /usr/local/lib/ruby/1.8/drb/drb.rb:1585:in `main_loop' > /usr/local/lib/ruby/1.8/drb/drb.rb:1581:in `start' > /usr/local/lib/ruby/1.8/drb/drb.rb:1581:in `main_loop' > /usr/local/lib/ruby/1.8/drb/drb.rb:1430:in `run' > /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `start' > /usr/local/lib/ruby/1.8/drb/drb.rb:1427:in `run' > /usr/local/lib/ruby/1.8/drb/drb.rb:1347:in `initialize' > /usr/local/lib/ruby/1.8/drb/drb.rb:1627:in `new' > /usr/local/lib/ruby/1.8/drb/drb.rb:1627:in `start_service' > ./script/spec_server:44: > > Finished in 0.009507 seconds > > 1 example, 1 failure > > > > > > > > > > > >> >> Best, >> >> Scott >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > -- > Ed Howland > http://greenprogrammer.blogspot.com > "The information transmitted is intended only for the person or entity > to which it is addressed and may contain proprietary, confidential > and/or legally privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance > upon, this information by persons or entities other than the intended > recipient is prohibited. If you received this in error, please contact > the sender and delete the material from all computers." > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Jun 21 15:48:52 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 21 Jun 2007 14:48:52 -0500 Subject: [rspec-users] it_should_behave_like In-Reply-To: <2f5c856e0706211001v691cf38cw2338cf6c26695113@mail.gmail.com> References: <2f5c856e0706210724o3e72e75ej3469056be793e71a@mail.gmail.com> <073427F5-5C97-4B77-8E30-059361CD47CE@railsnewbie.com> <57c63afe0706210955x67f0fbabp1be9cb667f0901d2@mail.gmail.com> <2f5c856e0706211001v691cf38cw2338cf6c26695113@mail.gmail.com> Message-ID: <57c63afe0706211248q66f008bfle2904af3342cfabc@mail.gmail.com> On 6/21/07, Jordan McKible wrote: > Scott, putting aside semantics of the spec for a second, the code you posted > generated the same error for me. According to David, it would seem this is > because fixtures aren't called in shared behaviors. > > So a shared context is really just an easy way of adding a bunch of specs to > another context? Does it follow that shared contexts shouldn't use > before/after methods either? before and after both work, and don't override the ones in the specs. The before's in the shared behaviour happen before the before's in the including behaviour, and vice versa for the afters. > > > On 6/21/07, David Chelimsky wrote: > > On 6/21/07, Scott Taylor wrote: > > > > > > What is the shared behavior between these two? Do you want a valid, > > > saved, and accepted contract to act like an unaccepted contract? > > > Abstract out what is common between them, and then use that as the > > > shared description. > > > > > > See: http://pastie.caboo.se/72413 > > > > FYI - fixtures in shared behaviours don't ever get called. Just > > declare them in the behaviours that use them. > > > > > > > > Best, > > > > > > Scott > > > > > > > > > On Jun 21, 2007, at 10:24 AM, Jordan McKible wrote: > > > > > > > I'm trying to use it_should_behave_like, and something seems to be > > > > wonky with the syntax. When I add :shared=>true, the DSL complains > > > > that the next line is the fixture declaration: > > > > > > > > /vendor/plugins/rspec/lib/spec > > > > /dsl/behaviour_eval.rb:137:in `method_missing': undefined method > > > > `fixtures' for # > (NoMethodError) > > > > > > > > Here's the spec http://pastie.caboo.se/72287 > > > > > > > > Am I using it_should_behave_like properly? Am I making a separate > > > > mistake? I have RSpec setup as a svn external (currently rev2101). > > > > > > > > Thanks, > > > > Jordan > > > > http://jordan.mckible.com > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Thu Jun 21 16:00:11 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 21 Jun 2007 16:00:11 -0400 Subject: [rspec-users] Testing two interdependent ActiveRecord models In-Reply-To: <99304812-8508-47AF-ADAA-6FDA5C6FAD57@collectiveinsight.net> References: <9EB53500-25A5-49C8-93B7-245CF48D34CB@collectiveinsight.net> <99304812-8508-47AF-ADAA-6FDA5C6FAD57@collectiveinsight.net> Message-ID: <26F27BC9-3EBF-4FDF-AF19-49B885EDF307@railsnewbie.com> On Jun 21, 2007, at 3:17 PM, David James wrote: > Dear geeky, pay-your-debt-up-front-instead-of-later testing guru > (tell me I'm wrong!)... > > I would appreciate if you (twould take a look at my message from a > few weeks ago, since I didn't get any replies. Any comments would > appreciated -- even if they are "you are barking up the wrong tree" > -- or "you should read article ____ so that you can rephrase / > rethink your question" > > Thanks, > David > > On Jun 8, 2007, at 9:05 AM, David James wrote: > >> Hello, >> >> In my app, I'd like to test two model object objects that interact >> with each other. (In my example, a Person can have Contributions.) >> I guess you could say that I'm testing ActiveRecord associations. >> For example, a Person has zero or many Contributions. A Contribution >> has one or more People. This is the very basic version, but I think >> it will illustrate the dependency. (In practice, I'm interested in >> testing these associations because there is some extra logic going on >> that needs testing.) >> >> Here are my observations / questions: >> 1. Since there are two models, it doesn't seem quite right to make a >> unit test for this, does it? >> 2. There is an interaction between the two models. What is a good >> way to test the interaction? Do I put some of the testing in >> person_spec.rb and some in contribution_spec.rb? Or do I create some >> sort of "interaction" spec? >> 3. I don't think that an integration test makes sense, because I >> don't want to test the controller and views. >> 4. I wonder if mocks or stubs would make sense. I don't think I need >> to stub out a particular method (i.e. credit card processing), >> though. I'm pretty new to mocking, any advice or perspective would >> be helpful. >> >> I would appreciate any feedback -- testing philosophy, and maybe some >> hand waving, if you like. :) As far as I can tell, BDD seems to be higher level than typical testing ("Unit testing" - What would the "Unit" be here?). So it would make sense (and you are certainly able) to test both models in one "describe" block. If you want more granular "unit" testing, write a person spec and a contributions spec separately (and maybe in addition to this). You may want to watch the Dave Astels video on Google Videos relating to this topic: http://video.google.com/videoplay? docid=8135690990081075324&q=Behaviour+Driven+Development With that said, mocking/stubbing will probably be helpful in this shared spec. Or you could just mock/stub the opposite model of the one you are testing (i.e. when testing Person, mock Contributors and vise-versa). For me, though, it's hard to see why you couldn't use the later method (of mocking the association). Maybe you could give us something a little more concrete and/or post some code? Hope that helps, Scott Taylor >> >> I would also be open to a refactoring / redesign if that will help >> with testing. >> >> Thanks, >> -David >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From bob.cotton at rallydev.com Thu Jun 21 23:17:40 2007 From: bob.cotton at rallydev.com (Bob Cotton) Date: Thu, 21 Jun 2007 21:17:40 -0600 Subject: [rspec-users] it_should_behave_like In-Reply-To: <57c63afe0706211248q66f008bfle2904af3342cfabc@mail.gmail.com> (David Chelimsky's message of "Thu, 21 Jun 2007 14:48:52 -0500") References: <2f5c856e0706210724o3e72e75ej3469056be793e71a@mail.gmail.com> <073427F5-5C97-4B77-8E30-059361CD47CE@railsnewbie.com> <57c63afe0706210955x67f0fbabp1be9cb667f0901d2@mail.gmail.com> <2f5c856e0706211001v691cf38cw2338cf6c26695113@mail.gmail.com> <57c63afe0706211248q66f008bfle2904af3342cfabc@mail.gmail.com> Message-ID: "David Chelimsky" writes: > On 6/21/07, Jordan McKible wrote: >> Scott, putting aside semantics of the spec for a second, the code you posted >> generated the same error for me. According to David, it would seem this is >> because fixtures aren't called in shared behaviors. >> >> So a shared context is really just an easy way of adding a bunch of specs to >> another context? Does it follow that shared contexts shouldn't use >> before/after methods either? > > before and after both work, and don't override the ones in the specs. > The before's in the shared behaviour happen before the before's in the > including behaviour, and vice versa for the afters. Actually the before's happen in the order they are encountered in the non-shared behavior. i.e. The order of before and is_should_behave_like are kept: describe "First", :shared => true do before(:all) do puts "First shared all" end it "should say 'What!?'" do puts "What!?" end end describe "Second", :shared => true do before(:all) do puts "Second shared all" end it "should say 'What!?' again" do puts "What again" end end describe "Non shared" do it_should_behave_like "First" before(:all) do puts "first NON-shared all" end it_should_behave_like "Second" before(:all) do puts "second NON-shared all" end it "should print the them in order" do puts "non-shared example" end end > spec shared_behavior_example.rb First shared all first NON-shared all Second shared all second NON-shared all What!? .What again .non-shared example . - Bob > >> >> >> On 6/21/07, David Chelimsky wrote: >> > On 6/21/07, Scott Taylor wrote: >> > > >> > > What is the shared behavior between these two? Do you want a valid, >> > > saved, and accepted contract to act like an unaccepted contract? >> > > Abstract out what is common between them, and then use that as the >> > > shared description. >> > > >> > > See: http://pastie.caboo.se/72413 >> > >> > FYI - fixtures in shared behaviours don't ever get called. Just >> > declare them in the behaviours that use them. >> > >> > > >> > > Best, >> > > >> > > Scott >> > > >> > > >> > > On Jun 21, 2007, at 10:24 AM, Jordan McKible wrote: >> > > >> > > > I'm trying to use it_should_behave_like, and something seems to be >> > > > wonky with the syntax. When I add :shared=>true, the DSL complains >> > > > that the next line is the fixture declaration: >> > > > >> > > > /vendor/plugins/rspec/lib/spec >> > > > /dsl/behaviour_eval.rb:137:in `method_missing': undefined method >> > > > `fixtures' for # >> (NoMethodError) >> > > > >> > > > Here's the spec http://pastie.caboo.se/72287 >> > > > >> > > > Am I using it_should_behave_like properly? Am I making a separate >> > > > mistake? I have RSpec setup as a svn external (currently rev2101). >> > > > >> > > > Thanks, >> > > > Jordan >> > > > http://jordan.mckible.com >> > > > >> > > > _______________________________________________ >> > > > rspec-users mailing list >> > > > rspec-users at rubyforge.org >> > > > http://rubyforge.org/mailman/listinfo/rspec-users >> > > >> > > _______________________________________________ >> > > rspec-users mailing list >> > > rspec-users at rubyforge.org >> > > http://rubyforge.org/mailman/listinfo/rspec-users >> > > >> > _______________________________________________ >> > rspec-users mailing list >> > rspec-users at rubyforge.org >> > http://rubyforge.org/mailman/listinfo/rspec-users >> > >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Jun 21 23:31:18 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 21 Jun 2007 22:31:18 -0500 Subject: [rspec-users] it_should_behave_like In-Reply-To: References: <2f5c856e0706210724o3e72e75ej3469056be793e71a@mail.gmail.com> <073427F5-5C97-4B77-8E30-059361CD47CE@railsnewbie.com> <57c63afe0706210955x67f0fbabp1be9cb667f0901d2@mail.gmail.com> <2f5c856e0706211001v691cf38cw2338cf6c26695113@mail.gmail.com> <57c63afe0706211248q66f008bfle2904af3342cfabc@mail.gmail.com> Message-ID: <57c63afe0706212031v43614483i41ccd9e7c31ffe1a@mail.gmail.com> On 6/21/07, Bob Cotton wrote: > "David Chelimsky" writes: > > > On 6/21/07, Jordan McKible wrote: > >> Scott, putting aside semantics of the spec for a second, the code you posted > >> generated the same error for me. According to David, it would seem this is > >> because fixtures aren't called in shared behaviors. > >> > >> So a shared context is really just an easy way of adding a bunch of specs to > >> another context? Does it follow that shared contexts shouldn't use > >> before/after methods either? > > > > before and after both work, and don't override the ones in the specs. > > The before's in the shared behaviour happen before the before's in the > > including behaviour, and vice versa for the afters. > > Actually the before's happen in the order they are encountered in the > non-shared behavior. i.e. The order of before and > is_should_behave_like are kept: > > > > > describe "First", :shared => true do > before(:all) do > puts "First shared all" > end > > it "should say 'What!?'" do > puts "What!?" > end > end > > describe "Second", :shared => true do > before(:all) do > puts "Second shared all" > end > > it "should say 'What!?' again" do > puts "What again" > end > end > > describe "Non shared" do > > it_should_behave_like "First" > > before(:all) do > puts "first NON-shared all" > end > > it_should_behave_like "Second" > > before(:all) do > puts "second NON-shared all" > end > > it "should print the them in order" do > puts "non-shared example" > end > end > > > spec shared_behavior_example.rb > > First shared all > first NON-shared all > Second shared all > second NON-shared all > What!? > .What again > .non-shared example That makes sense. Thanks for the clarification. FYI - when this email came in my growl notifier read "it_should_behave_like Bob Cotton." Hope you find that as amusing as I did. Cheers, David > . > > > - Bob > > > > >> > >> > >> On 6/21/07, David Chelimsky wrote: > >> > On 6/21/07, Scott Taylor wrote: > >> > > > >> > > What is the shared behavior between these two? Do you want a valid, > >> > > saved, and accepted contract to act like an unaccepted contract? > >> > > Abstract out what is common between them, and then use that as the > >> > > shared description. > >> > > > >> > > See: http://pastie.caboo.se/72413 > >> > > >> > FYI - fixtures in shared behaviours don't ever get called. Just > >> > declare them in the behaviours that use them. > >> > > >> > > > >> > > Best, > >> > > > >> > > Scott > >> > > > >> > > > >> > > On Jun 21, 2007, at 10:24 AM, Jordan McKible wrote: > >> > > > >> > > > I'm trying to use it_should_behave_like, and something seems to be > >> > > > wonky with the syntax. When I add :shared=>true, the DSL complains > >> > > > that the next line is the fixture declaration: > >> > > > > >> > > > /vendor/plugins/rspec/lib/spec > >> > > > /dsl/behaviour_eval.rb:137:in `method_missing': undefined method > >> > > > `fixtures' for # > >> (NoMethodError) > >> > > > > >> > > > Here's the spec http://pastie.caboo.se/72287 > >> > > > > >> > > > Am I using it_should_behave_like properly? Am I making a separate > >> > > > mistake? I have RSpec setup as a svn external (currently rev2101). > >> > > > > >> > > > Thanks, > >> > > > Jordan > >> > > > http://jordan.mckible.com > >> > > > > >> > > > _______________________________________________ > >> > > > rspec-users mailing list > >> > > > rspec-users at rubyforge.org > >> > > > http://rubyforge.org/mailman/listinfo/rspec-users > >> > > > >> > > _______________________________________________ > >> > > rspec-users mailing list > >> > > rspec-users at rubyforge.org > >> > > http://rubyforge.org/mailman/listinfo/rspec-users > >> > > > >> > _______________________________________________ > >> > rspec-users mailing list > >> > rspec-users at rubyforge.org > >> > http://rubyforge.org/mailman/listinfo/rspec-users > >> > > >> > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tom at hobocentral.net Fri Jun 22 08:36:19 2007 From: tom at hobocentral.net (Tom Locke) Date: Fri, 22 Jun 2007 13:36:19 +0100 Subject: [rspec-users] Nicer failure message formatting Message-ID: Hi Are there any tools around that make rspec's failure messages easier to read? unit_diff from ZenTest doesn't seem to work - unless I missed something. A simple but very helpful improvement would be to use more line- breaks, e.g. Current output: expected "this is a very long string blah blah", got "this is a very very long string blah blah" (using ==) Easier to read: expected: "this is a very long string blah blah" got: "this is a very very long string blah blah" (using ==) Comments? Tom From aslak.hellesoy at gmail.com Fri Jun 22 09:08:05 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 22 Jun 2007 15:08:05 +0200 Subject: [rspec-users] Nicer failure message formatting In-Reply-To: References: Message-ID: <8d961d900706220608h5979f79dv9939b09cfee101df@mail.gmail.com> On 6/22/07, Tom Locke wrote: > Hi > > Are there any tools around that make rspec's failure messages easier > to read? > > unit_diff from ZenTest doesn't seem to work - unless I missed something. > > A simple but very helpful improvement would be to use more line- > breaks, e.g. > > Current output: > > expected "this is a very long string blah blah", got "this is a very > very long string blah blah" (using ==) > > Easier to read: > > expected: > "this is a very long string blah blah" > got: > "this is a very very long string blah blah" > (using ==) > > Comments? > Try the --diff option. But I agree that we should consider breaking things up like you suggest anyway. What do others think? Aslak > Tom > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jun 22 09:13:16 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 22 Jun 2007 08:13:16 -0500 Subject: [rspec-users] Nicer failure message formatting In-Reply-To: <8d961d900706220608h5979f79dv9939b09cfee101df@mail.gmail.com> References: <8d961d900706220608h5979f79dv9939b09cfee101df@mail.gmail.com> Message-ID: <57c63afe0706220613q443e9c84yd019121f14dbeea7@mail.gmail.com> On 6/22/07, aslak hellesoy wrote: > On 6/22/07, Tom Locke wrote: > > Hi > > > > Are there any tools around that make rspec's failure messages easier > > to read? > > > > unit_diff from ZenTest doesn't seem to work - unless I missed something. > > > > A simple but very helpful improvement would be to use more line- > > breaks, e.g. > > > > Current output: > > > > expected "this is a very long string blah blah", got "this is a very > > very long string blah blah" (using ==) > > > > Easier to read: > > > > expected: > > "this is a very long string blah blah" > > got: > > "this is a very very long string blah blah" > > (using ==) > > > > Comments? > > > > Try the --diff option. But I agree that we should consider breaking > things up like you suggest anyway. > > What do others think? +1 > > Aslak > > > Tom > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From win at wincent.com Fri Jun 22 09:34:43 2007 From: win at wincent.com (Wincent Colaiuta) Date: Fri, 22 Jun 2007 15:34:43 +0200 Subject: [rspec-users] Nicer failure message formatting In-Reply-To: References: Message-ID: <190A2F5D-96D3-49D2-805A-4B8209B32F53@wincent.com> El 22/6/2007, a las 14:36, Tom Locke escribi?: > Easier to read: > > expected: > "this is a very long string blah blah" > got: > "this is a very very long string blah blah" > (using ==) > > Comments? For me even easier to read would be: expected: "this is a very long string blah blah" got : "this is a very very long string blah blah" (using ==) I'm inclined to think that this formatting should only be employed for strings over a certain length. Really short strings wouldn't benefit from it (eg. expected "foo", got "bar"). Cheers, Wincent From scott at tynerblain.com Fri Jun 22 10:08:25 2007 From: scott at tynerblain.com (Scott Sehlhorst) Date: Fri, 22 Jun 2007 09:08:25 -0500 Subject: [rspec-users] Nicer failure message formatting In-Reply-To: <190A2F5D-96D3-49D2-805A-4B8209B32F53@wincent.com> References: <190A2F5D-96D3-49D2-805A-4B8209B32F53@wincent.com> Message-ID: <4f34789a0706220708i7f805a10r729c5560505e1551@mail.gmail.com> I think it is a great idea. Noticeably better for long strings (and arrays), no worse for the short ones. +1 On 6/22/07, Wincent Colaiuta wrote: > > El 22/6/2007, a las 14:36, Tom Locke escribi?: > > > Easier to read: > > > > expected: > > "this is a very long string blah blah" > > got: > > "this is a very very long string blah blah" > > (using ==) > > > > Comments? > > For me even easier to read would be: > > expected: "this is a very long string blah blah" > got : "this is a very very long string blah blah" > (using ==) > > I'm inclined to think that this formatting should only be employed > for strings over a certain length. Really short strings wouldn't > benefit from it (eg. expected "foo", got "bar"). > > Cheers, > Wincent > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Scott Sehlhorst, President Tyner Blain LLC http://tynerblain.com/blog http://tynerblain.com/nexus -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070622/04c88870/attachment.html From dchelimsky at gmail.com Fri Jun 22 10:11:26 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 22 Jun 2007 09:11:26 -0500 Subject: [rspec-users] Nicer failure message formatting In-Reply-To: <190A2F5D-96D3-49D2-805A-4B8209B32F53@wincent.com> References: <190A2F5D-96D3-49D2-805A-4B8209B32F53@wincent.com> Message-ID: <57c63afe0706220711t2d7ad66ctacce0c99dd73376@mail.gmail.com> On 6/22/07, Wincent Colaiuta wrote: > El 22/6/2007, a las 14:36, Tom Locke escribi?: > > > Easier to read: > > > > expected: > > "this is a very long string blah blah" > > got: > > "this is a very very long string blah blah" > > (using ==) > > > > Comments? > > For me even easier to read would be: > > expected: "this is a very long string blah blah" > got : "this is a very very long string blah blah" > (using ==) > > I'm inclined to think that this formatting should only be employed > for strings over a certain length. Really short strings wouldn't > benefit from it (eg. expected "foo", got "bar"). Do we really want to try and make it that smart? What would that length be? I think this is asking for trouble. > > Cheers, > Wincent > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tom at hobocentral.net Fri Jun 22 10:08:10 2007 From: tom at hobocentral.net (Tom Locke) Date: Fri, 22 Jun 2007 15:08:10 +0100 Subject: [rspec-users] Nicer failure message formatting In-Reply-To: <190A2F5D-96D3-49D2-805A-4B8209B32F53@wincent.com> References: <190A2F5D-96D3-49D2-805A-4B8209B32F53@wincent.com> Message-ID: <3FADCEB3-442D-4C17-A4FF-A02610B92B36@hobocentral.net> > For me even easier to read would be: > > expected: "this is a very long string blah blah" > got : "this is a very very long string blah blah" > (using ==) What about values with a very long inspect? It would be nice to include PP formatting, in which case you would want to either start on a new line, or I guess you could indent every line, but you do lose some horizontal space. Tom From dchelimsky at gmail.com Fri Jun 22 10:14:08 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 22 Jun 2007 09:14:08 -0500 Subject: [rspec-users] Nicer failure message formatting In-Reply-To: References: Message-ID: <57c63afe0706220714j21a08f88w9e73d22e4317ee09@mail.gmail.com> On 6/22/07, Tom Locke wrote: > expected: > "this is a very long string blah blah" > got: > "this is a very very long string blah blah" > (using ==) How about the values indented? expected: "this is a very long string blah blah" got: "this is a very very long string blah blah" (using ==) From cdemyanovich at gmail.com Fri Jun 22 10:52:05 2007 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Fri, 22 Jun 2007 09:52:05 -0500 Subject: [rspec-users] Nicer failure message formatting In-Reply-To: <57c63afe0706220714j21a08f88w9e73d22e4317ee09@mail.gmail.com> References: <57c63afe0706220714j21a08f88w9e73d22e4317ee09@mail.gmail.com> Message-ID: <61c885db0706220752i68f1e6c4r63d76582880f6375@mail.gmail.com> I like it. Also, I agree that it should be simple (at least for now), i.e., always use the format that you suggested instead of adding smarts about line length. That can come later if there's enough support for it or patches are submitted. On 6/22/07, David Chelimsky wrote: > > On 6/22/07, Tom Locke wrote: > > expected: > > "this is a very long string blah blah" > > got: > > "this is a very very long string blah blah" > > (using ==) > > How about the values indented? > > expected: > "this is a very long string blah blah" > got: > "this is a very very long string blah blah" > (using ==) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070622/182477dd/attachment.html From dchelimsky at gmail.com Fri Jun 22 10:54:44 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 22 Jun 2007 09:54:44 -0500 Subject: [rspec-users] Problems translating should_render from 0.8.2 to 1.0.5 In-Reply-To: References: Message-ID: <57c63afe0706220754y741a3714jac2bdc1b2a3639ea@mail.gmail.com> On 6/19/07, Jake Scruggs wrote: > I'm working on a large Rails site and we want to move from RSpec 0.8.2 to > the latest and greatest. So we ran the translator and yet we're having a > lot of trouble translating should_render. > > I found this on the web: > > We will NOT be supporting the following in the new syntax: > controller.should_render > controller.should_redirect_to > > You will be able to use instead: > response.should render_template > response.should render_text > response.should redirect_to > > But the problem I have is that render_template doesn't have the > functionality that we used in lots of our should_render expectations. A lot > of our should renders specify an action and and a controller, so now the > change over is slow (we have to figure out which file is being rendered > instead), but the big problem is that when testing actions that render a > partial (mostly for ajax calls) we need to test the locals that get passed > into the template. > > here's a typical spec: > specify "the :start_date should equal the date passed in" do > @mock_event_calendar_data = mock('Mock event_calendar_data') > > EventCalendarData.should_receive(:new).and_return(@mock_event_calendar_data) > date = Date.today > controller.should_render :partial => 'calendar', :locals => {:start_date > => date, :event_calendar_data => @mock_event_calendar_data} > get 'ajax_calendar', :date => Date.today.strftime("%B-%d-%Y") > end > > here's another expectation I don't know how to translate: > controller.should_render({:controller=>:content_item, :layout=>"frame", > :action=>:upload_image}) > > Does anybody have any ideas about how to get these things working in the new > RSpec? Sorry for not responding sooner. This was functionality we yanked when we went from should_render to should render_template. To keep the matchers simple, I'd suggest we add another matcher named render_action that looked at the hash, or render_with_options. WDYT? From tom at hobocentral.net Fri Jun 22 10:44:31 2007 From: tom at hobocentral.net (Tom Locke) Date: Fri, 22 Jun 2007 15:44:31 +0100 Subject: [rspec-users] Nicer failure message formatting In-Reply-To: <57c63afe0706220714j21a08f88w9e73d22e4317ee09@mail.gmail.com> References: <57c63afe0706220714j21a08f88w9e73d22e4317ee09@mail.gmail.com> Message-ID: > How about the values indented? > > expected: > "this is a very long string blah blah" > got: > "this is a very very long string blah blah" > (using ==) > I like that style. better still with PP: PP.pp(value, " ").gsub("\n", "\n ") Tom From ed.howland at gmail.com Fri Jun 22 18:20:04 2007 From: ed.howland at gmail.com (Ed Howland) Date: Fri, 22 Jun 2007 17:20:04 -0500 Subject: [rspec-users] How to test for exceptions In-Reply-To: References: Message-ID: <3df642dd0706221520x114c0f59qd3f5c4c03b82397d@mail.gmail.com> On 5/20/07, Dylan Egan wrote: > You want update_attributes! to raise the exception. Otherwise if > you're returning false you'll want to be using update_attributes and > if else statements. > > So something like > > it "should ..." do > @venue.should_receive(:update_attributes!).with("name" => "random > text").and_raise(ActiveRecord::RecordInvalid.new(mock_invalid_record)) > do_update_call > end > > it "should ..." do > do_update_call > response.should render_template(:edit) > end > > This is the mock I create for invalid records. > > def mock_invalid_record(name = 'invalid_record') > invalid_record, errors = mock(name), mock('errors') > invalid_record.stub!(:errors).and_return(errors) > errors.stub!(:full_messages).and_return(['errors']) > invalid_record > end Dylan, I think this code is great. I'd like to recommend that this should be documented in the RSpec site somehow. If you need to test controllers that are written in the style of the AWDWR book with save! and rescue and want to test the save! part and use mocked AR models, this is definitely the way to go. Thanks for fixing me. I spent several hours on this till I came across your post. Ed -- Ed Howland http://greenprogrammer.blogspot.com "The information transmitted is intended only for the person or entity to which it is addressed and may contain proprietary, confidential and/or legally privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers." From dchelimsky at gmail.com Sat Jun 23 12:01:38 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 23 Jun 2007 11:01:38 -0500 Subject: [rspec-users] new pending feature (pending release) Message-ID: <57c63afe0706230901x72f06fcck5b3cd64f43f85912@mail.gmail.com> I just added a new "pending" feature. It's in trunk (rev 2118+) and will be part of the 1.0.6 release (*probably* within the next week). Read all about it: http://blog.davidchelimsky.net/articles/2007/06/23/pending-insert-reason-here Cheers, David From jchris at mfdz.com Sat Jun 23 12:36:06 2007 From: jchris at mfdz.com (Chris Anderson) Date: Sat, 23 Jun 2007 09:36:06 -0700 Subject: [rspec-users] inverse examples? (should fail) Message-ID: The new "pending" example feature reminds me of a feature I've been bouncing around in my head, to aid in refactoring. Often, when I'm changing existing behaviour, I know that certain aspects of the old behaviour should change. Imagine changing the "it" method to perhaps "not" or "old" or "removed"... The behaviour would be to raise a spec error if the example DOES NOT fail. So if it "should do something that's been deprecated" do my_object.should_receive(:deprecated_message) action end passes, than old "should do something that's been deprecated" do my_object.should_receive(:deprecated_message) action end ought to fail. It seems like this might be a good first line of defense when starting a big refactor. I'm not sure about the wording - maybe there's a better way of expressing it - perhaps as a second argument to the spec (but that would be a little less fun to pepper throughout a document). it "should do something that's been deprecated", :inverse => true do my_object.should_receive(:deprecated_message) action end Thoughts? Does this exist already and I haven't noticed it? -- Chris Anderson http://jchris.mfdz.com From dchelimsky at gmail.com Sat Jun 23 12:47:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 23 Jun 2007 11:47:37 -0500 Subject: [rspec-users] inverse examples? (should fail) In-Reply-To: References: Message-ID: <57c63afe0706230947i1ebedd53hbcca150125a1de26@mail.gmail.com> On 6/23/07, Chris Anderson wrote: > The new "pending" example feature reminds me of a feature I've been > bouncing around in my head, to aid in refactoring. Often, when I'm > changing existing behaviour, I know that certain aspects of the old > behaviour should change. Imagine changing the "it" method to perhaps > "not" or "old" or "removed"... The behaviour would be to raise a spec > error if the example DOES NOT fail. So if > > it "should do something that's been deprecated" do > my_object.should_receive(:deprecated_message) > action > end > > passes, than > > old "should do something that's been deprecated" do > my_object.should_receive(:deprecated_message) > action > end > > ought to fail. > > It seems like this might be a good first line of defense when starting > a big refactor. > > I'm not sure about the wording - maybe there's a better way of > expressing it - perhaps as a second argument to the spec (but that > would be a little less fun to pepper throughout a document). > > it "should do something that's been deprecated", :inverse => true do > my_object.should_receive(:deprecated_message) > action > end > > Thoughts? Does this exist already and I haven't noticed it? It doesn't exist in rspec, but something like it does in rspec_ext: http://rashkovskii.com/articles/2007/1/25/rspec-specify_negatively http://rubyforge.org/projects/rspec-ext/ I haven't used that, so I don't know if it works with the latest version or not, but you can give it a shot. As for including this in rspec, I'm not really understanding it's value. How would saying something should fail, and failing it if it doesn't, help you (unless you're writing another behaviour definition framework ;) )? > > -- > Chris Anderson > http://jchris.mfdz.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Sat Jun 23 16:04:09 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 23 Jun 2007 16:04:09 -0400 Subject: [rspec-users] Autotest bug with rerunning passing tests? Message-ID: Am I correct in remembering that autotest (with Test::Unit) would rerun all the tests if a subset of the tests passed? If so, shouldn't this behaviour also be present in rspec's autotest library? Scott From dchelimsky at gmail.com Sat Jun 23 16:14:38 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 23 Jun 2007 15:14:38 -0500 Subject: [rspec-users] Autotest bug with rerunning passing tests? In-Reply-To: References: Message-ID: <57c63afe0706231314tab95dd4jf38b27fc00dc47c0@mail.gmail.com> On 6/23/07, Scott Taylor wrote: > > Am I correct in remembering that autotest (with Test::Unit) would > rerun all the tests if a subset of the tests passed? If so, > shouldn't this behaviour also be present in rspec's autotest library? Yes, but it depends on where you make the change. Let's say you get a failure and you go look at your example and realize there's something wrong and change that. Then autotest will only rerun that example (well, that whole file). If you make the change to subject code, then it should re-run everything once you get the failing example to pass. If you're experiencing something different, please follow up with a bit of detail about what files you're changing and what examples are getting run. Also, if you want to take a look at one source of any potential problems, look at @test_mappings in vendor/plugins/rspec_on_rails/lib/autotest/rails_rspec.rb. Cheers, David > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Sat Jun 23 16:24:11 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 23 Jun 2007 16:24:11 -0400 Subject: [rspec-users] Autotest bug with rerunning passing tests? In-Reply-To: <57c63afe0706231314tab95dd4jf38b27fc00dc47c0@mail.gmail.com> References: <57c63afe0706231314tab95dd4jf38b27fc00dc47c0@mail.gmail.com> Message-ID: <3C88A9B9-ABDB-4A32-A66B-E96B907D5430@railsnewbie.com> On Jun 23, 2007, at 4:14 PM, David Chelimsky wrote: > On 6/23/07, Scott Taylor wrote: >> >> Am I correct in remembering that autotest (with Test::Unit) would >> rerun all the tests if a subset of the tests passed? If so, >> shouldn't this behaviour also be present in rspec's autotest library? > > Yes, but it depends on where you make the change. Let's say you get a > failure and you go look at your example and realize there's something > wrong and change that. Then autotest will only rerun that example > (well, that whole file). > > If you make the change to subject code, then it should re-run > everything once you get the failing example to pass. > > If you're experiencing something different, please follow up with a > bit of detail about what files you're changing and what examples are > getting run. Well actually I was in the refactoring step. Here is the behaviour: 1. All of the specs are passing. 2. I refactor. 3. The subset of specs that apply runs, and passed 4. Autotest now waits for the next file change or Interrupt. Nothing else happens (although, now, all of the specs should run) Scott P.S. You mentioned that the whole spec file runs with autotest, not just the ones that are failing. Is this a bug in the code, or is it presumed that we should be using the --failures option in spec.opts? > > Also, if you want to take a look at one source of any potential > problems, look at @test_mappings in > vendor/plugins/rspec_on_rails/lib/autotest/rails_rspec.rb. > > Cheers, > David >> >> Scott >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sat Jun 23 16:29:28 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 23 Jun 2007 15:29:28 -0500 Subject: [rspec-users] Autotest bug with rerunning passing tests? In-Reply-To: <3C88A9B9-ABDB-4A32-A66B-E96B907D5430@railsnewbie.com> References: <57c63afe0706231314tab95dd4jf38b27fc00dc47c0@mail.gmail.com> <3C88A9B9-ABDB-4A32-A66B-E96B907D5430@railsnewbie.com> Message-ID: <57c63afe0706231329s50af8e8bj9c6c5d40ce501295@mail.gmail.com> On 6/23/07, Scott Taylor wrote: > > On Jun 23, 2007, at 4:14 PM, David Chelimsky wrote: > > > On 6/23/07, Scott Taylor wrote: > >> > >> Am I correct in remembering that autotest (with Test::Unit) would > >> rerun all the tests if a subset of the tests passed? If so, > >> shouldn't this behaviour also be present in rspec's autotest library? > > > > Yes, but it depends on where you make the change. Let's say you get a > > failure and you go look at your example and realize there's something > > wrong and change that. Then autotest will only rerun that example > > (well, that whole file). > > > > If you make the change to subject code, then it should re-run > > everything once you get the failing example to pass. > > > > If you're experiencing something different, please follow up with a > > bit of detail about what files you're changing and what examples are > > getting run. > > Well actually I was in the refactoring step. Here is the behaviour: > > 1. All of the specs are passing. > 2. I refactor. > 3. The subset of specs that apply runs, and passed > 4. Autotest now waits for the next file change or Interrupt. Nothing > else happens (although, now, all of the specs should run) That's the way autotest works AFAIK. It's not going to rerun everything until you get a failing example to pass. Otherwise it just runs the files that map to those that you change. > > Scott > > P.S. You mentioned that the whole spec file runs with autotest, not > just the ones that are failing. Is this a bug in the code, or is it > presumed that we should be using the --failures option in spec.opts? > > > > > > > Also, if you want to take a look at one source of any potential > > problems, look at @test_mappings in > > vendor/plugins/rspec_on_rails/lib/autotest/rails_rspec.rb. > > > > Cheers, > > David > >> > >> Scott > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Jun 23 16:38:38 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 23 Jun 2007 15:38:38 -0500 Subject: [rspec-users] Autotest bug with rerunning passing tests? In-Reply-To: <3C88A9B9-ABDB-4A32-A66B-E96B907D5430@railsnewbie.com> References: <57c63afe0706231314tab95dd4jf38b27fc00dc47c0@mail.gmail.com> <3C88A9B9-ABDB-4A32-A66B-E96B907D5430@railsnewbie.com> Message-ID: <57c63afe0706231338n66769d52va67f6d8161286870@mail.gmail.com> On 6/23/07, Scott Taylor wrote: > P.S. You mentioned that the whole spec file runs with autotest, not > just the ones that are failing. Is this a bug in the code, or is it > presumed that we should be using the --failures option in spec.opts? Neither. It's just the way we set up the mappings. My experience is that the performance savings of targeting just one example as opposed to the whole file is not that noticeable but the feedback from running all the examples in a given file is much more useful than the feedback you get from running just one example until it passes. If you want to get it to run one at a time, it'll take a bit of work on rails_rspec.rb. Feel free to contribute a patch if you like, but if you do, please set it up so that you can flip a switch of some sort to get it to work either way. Cheers, David From jchris at mfdz.com Sat Jun 23 16:42:21 2007 From: jchris at mfdz.com (Chris Anderson) Date: Sat, 23 Jun 2007 13:42:21 -0700 Subject: [rspec-users] inverse examples? (should fail) In-Reply-To: <57c63afe0706230947i1ebedd53hbcca150125a1de26@mail.gmail.com> References: <57c63afe0706230947i1ebedd53hbcca150125a1de26@mail.gmail.com> Message-ID: Thanks for the pointer about rspec-ext, I'll check it out. On 6/23/07, David Chelimsky wrote: > As for including this in rspec, I'm not really understanding it's > value. How would saying something should fail, and failing it if it > doesn't, help you (unless you're writing another behaviour definition > framework ;) )? Not having done it yet, I'm not sure how it would pan out in practice, but the notion is that you're refactoring to change existing behavior. You've got a describe-block, and among the examples are a few that no longer apply. With the objective of maintaining behaviour-driven development, I don't want to change any code without a failing spec. One helpful way to do that would be with inverse examples. It seems like a 5% case - even most behaviour-changing refactorings force the old behaviour to change, but there have been times I've run into old examples, that are passing, and supported by code. But that code is not used anywhere in the application - so the behaviour should have been removed long ago. With inverse examples, you can start a refactor by removing the behaviour you know should not be present. If you just delete the examples, there's no reason to ever delete the vestigial code. I'll check out the negative specification - the post you link to has another interesting idea - write negative specs as a form of pending - but I think forcing changes via the inverting of existing examples is more up my alley. -- Chris Anderson http://jchris.mfdz.com From dchelimsky at gmail.com Sat Jun 23 16:54:43 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 23 Jun 2007 15:54:43 -0500 Subject: [rspec-users] inverse examples? (should fail) In-Reply-To: References: <57c63afe0706230947i1ebedd53hbcca150125a1de26@mail.gmail.com> Message-ID: <57c63afe0706231354h7b354ff9ufc5b449d25d0c6e2@mail.gmail.com> On 6/23/07, Chris Anderson wrote: > Thanks for the pointer about rspec-ext, I'll check it out. > > On 6/23/07, David Chelimsky wrote: > > As for including this in rspec, I'm not really understanding it's > > value. How would saying something should fail, and failing it if it > > doesn't, help you (unless you're writing another behaviour definition > > framework ;) )? > > Not having done it yet, I'm not sure how it would pan out in practice, > but the notion is that you're refactoring to change existing behavior. > You've got a describe-block, and among the examples are a few that no > longer apply. > > With the objective of maintaining behaviour-driven development, I > don't want to change any code without a failing spec. One helpful way > to do that would be with inverse examples. > > It seems like a 5% case - even most behaviour-changing refactorings Refactoring == changing the design while preserving existing behaviour, so there is not really any such thing as a behaviour-changing refactoring. What is it that you mean by this? Can you give an example? > force the old behaviour to change, but there have been times I've run > into old examples, that are passing, and supported by code. But that > code is not used anywhere in the application - so the behaviour should > have been removed long ago. With inverse examples, you can start a > refactor by removing the behaviour you know should not be present. If > you just delete the examples, there's no reason to ever delete the > vestigial code. > > I'll check out the negative specification - the post you link to has > another interesting idea - write negative specs as a form of pending - > but I think forcing changes via the inverting of existing examples is > more up my alley. I'm still not getting this. Call me dense. Would you mind describing a small step-by-step example of how this process would work? Thanks for your patience. David > > -- > Chris Anderson > http://jchris.mfdz.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jchris at mfdz.com Sat Jun 23 17:25:36 2007 From: jchris at mfdz.com (Chris Anderson) Date: Sat, 23 Jun 2007 14:25:36 -0700 Subject: [rspec-users] inverse examples? (should fail) In-Reply-To: References: <57c63afe0706230947i1ebedd53hbcca150125a1de26@mail.gmail.com> Message-ID: I wrote an updated monkey-patch that creates negative examples, using Yurii's code as inspiration. It seems to work, but I won't need it for a while. When I try it out, if it is valuable in my workflow, I'll clean it up as a proper patch or extension. For the time being, you can throw it in your spec_helper.rb and get a rough idea of what it would be like. http://pastie.caboo.se/72927 I decided to name the inverse-it "x" because it's easy to type and gets the point across. Feel free to rename to your taste in your own projects. On 6/23/07, Chris Anderson wrote: > Thanks for the pointer about rspec-ext, I'll check it out. > > On 6/23/07, David Chelimsky wrote: > > As for including this in rspec, I'm not really understanding it's > > value. How would saying something should fail, and failing it if it > > doesn't, help you (unless you're writing another behaviour definition > > framework ;) )? > > Not having done it yet, I'm not sure how it would pan out in practice, > but the notion is that you're refactoring to change existing behavior. > You've got a describe-block, and among the examples are a few that no > longer apply. > > With the objective of maintaining behaviour-driven development, I > don't want to change any code without a failing spec. One helpful way > to do that would be with inverse examples. > > It seems like a 5% case - even most behaviour-changing refactorings > force the old behaviour to change, but there have been times I've run > into old examples, that are passing, and supported by code. But that > code is not used anywhere in the application - so the behaviour should > have been removed long ago. With inverse examples, you can start a > refactor by removing the behaviour you know should not be present. If > you just delete the examples, there's no reason to ever delete the > vestigial code. > > I'll check out the negative specification - the post you link to has > another interesting idea - write negative specs as a form of pending - > but I think forcing changes via the inverting of existing examples is > more up my alley. > > -- > Chris Anderson > http://jchris.mfdz.com > -- Chris Anderson http://jchris.mfdz.com From jchris at mfdz.com Sat Jun 23 17:35:54 2007 From: jchris at mfdz.com (Chris Anderson) Date: Sat, 23 Jun 2007 14:35:54 -0700 Subject: [rspec-users] Autotest bug with rerunning passing tests? In-Reply-To: <57c63afe0706231338n66769d52va67f6d8161286870@mail.gmail.com> References: <57c63afe0706231314tab95dd4jf38b27fc00dc47c0@mail.gmail.com> <3C88A9B9-ABDB-4A32-A66B-E96B907D5430@railsnewbie.com> <57c63afe0706231338n66769d52va67f6d8161286870@mail.gmail.com> Message-ID: On 6/23/07, David Chelimsky wrote: > Neither. It's just the way we set up the mappings. My experience is > that the performance savings of targeting just one example as opposed > to the whole file is not that noticeable but the feedback from running > all the examples in a given file is much more useful than the feedback > you get from running just one example until it passes. > I'm a little off-trunk right now, so maybe it's not an issue anymore - but when I have a spec that has say, 4 failing examples, autotest puts that file into the next run 4 times. It's a little frustrating when the number is much larger than four. I often get the spec completely passing, and then sit and wait for many more identical passing test runs before autotest finishes the last command-line batch, which in the worst case can look like this (actually the real command line was at least 20 times longer): script/spec -O spec/spec.opts spec/models/track_collision_spec.rb; script/spec -O spec/spec.opts spec/controllers/playlists_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec -O spec/spec.opts spec/controllers/grabs_controller_spec.rb If nothing else it's bad for my battery-life. :) The autotest - rspec interface seems like black-magic to me right now, so if someone is gonna jump in there and clean things up, I'd be really happy if this one goes away too. -- Chris Anderson http://jchris.mfdz.com From dchelimsky at gmail.com Sat Jun 23 17:42:08 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 23 Jun 2007 16:42:08 -0500 Subject: [rspec-users] Autotest bug with rerunning passing tests? In-Reply-To: References: <57c63afe0706231314tab95dd4jf38b27fc00dc47c0@mail.gmail.com> <3C88A9B9-ABDB-4A32-A66B-E96B907D5430@railsnewbie.com> <57c63afe0706231338n66769d52va67f6d8161286870@mail.gmail.com> Message-ID: <57c63afe0706231442m36b16ccdud7947b2e8406c735@mail.gmail.com> On 6/23/07, Chris Anderson wrote: > On 6/23/07, David Chelimsky wrote: > > Neither. It's just the way we set up the mappings. My experience is > > that the performance savings of targeting just one example as opposed > > to the whole file is not that noticeable but the feedback from running > > all the examples in a given file is much more useful than the feedback > > you get from running just one example until it passes. > > > > I'm a little off-trunk right now, so maybe it's not an issue anymore - > but when I have a spec that has say, 4 failing examples, autotest puts > that file into the next run 4 times. It's a little frustrating when > the number is much larger than four. I often get the spec completely > passing, and then sit and wait for many more identical passing test > runs before autotest finishes the last command-line batch, which in > the worst case can look like this (actually the real command line was > at least 20 times longer): > > script/spec -O spec/spec.opts spec/models/track_collision_spec.rb; > script/spec -O spec/spec.opts > spec/controllers/playlists_controller_spec.rb; script/spec -O > spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec > -O spec/spec.opts spec/controllers/stars_controller_spec.rb; > script/spec -O spec/spec.opts > spec/controllers/stars_controller_spec.rb; script/spec -O > spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec > -O spec/spec.opts spec/controllers/stars_controller_spec.rb; > script/spec -O spec/spec.opts > spec/controllers/stars_controller_spec.rb; script/spec -O > spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec > -O spec/spec.opts spec/controllers/stars_controller_spec.rb; > script/spec -O spec/spec.opts > spec/controllers/stars_controller_spec.rb; script/spec -O > spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec > -O spec/spec.opts spec/controllers/stars_controller_spec.rb; > script/spec -O spec/spec.opts > spec/controllers/stars_controller_spec.rb; script/spec -O > spec/spec.opts spec/controllers/stars_controller_spec.rb; script/spec > -O spec/spec.opts spec/controllers/stars_controller_spec.rb; > script/spec -O spec/spec.opts > spec/controllers/stars_controller_spec.rb; script/spec -O > spec/spec.opts spec/controllers/grabs_controller_spec.rb > > If nothing else it's bad for my battery-life. :) The autotest - rspec > interface seems like black-magic to me right now, so if someone is > gonna jump in there and clean things up, I'd be really happy if this > one goes away too. There have been a few bugs fixed related to this that have been released already - are you on 1.0.5? Also, give this a read - it might be the source of your problem: http://blog.davidchelimsky.net/articles/2007/05/29/rspec-and-autotest > > -- > Chris Anderson > http://jchris.mfdz.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From david.smalley.lists at googlemail.com Sun Jun 24 09:22:00 2007 From: david.smalley.lists at googlemail.com (David Smalley) Date: Sun, 24 Jun 2007 14:22:00 +0100 Subject: [rspec-users] mocking errors Message-ID: <517DEB28-D93B-4AA0-93ED-7258C97485AA@googlemail.com> What is the correct way to mock out the errors on a Rails model? I'm assuming i need to say @mock_thing = mock_model(Thing) @mock_thing_errors = mock("errors") @mock_thing_errors.should_receive(:full_messages).and_return("An error") @mock_thing.should_receive(:errors).and_return(@mock_thing_errors) Just wanted to check the best practice on this kind of thing and how other people handle it. Cheers, David From rupespad1 at mac.com Sun Jun 24 10:28:24 2007 From: rupespad1 at mac.com (Rupert) Date: Sun, 24 Jun 2007 15:28:24 +0100 Subject: [rspec-users] mocking errors In-Reply-To: <517DEB28-D93B-4AA0-93ED-7258C97485AA@googlemail.com> References: <517DEB28-D93B-4AA0-93ED-7258C97485AA@googlemail.com> Message-ID: > What is the correct way to mock out the errors on a Rails model? > > I'm assuming i need to say > > @mock_thing = mock_model(Thing) > @mock_thing_errors = mock("errors") > @mock_thing_errors.should_receive(:full_messages).and_return("An > error") > @mock_thing.should_receive(:errors).and_return(@mock_thing_errors) > > Just wanted to check the best practice on this kind of thing and how > other people handle it. Don't know if this is the best way, but I do this sort of thing.... thing = Thing.create(:a_required_attribute => nil) thing.should have_at_least(1).errors_on(:a_required_attribute) I don't think you need to mock the error handling code itself, you just want to check that the result of passing an invalid attribute to a model results in an error on that attribute. Hope this makes sense Cheers Rupert From cwdinfo at gmail.com Sun Jun 24 12:34:23 2007 From: cwdinfo at gmail.com (s.ross) Date: Sun, 24 Jun 2007 09:34:23 -0700 Subject: [rspec-users] mocking errors In-Reply-To: <517DEB28-D93B-4AA0-93ED-7258C97485AA@googlemail.com> References: <517DEB28-D93B-4AA0-93ED-7258C97485AA@googlemail.com> Message-ID: I'm doing this and overriding the last line if I want errors, but yours should also work if you want a message. Dunno if mine is more or less "correct". @thing = mock_model(Thing, :title => 'my mock title') @thing.should_receive(:errors).any_number_of_times.and_return (@errors) @errors = mock('errors') @errors.should_receive(:size).any_number_of_times.and_return(0) On Jun 24, 2007, at 6:22 AM, David Smalley wrote: > What is the correct way to mock out the errors on a Rails model? > > I'm assuming i need to say > > @mock_thing = mock_model(Thing) > @mock_thing_errors = mock("errors") > @mock_thing_errors.should_receive(:full_messages).and_return("An > error") > @mock_thing.should_receive(:errors).and_return(@mock_thing_errors) > > Just wanted to check the best practice on this kind of thing and how > other people handle it. > > Cheers, > > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Steve Ross sross at calicowebdev.com http://www.calicowebdev.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070624/3274243c/attachment.html From moses.hohman at gmail.com Sun Jun 24 13:45:23 2007 From: moses.hohman at gmail.com (Moses Hohman) Date: Sun, 24 Jun 2007 10:45:23 -0700 Subject: [rspec-users] mocking errors In-Reply-To: <517DEB28-D93B-4AA0-93ED-7258C97485AA@googlemail.com> References: <517DEB28-D93B-4AA0-93ED-7258C97485AA@googlemail.com> Message-ID: <425146b90706241045k5e4bccedi38e246b525ace22d@mail.gmail.com> Rupert: I assume David wants to do this because he wants to pass a model object with errors to a view or a controller or something to make sure it reacts properly to validation errors. SImplest case: @mock_thing = mock_model(Thing, :errors => mock_model(Errors, :full_messages => ["An error"])) Hey David and Aslak: I wish I could just say "mock(Errors, :full_messages => ["An error"])", since I never use the :null_object option on mock(), and I think it would be better to just have a separate method, "null_object()", for that case anyway. Is there a reason why that's a bad idea? If you have lots going on in your mock_model call, you might want to split this out into a separate stub! call: @mock_thing = mock_model(Thing, etc. etc.) @mock_thing.stub!(:errors).and_return(mock_model(Errors, :full_messages => ["An error"])) If I needed more methods implemented on Errors than just :full_messages, then I would rather just use a real Errors object. I don't think you lose anything by doing this, especially since Errors is a library class and not one you own. In fact I think you gain something by using the real interface to this library object instead of a mocked one (to give a more extreme example, it's better to use a real String than a mock String). In this case it's nice to write a helper method to decorate the mocked model with an Errors object: def mock_model_with_errors(klass, stubs = {}) model = mock_model(klass, stubs) model.stub!(:errors).and_return(ActiveRecord::Errors.new(model)) model end and in the example setup: before(:each) do ... assigns[:thing] = mock_model_with_errors(Thing, :a_method => "whatever", etc.) assigns[:thing].errors.add_to_base("An error") end Following the Law of Demeter helps reduce the complexity of mocking. In any situation where Rails frustrates your ability to follow the law (like ActiveRecord Errors), thereby turning what should be one line of mock setup into several, I often like to write test helper methods like the above. You do run the risk of making things less clear in your test, however, so tread carefully. I also have this problem mocking ActiveRecord association proxies, where I need to mock things like client.invoices.find(:conditions => "whatever") in a controller or something. Moses On 6/24/07, David Smalley < david.smalley.lists at googlemail.com> wrote: > > What is the correct way to mock out the errors on a Rails model? > > I'm assuming i need to say > > @mock_thing = mock_model(Thing) > @mock_thing_errors = mock("errors") > @mock_thing_errors.should_receive(:full_messages).and_return("An error") > @mock_thing.should_receive(:errors).and_return(@mock_thing_errors) > > Just wanted to check the best practice on this kind of thing and how > other people handle it. > > Cheers, > > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070624/66612444/attachment-0001.html From david.smalley.lists at googlemail.com Sun Jun 24 14:58:22 2007 From: david.smalley.lists at googlemail.com (David Smalley) Date: Sun, 24 Jun 2007 19:58:22 +0100 Subject: [rspec-users] mocking errors In-Reply-To: <425146b90706241045k5e4bccedi38e246b525ace22d@mail.gmail.com> References: <517DEB28-D93B-4AA0-93ED-7258C97485AA@googlemail.com> <425146b90706241045k5e4bccedi38e246b525ace22d@mail.gmail.com> Message-ID: <7EE5275B-99BF-4AF5-9C2B-58EB07957486@googlemail.com> Thanks everyone for your replies on a Sunday! On 24 Jun 2007, at 18:45, Moses Hohman wrote: > Rupert: I assume David wants to do this because he wants to pass a > model object with errors to a view or a controller or something to > make sure it reacts properly to validation errors. Bingo, you got that right in one. > SImplest case: > > @mock_thing = mock_model(Thing, :errors => mock_model > (Errors, :full_messages => ["An error"])) Cool - I'll start looking into this right now. It'll tidy up my current setup code. Thanks guys, David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070624/16147c9f/attachment.html From moses.hohman at gmail.com Sun Jun 24 19:48:19 2007 From: moses.hohman at gmail.com (Moses Hohman) Date: Sun, 24 Jun 2007 16:48:19 -0700 Subject: [rspec-users] mocking errors In-Reply-To: <7EE5275B-99BF-4AF5-9C2B-58EB07957486@googlemail.com> References: <517DEB28-D93B-4AA0-93ED-7258C97485AA@googlemail.com> <425146b90706241045k5e4bccedi38e246b525ace22d@mail.gmail.com> <7EE5275B-99BF-4AF5-9C2B-58EB07957486@googlemail.com> Message-ID: <425146b90706241648t38b0fa7fkc74362476dc1d1b1@mail.gmail.com> On 6/24/07, David Smalley wrote: > > > SImplest case: > > @mock_thing = mock_model(Thing, :errors => mock_model(Errors, > :full_messages => ["An error"])) > > I left out something, that should actually be: @mock_thing = mock_model(Thing, :errors => mock_model(ActiveRecord::Errors, :full_messages => ["An error"])) Moses -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070624/5f457e9d/attachment.html From cwdinfo at gmail.com Sun Jun 24 19:52:36 2007 From: cwdinfo at gmail.com (s.ross) Date: Sun, 24 Jun 2007 16:52:36 -0700 Subject: [rspec-users] mocking errors In-Reply-To: <425146b90706241648t38b0fa7fkc74362476dc1d1b1@mail.gmail.com> References: <517DEB28-D93B-4AA0-93ED-7258C97485AA@googlemail.com> <425146b90706241045k5e4bccedi38e246b525ace22d@mail.gmail.com> <7EE5275B-99BF-4AF5-9C2B-58EB07957486@googlemail.com> <425146b90706241648t38b0fa7fkc74362476dc1d1b1@mail.gmail.com> Message-ID: I think having the errors collection not block specs from working initially should be a part of mock_model. Many, if not most, views rely on that collection's existence, so it could be considered a common case. Is this a candidate for including in mock_model by default, allowing the user to override to test certain error or success cases? Steve On Jun 24, 2007, at 4:48 PM, Moses Hohman wrote: > > > On 6/24/07, David Smalley wrote: > >> SImplest case: >> >> @mock_thing = mock_model(Thing, :errors => mock_model >> (Errors, :full_messages => ["An error"])) > > I left out something, that should actually be: > > @mock_thing = mock_model(Thing, :errors => mock_model > (ActiveRecord::Errors, :full_messages => ["An error"])) > > Moses > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Steve Ross sross at calicowebdev.com http://www.calicowebdev.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070624/07293f68/attachment.html From david.smalley.lists at googlemail.com Mon Jun 25 05:21:02 2007 From: david.smalley.lists at googlemail.com (David Smalley) Date: Mon, 25 Jun 2007 10:21:02 +0100 Subject: [rspec-users] strange mock error Message-ID: <32AF477A-660B-411A-83FD-56CEC3F1A487@googlemail.com> I'm testing using the rspec mocking framework and rspec 1.0.5 and I'm getting the following strange error: # expected :set_defaults with (#, {"1"=>"1", "2"=>"2"}) but received it with (#, {"1"=>"1", "2"=>"2"}) Oddly, it looks like what its expecting and what its receiving are the same. Why would this fail? David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070625/b284e084/attachment.html From aslak.hellesoy at gmail.com Mon Jun 25 06:08:18 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 25 Jun 2007 12:08:18 +0200 Subject: [rspec-users] strange mock error In-Reply-To: <32AF477A-660B-411A-83FD-56CEC3F1A487@googlemail.com> References: <32AF477A-660B-411A-83FD-56CEC3F1A487@googlemail.com> Message-ID: <8d961d900706250308s6713fcacyaab3b300a0e6be3c@mail.gmail.com> On 6/25/07, David Smalley wrote: > I'm testing using the rspec mocking framework and rspec 1.0.5 and I'm > getting the following strange error: > > > # expected :set_defaults with > (#, {"1"=>"1", "2"=>"2"}) but > received it with (#, {"1"=>"1", > "2"=>"2"}) > > Oddly, it looks like what its expecting and what its receiving are the same. > Why would this fail? > I don't know. We need more context information. Can you post some code so we can reproduce this? Aslak > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From david.smalley.lists at googlemail.com Mon Jun 25 06:51:35 2007 From: david.smalley.lists at googlemail.com (David Smalley) Date: Mon, 25 Jun 2007 11:51:35 +0100 Subject: [rspec-users] strange mock error In-Reply-To: <8d961d900706250308s6713fcacyaab3b300a0e6be3c@mail.gmail.com> References: <32AF477A-660B-411A-83FD-56CEC3F1A487@googlemail.com> <8d961d900706250308s6713fcacyaab3b300a0e6be3c@mail.gmail.com> Message-ID: <03A6FE70-E52B-42C4-AA09-94873EBAD08C@googlemail.com> On 25 Jun 2007, at 11:08, aslak hellesoy wrote: > Can you post some code > so we can reproduce this? Sure thing. The TestSet model is: create_table "test_sets", :force => true do |t| t.column "created_at", :datetime t.column "updated_at", :datetime t.column "name", :string t.column "user_id", :integer t.column "account_id", :integer t.column "service_id", :integer t.column "testable_type", :string t.column "testable_id", :integer end My spec: describe TestSet, "saving defaults" do before(:each) do @test_set = TestSet.new @test_set.service = mock_model(Service, :slug_name => 'page') @test_set.user = mock_model(User, :id => 1) @test_set.checked_client_ids = {"1" => "1", "2" => "2"} end ...... it "should save defaults from checked_client_ids if save defaults is true and use defaults is false" do @test_set.use_defaults = false @test_set.save_defaults = true @test_set.user.should_receive(:set_defaults).with (@test_set.service, @test_set.checked_client_ids) @test_set.set_defaults @test_set.checked_client_ids.should == {"1" => "1", "2" => "2"} end Hope thats enough to go on, thanks David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070625/f9824ed4/attachment.html From justnothing at tiscali.co.uk Mon Jun 25 08:56:49 2007 From: justnothing at tiscali.co.uk (David Green) Date: Mon, 25 Jun 2007 05:56:49 -0700 (PDT) Subject: [rspec-users] db:test:clone_structure doesn't purge db Message-ID: <11286138.post@talk.nabble.com> I'm using a "CHARSET=utf8" option in my migrations, but this isn't dumped to schema.rb - a file that test:db:clone uses to create the test database. The end result is some of my specs fail because they're expecting the db table to be using utf8. to get round this, I switched to using db:test:clone_structure which DOES preserve the charset option, but when the test db is created using this method, the db isn't emptied between specs. e.g. If my before method creates an object, and the spec has 8 examples, by the time the last example is run there are 7 objects in the database. This isn't the case when I use db:test:clone this doesn't happen when using Test::Unit so I think it may be an rspec issue but I can't figure out why. any suggestions? thanks dave -- View this message in context: http://www.nabble.com/db%3Atest%3Aclone_structure-doesn%27t-purge-db-tf3975989.html#a11286138 Sent from the rspec-users mailing list archive at Nabble.com. From aslak.hellesoy at gmail.com Mon Jun 25 11:06:49 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 25 Jun 2007 17:06:49 +0200 Subject: [rspec-users] strange mock error In-Reply-To: <03A6FE70-E52B-42C4-AA09-94873EBAD08C@googlemail.com> References: <32AF477A-660B-411A-83FD-56CEC3F1A487@googlemail.com> <8d961d900706250308s6713fcacyaab3b300a0e6be3c@mail.gmail.com> <03A6FE70-E52B-42C4-AA09-94873EBAD08C@googlemail.com> Message-ID: <8d961d900706250806l18d9336hd60dfedca8df4da6@mail.gmail.com> On 6/25/07, David Smalley wrote: > > > On 25 Jun 2007, at 11:08, aslak hellesoy wrote: > > > Can you post some code > > so we can reproduce this? > Sure thing. > > The TestSet model is: > create_table "test_sets", :force => true do |t| > t.column "created_at", :datetime > t.column "updated_at", :datetime > t.column "name", :string > t.column "user_id", :integer > t.column "account_id", :integer > t.column "service_id", :integer > t.column "testable_type", :string > t.column "testable_id", :integer > end > > > My spec: > > > describe TestSet, "saving defaults" do > > before(:each) do > @test_set = TestSet.new > @test_set.service = mock_model(Service, :slug_name => 'page') > @test_set.user = mock_model(User, :id => 1) > @test_set.checked_client_ids = {"1" => "1", "2" => "2"} > end > > ...... > > it "should save defaults from checked_client_ids if save defaults is > true and use defaults is false" do > @test_set.use_defaults = false > @test_set.save_defaults = true > > @test_set.user.should_receive(:set_defaults).with(@test_set.service, > @test_set.checked_client_ids) > @test_set.set_defaults > @test_set.checked_client_ids.should == {"1" => "1", "2" > => "2"} > end > > Hope thats enough to go on, thanks > I will have to set up a new project and fill in a lot of blanks to get this working. Unless you provide something more complete it will be rather time consuming to reproduce this. Aslak > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From david.smalley.lists at googlemail.com Mon Jun 25 12:31:46 2007 From: david.smalley.lists at googlemail.com (David Smalley) Date: Mon, 25 Jun 2007 17:31:46 +0100 Subject: [rspec-users] strange mock error In-Reply-To: <8d961d900706250806l18d9336hd60dfedca8df4da6@mail.gmail.com> References: <32AF477A-660B-411A-83FD-56CEC3F1A487@googlemail.com> <8d961d900706250308s6713fcacyaab3b300a0e6be3c@mail.gmail.com> <03A6FE70-E52B-42C4-AA09-94873EBAD08C@googlemail.com> <8d961d900706250806l18d9336hd60dfedca8df4da6@mail.gmail.com> Message-ID: On 25 Jun 2007, at 16:06, aslak hellesoy wrote: > I will have to set up a new project and fill in a lot of blanks to get > this working. Unless you provide something more complete it will be > rather time consuming to reproduce this. > > Aslak Hi Aslak, Sorry, I didn't want to take up lots of your time and was erring on the side of not filling my email full of code. I'd prefer not to send the full code to list, but I can send the model and the spec for it off list if that would be acceptable? Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070625/6386f065/attachment.html From aslak.hellesoy at gmail.com Tue Jun 26 02:54:49 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 26 Jun 2007 08:54:49 +0200 Subject: [rspec-users] strange mock error In-Reply-To: References: <32AF477A-660B-411A-83FD-56CEC3F1A487@googlemail.com> <8d961d900706250308s6713fcacyaab3b300a0e6be3c@mail.gmail.com> <03A6FE70-E52B-42C4-AA09-94873EBAD08C@googlemail.com> <8d961d900706250806l18d9336hd60dfedca8df4da6@mail.gmail.com> Message-ID: <8d961d900706252354g4755d2d5nb1ac077f788da83e@mail.gmail.com> On 6/25/07, David Smalley wrote: > > > On 25 Jun 2007, at 16:06, aslak hellesoy wrote: > > > I will have to set up a new project and fill in a lot of blanks to get > > this working. Unless you provide something more complete it will be > > rather time consuming to reproduce this. > > > > > Aslak > Hi Aslak, > > Sorry, I didn't want to take up lots of your time and was erring on the side > of not filling my email full of code. > > I'd prefer not to send the full code to list, but I can send the model and > the spec for it off list if that would be acceptable? > If you think this is a bug, please follow the guidelines here: http://rspec.rubyforge.org/community/contribute.html (at the bottom) The best is if you can narrow down and isolate the problem into some files (or patches) that we can just run. Cheers Aslak > Cheers, > > David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Tue Jun 26 07:56:23 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 26 Jun 2007 12:56:23 +0100 Subject: [rspec-users] Fake SSL in specs when using ssl_requirement plug-in Message-ID: <0557FB75-BB99-4519-AADC-0BF719086EEA@ashleymoran.me.uk> Hi I've used the ssl_required line from the ssl_requirement plug-in at the start of a controller for SSL. Its implemented as redirects so I can spec this... describe "GET /gap/get_qote" do controller_name :gap it "should redirect to the HTTPS version of the action" do get 'get_quote', :id => "finance" response.should redirect_to('https://test.host/gap/get_quote/ finance') end end ...with no problems. But I can't figure out how to fake an SSL request in the spec setups so all my other specs are failing as they are being treated as non-SSL by the controller and redirected. Anyone know how to do this? Thanks in advance Ashley From johan at johansorensen.com Tue Jun 26 08:11:40 2007 From: johan at johansorensen.com (=?ISO-8859-1?Q?Johan_S=F8rensen?=) Date: Tue, 26 Jun 2007 14:11:40 +0200 Subject: [rspec-users] Fake SSL in specs when using ssl_requirement plug-in In-Reply-To: <0557FB75-BB99-4519-AADC-0BF719086EEA@ashleymoran.me.uk> References: <0557FB75-BB99-4519-AADC-0BF719086EEA@ashleymoran.me.uk> Message-ID: On Jun 26, 2007, at 1:56 PM, Ashley Moran wrote: > describe "GET /gap/get_qote" do > controller_name :gap > > it "should redirect to the HTTPS version of the action" do > get 'get_quote', :id => "finance" > response.should redirect_to('https://test.host/gap/get_quote/ > finance') > end > end > > ...with no problems. But I can't figure out how to fake an SSL > request in the spec setups so all my other specs are failing as they > are being treated as non-SSL by the controller and redirected. Maybe with: > it "should redirect to the HTTPS version of the action" do request.stub!(:ssl?).and_return(true) > get 'get_quote', :id => "finance" > response.should redirect_to('https://test.host/gap/get_quote/ > finance') > end eg. stub out the method that the ssl redirect method checks against JS From work at ashleymoran.me.uk Tue Jun 26 09:01:03 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 26 Jun 2007 14:01:03 +0100 Subject: [rspec-users] Fake SSL in specs when using ssl_requirement plug-in In-Reply-To: References: <0557FB75-BB99-4519-AADC-0BF719086EEA@ashleymoran.me.uk> Message-ID: <6D6DE1EB-4E9B-42FC-9590-AA9FCEDCFE82@ashleymoran.me.uk> On 26 Jun 2007, at 13:11, Johan S?rensen wrote: > request.stub!(:ssl?).and_return(true) Now why didn't I think of that :) I was looking for a way to set the request headers or protocol or something... Ta very much From jonathan at parkerhill.com Tue Jun 26 10:00:00 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 26 Jun 2007 10:00:00 -0400 Subject: [rspec-users] Fake SSL in specs when using ssl_requirement plug-in In-Reply-To: <6D6DE1EB-4E9B-42FC-9590-AA9FCEDCFE82@ashleymoran.me.uk> References: <0557FB75-BB99-4519-AADC-0BF719086EEA@ashleymoran.me.uk> <6D6DE1EB-4E9B-42FC-9590-AA9FCEDCFE82@ashleymoran.me.uk> Message-ID: <3C9839B8-D668-40CF-B9B3-DDBA8B3606CA@parkerhill.com> I wonder if there could be some kind of tool that dumps a potential call sequence and stack so you could more easily see where stubs could go. On Jun 26, 2007, at 9:01 AM, Ashley Moran wrote: > > On 26 Jun 2007, at 13:11, Johan S?rensen wrote: > >> request.stub!(:ssl?).and_return(true) > > Now why didn't I think of that :) I was looking for a way to set the > request headers or protocol or something... > > Ta very much > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From JScruggs at thoughtworks.com Tue Jun 26 12:17:30 2007 From: JScruggs at thoughtworks.com (Jake Scruggs) Date: Tue, 26 Jun 2007 11:17:30 -0500 Subject: [rspec-users] Problems translating should_render from 0.8.2 to 1.0.5 Message-ID: An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070626/a4870bd4/attachment.html From pergesu at gmail.com Tue Jun 26 15:52:32 2007 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 26 Jun 2007 13:52:32 -0600 Subject: [rspec-users] Can I stub a method on a belongs_to association: Message-ID: <810a540e0706261252l3c24b719w28e2a29d5ef2cae2@mail.gmail.com> describe Asset, " when destroyed" do fixtures :assets, :videos, :sites, :publish_settings before(:each) do @asset = assets(:test_asset) @mock_hook = mock("hook") @asset.video.stub!(:hook).and_return @mock_hook # error occurs here end it "should call the delete hook" do @mock_hook.should_receive(:update).with("test_video", :asset_id => @assetid, :asset_action => "destroy") @asset.destroy end end NameError in 'Asset when destroyed should call the delete hook' undefined method `hook' for class `ActiveRecord::Associations::BelongsToAssociation' I'm not sure why I can't stub the hook method on the video proxy...I need to though, because my implementation is video.hook.update.... Any ideas? Pat From moses.hohman at gmail.com Tue Jun 26 16:13:17 2007 From: moses.hohman at gmail.com (Moses Hohman) Date: Tue, 26 Jun 2007 13:13:17 -0700 Subject: [rspec-users] Can I stub a method on a belongs_to association: In-Reply-To: <810a540e0706261252l3c24b719w28e2a29d5ef2cae2@mail.gmail.com> References: <810a540e0706261252l3c24b719w28e2a29d5ef2cae2@mail.gmail.com> Message-ID: <425146b90706261313l7f78bb85q90e6f9363fb7cd40@mail.gmail.com> Stub @asset's :video first, i.e. @mock_video_proxy = mock("assay.video proxy") @asset.stub!(:video).and_return(@mock_video_proxy) @assay.video.stub!(:hook).and_return @mock_hook Generally mocking starts to get frustrating when the code you're mocking doesn't follow the Law of Demeter. I have been creating helper methods for these things, e.g. def mock_video_proxy @mock_video_proxy ||= begin proxy = mock("assay.video proxy") @asset.stub!(:video).and_return(proxy) proxy end proxy end so you can just use mock_video_proxy.stub!(:hook).and_return @mock_hook in any spec. I think there might be a better way, though. I'm not sure it's worth it to use mocks in this situation since you're already using fixtures. Why not just check the expected outcome of the hook method? Moses On 6/26/07, Pat Maddox wrote: > > describe Asset, " when destroyed" do > fixtures :assets, :videos, :sites, :publish_settings > > before(:each) do > @asset = assets(:test_asset) > @mock_hook = mock("hook") > @asset.video.stub!(:hook).and_return @mock_hook # error occurs here > end > > it "should call the delete hook" do > @mock_hook.should_receive(:update).with("test_video", :asset_id => > @assetid, :asset_action => "destroy") > @asset.destroy > end > end > > NameError in 'Asset when destroyed should call the delete hook' > undefined method `hook' for class > `ActiveRecord::Associations::BelongsToAssociation' > > I'm not sure why I can't stub the hook method on the video proxy...I > need to though, because my implementation is > > video.hook.update.... > > Any ideas? > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070626/2575700f/attachment.html From pergesu at gmail.com Tue Jun 26 16:33:08 2007 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 26 Jun 2007 14:33:08 -0600 Subject: [rspec-users] Can I stub a method on a belongs_to association: In-Reply-To: <425146b90706261313l7f78bb85q90e6f9363fb7cd40@mail.gmail.com> References: <810a540e0706261252l3c24b719w28e2a29d5ef2cae2@mail.gmail.com> <425146b90706261313l7f78bb85q90e6f9363fb7cd40@mail.gmail.com> Message-ID: <810a540e0706261333y471b1bbcge875eb5493e850d5@mail.gmail.com> On 6/26/07, Moses Hohman wrote: > Stub @asset's :video first, i.e. > > @mock_video_proxy = mock("assay.video proxy") > @asset.stub!(:video).and_return(@mock_video_proxy) > @assay.video.stub!(:hook).and_return @mock_hook > > Generally mocking starts to get frustrating when the code you're mocking > doesn't follow the Law of Demeter. I have been creating helper methods for > these things, e.g. > > def mock_video_proxy > @mock_video_proxy ||= begin > proxy = mock("assay.video proxy") > @asset.stub!(:video).and_return(proxy) > proxy > end > proxy > end > > so you can just use > > mock_video_proxy.stub!(:hook).and_return @mock_hook > > in any spec. I think there might be a better way, though. I'm not sure it's > worth it to use mocks in this situation since you're already using fixtures. > Why not just check the expected outcome of the hook method? > > Moses I don't really want to stub too much since this is kind of an integration test at the model level. I also can't check the expected outcome of the hook method because it makes a network call. Basically I want to test everything except for the hook method itself, because that's thoroughly tested elsewhere. So I just need to make sure that it gets called. Pat From court3nay at gmail.com Tue Jun 26 19:00:37 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 26 Jun 2007 16:00:37 -0700 Subject: [rspec-users] Can I stub a method on a belongs_to association: In-Reply-To: <810a540e0706261333y471b1bbcge875eb5493e850d5@mail.gmail.com> References: <810a540e0706261252l3c24b719w28e2a29d5ef2cae2@mail.gmail.com> <425146b90706261313l7f78bb85q90e6f9363fb7cd40@mail.gmail.com> <810a540e0706261333y471b1bbcge875eb5493e850d5@mail.gmail.com> Message-ID: <4b430c8f0706261600u1a823d5r7d49bc48c374bf95@mail.gmail.com> On 6/26/07, Pat Maddox wrote: > I don't really want to stub too much since this is kind of an > integration test at the model level. I also can't check the expected > outcome of the hook method because it makes a network call. What is the actual error? From pergesu at gmail.com Tue Jun 26 20:26:57 2007 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 26 Jun 2007 18:26:57 -0600 Subject: [rspec-users] Can I stub a method on a belongs_to association: In-Reply-To: <4b430c8f0706261600u1a823d5r7d49bc48c374bf95@mail.gmail.com> References: <810a540e0706261252l3c24b719w28e2a29d5ef2cae2@mail.gmail.com> <425146b90706261313l7f78bb85q90e6f9363fb7cd40@mail.gmail.com> <810a540e0706261333y471b1bbcge875eb5493e850d5@mail.gmail.com> <4b430c8f0706261600u1a823d5r7d49bc48c374bf95@mail.gmail.com> Message-ID: <810a540e0706261726h4a8d1aedhf4a43b631b8b2013@mail.gmail.com> On 6/26/07, Courtenay wrote: > On 6/26/07, Pat Maddox wrote: > > I don't really want to stub too much since this is kind of an > > integration test at the model level. I also can't check the expected > > outcome of the hook method because it makes a network call. > > What is the actual error? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > NameError in 'Asset when destroyed should call the delete hook' undefined method `hook' for class `ActiveRecord::Associations::BelongsToAssociation' From dchelimsky at gmail.com Tue Jun 26 21:19:07 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 26 Jun 2007 20:19:07 -0500 Subject: [rspec-users] Problems translating should_render from 0.8.2 to 1.0.5 In-Reply-To: References: Message-ID: <57c63afe0706261819l3aa49ca4sc9e424adb4f1e0c7@mail.gmail.com> On 6/26/07, Jake Scruggs wrote: > > -----rspec-users-bounces at rubyforge.org wrote: ----- > > >To: rspec-users > >From: "David Chelimsky" > >Sent by: rspec-users-bounces at rubyforge.org > >Date: 06/22/2007 09:54AM > >Subject: Re: [rspec-users] Problems translating should_render from > >0.8.2 to 1.0.5 > > > > >On 6/19/07, Jake Scruggs wrote: > >> I'm working on a large Rails site and we want to move from RSpec > >0.8.2 to > >> the latest and greatest. So we ran the translator and yet we're > >having a > >> lot of trouble translating should_render. > >> > >> I found this on the web: > >> > >> We will NOT be supporting the following in the > new syntax: > >> controller.should_render > >> controller.should_redirect_to > >> > >> You will be able to use instead: > >> response.should render_template > >> response.should render_text > >> response.should redirect_to > >> > >> But the problem I have is that render_template > doesn't have the > >> functionality that we used in lots of our should_render > >expectations. A lot > >> of our should renders specify an action and and a controller, so > >now the > >> change over is slow (we have to figure out which file is being > >rendered > >> instead), but the big problem is that when testing actions that > >render a > >> partial (mostly for ajax calls) we need to test the locals that get > >passed > >> into the template. > >> > >> here's a typical spec: > >> specify "the :start_date should equal the date > passed in" do > >> @mock_event_calendar_data = mock('Mock > event_calendar_data') > >> > >> > >EventCalendarData.should_receive(:new).and_return(@mock_event_calenda > >r_data) > >> date = Date.today > >> controller.should_render :partial => 'calendar', :locals => > >{:start_date > >> => date, :event_calendar_data => > @mock_event_calendar_data} > >> get 'ajax_calendar', :date => > Date.today.strftime("%B-%d-%Y") > >> end > >> > >> here's another expectation I don't know how to > translate: > >> controller.should_render({:controller=>:content_item, > >:layout=>"frame", > >> :action=>:upload_image}) > >> > >> Does anybody have any ideas about how to get these things working > >in the new > >> RSpec? > > > >Sorry for not responding sooner. This was functionality we yanked > >when > >we went from should_render to should render_template. > To keep the > >matchers simple, I'd suggest we add another matcher named > >render_action that looked at the hash, or > render_with_options. WDYT? > > That would be cool, because right now we have a lot of tests/specs/examples > that do things just like the examples I gave and the time involved in > converting all these of them means that we probably won't leave RSpec 0.82 > anytime soon (if at all). If there was a render_action, then the conversion > would be more of a simple mapping and might only take a day -- and I'm > pretty sure I could convince the business to give up a day. > > maybe we could pair on it?, That'd be great! > -Jake Scruggs > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Jun 27 01:31:53 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 27 Jun 2007 00:31:53 -0500 Subject: [rspec-users] template.expect_render Message-ID: <57c63afe0706262231o31ffe07bv36d51b1fde376e15@mail.gmail.com> Trunksters, I just added a couple of methods to ActionView::Base in Spec::Rails (as of r2136) that lets you do this in view examples: describe '/things/index.html.erb' do it "should render _thing with a collection of things" do assigns[:things] = things = [Object.new] template.expect_render(:partial => 'thing', :collection => things) render '/things/index.html.erb' end end This solves two big problems - mocking nested partials and mocking :object and :collection in partials. template.expect_render wraps part of 'spec/mocks', but not the whole framework - so we get the expectation matching benefit w/o conflicting with other mock frameworks that ppl might choose to use. There is also template.stub_render(opts) in case you just want to stub the render w/o verification. I would LOVE it if some of you would try this method out and provide feedback before we release it. Please feel to ask any questions about this on this list. Thanks, David From port001 at gmail.com Wed Jun 27 04:48:13 2007 From: port001 at gmail.com (Ian Leitch) Date: Wed, 27 Jun 2007 02:48:13 -0600 Subject: [rspec-users] rspec_on_rails: assert_select wrapper doesn't play nice with XML Message-ID: Hey, I'm using rspec and rspec_on_rails to test some RSS feed views, the problem is that the specs spew out messy warnings when they run: ignoring attempt to close channel with link opened at byte 61, line 3 closed at byte 141, line 5 attributes at open: {} text around open: "ss version=\"2.0\">\n \n \n Hi I just wondered if there was a reason why Rails controller specs are not shareable? eg describe "All XHR POSTs to /gap/calculate_quote", :shared => true do controller_name :gap # ... end describe "XHR POST /gap/calculate_quote with valid details" do it_should_behave_like "All XHR POSTs to /gap/calculate_quote" # ... end blows up with the following error: ########## /Users/ashleymoran/Documents/Development/YourMoney/trunk/src/vendor/ plugins/rspec/lib/spec/dsl/behaviour_eval.rb:137:in `method_missing': undefined method `controller_name' for # (NoMethodError) from ./spec/ controllers/gap_controller_spec.rb:165 from /Users/ashleymoran/ Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ spec/dsl/behaviour.rb:54:in `class_eval' from /Users/ashleymoran/ Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ spec/dsl/behaviour.rb:54:in `eval_behaviour' from /Users/ashleymoran/ Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ spec/dsl/behaviour.rb:31:in `original_initialize' from /Users/ ashleymoran/Documents/Development/YourMoney/trunk/src/spec/ spec_helper_additions.rb:25:in `initialize' from /Users/ashleymoran/ Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ spec/dsl/behaviour_factory.rb:36:in `new' from /Users/ashleymoran/ Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ spec/dsl/behaviour_factory.rb:36:in `create' from /Users/ashleymoran/ Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ spec/runner/extensions/kernel.rb:24:in `describe' ... 8 levels... from /Users/ashleymoran/Library/Application Support/TextMate/Pristine Copy/Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:46:in `chdir' from /Users/ashleymoran/Library/Application Support/TextMate/Pristine Copy/Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:46:in `run' from /Users/ashleymoran/Library/Application Support/TextMate/Pristine Copy/Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:25:in `run_file' from /tmp/temp_textmate.Ft0uGO:4 ########## I've had a quick look through the source and can sorta see why it doesn't work. Is there an easy way to fix this or any plans to add it in? The controller specs are where virtually all my duplication is. Ashley From dchelimsky at gmail.com Wed Jun 27 07:23:57 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 27 Jun 2007 06:23:57 -0500 Subject: [rspec-users] rspec_on_rails: assert_select wrapper doesn't play nice with XML In-Reply-To: References: Message-ID: <57c63afe0706270423k781e32c9va8328153f1618ea6@mail.gmail.com> On 6/27/07, Ian Leitch wrote: > Hey, > > I'm using rspec and rspec_on_rails to test some RSS feed views, the problem > is that the specs spew out messy warnings when they run: > > ignoring attempt to close channel with link > opened at byte 61, line 3 > closed at byte 141, line 5 > attributes at open: {} > text around open: "ss version=\"2.0\">\n \n text around close: "brands/2154/feed.rss\n > > The XML in the view is actually well formed, the problem is that the > HTML::Document class used is not instantiated in XML mode when an XML > response body is present. > See http://weblog.jamisbuck.org/2007/1/4/assert_xml_select > for more info. > > I've had a go at patching this and 'it works for me', but I've not spent > much time getting to know the internals of either rspec or rspec_on_rails, > so it may well be the wrong solution. Please post patches to the tracker, not the mailing lists. http://rubyforge.org/tracker/?group_id=797 Thanks, David > > Cheers > Ian > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > From dchelimsky at gmail.com Wed Jun 27 07:31:16 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 27 Jun 2007 06:31:16 -0500 Subject: [rspec-users] Controller specs not shareable? In-Reply-To: <97BBCFB2-68BC-4CA8-91D5-9ED73F61AB91@ashleymoran.me.uk> References: <97BBCFB2-68BC-4CA8-91D5-9ED73F61AB91@ashleymoran.me.uk> Message-ID: <57c63afe0706270431x15ca190fg9169ea251e383877@mail.gmail.com> On 6/27/07, Ashley Moran wrote: > Hi > > I just wondered if there was a reason why Rails controller specs are > not shareable? eg > > describe "All XHR POSTs to /gap/calculate_quote", :shared => true do > controller_name :gap > > # ... > end > > describe "XHR POST /gap/calculate_quote with valid details" do > it_should_behave_like "All XHR POSTs to /gap/calculate_quote" > > # ... > end Try this instead: describe "All XHR POSTs to /gap/calculate_quote", :shared => true do # ... end describe GapController, "XHR POST /gap/calculate_quote with valid details" do it_should_behave_like "All XHR POSTs to /gap/calculate_quote" # ... end The idea of shared behaviours is that multiple things that are being described have similar behaviour. The specific things, however, should never be created in the shared behaviour - they are the responsibility of the behaviours that should_behave_like them. Make sense? > > blows up with the following error: > > ########## > /Users/ashleymoran/Documents/Development/YourMoney/trunk/src/vendor/ > plugins/rspec/lib/spec/dsl/behaviour_eval.rb:137:in `method_missing': > undefined method `controller_name' for # (NoMethodError) from ./spec/ > controllers/gap_controller_spec.rb:165 from /Users/ashleymoran/ > Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ > spec/dsl/behaviour.rb:54:in `class_eval' from /Users/ashleymoran/ > Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ > spec/dsl/behaviour.rb:54:in `eval_behaviour' from /Users/ashleymoran/ > Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ > spec/dsl/behaviour.rb:31:in `original_initialize' from /Users/ > ashleymoran/Documents/Development/YourMoney/trunk/src/spec/ > spec_helper_additions.rb:25:in `initialize' from /Users/ashleymoran/ > Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ > spec/dsl/behaviour_factory.rb:36:in `new' from /Users/ashleymoran/ > Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ > spec/dsl/behaviour_factory.rb:36:in `create' from /Users/ashleymoran/ > Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ > spec/runner/extensions/kernel.rb:24:in `describe' ... 8 levels... > from /Users/ashleymoran/Library/Application Support/TextMate/Pristine > Copy/Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:46:in `chdir' > from /Users/ashleymoran/Library/Application Support/TextMate/Pristine > Copy/Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:46:in `run' > from /Users/ashleymoran/Library/Application Support/TextMate/Pristine > Copy/Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:25:in `run_file' > from /tmp/temp_textmate.Ft0uGO:4 > ########## > > I've had a quick look through the source and can sorta see why it > doesn't work. Is there an easy way to fix this or any plans to add > it in? The controller specs are where virtually all my duplication is. > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Wed Jun 27 09:37:51 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 27 Jun 2007 14:37:51 +0100 Subject: [rspec-users] Controller specs not shareable? In-Reply-To: <57c63afe0706270431x15ca190fg9169ea251e383877@mail.gmail.com> References: <97BBCFB2-68BC-4CA8-91D5-9ED73F61AB91@ashleymoran.me.uk> <57c63afe0706270431x15ca190fg9169ea251e383877@mail.gmail.com> Message-ID: <2E3F65FC-F79D-4E61-B057-C34524E4CADA@ashleymoran.me.uk> On 27 Jun 2007, at 12:31, David Chelimsky wrote: > Try this instead: > > describe "All XHR POSTs to /gap/calculate_quote", :shared => true do > # ... > end Aha yeah - it was the controller_name here that was making it fail > > describe GapController, "XHR POST /gap/calculate_quote with valid > details" do > it_should_behave_like "All XHR POSTs to /gap/calculate_quote" > > # ... > end > > The idea of shared behaviours is that multiple things that are being > described have similar behaviour. The specific things, however, should > never be created in the shared behaviour - they are the responsibility > of the behaviours that should_behave_like them. > > Make sense? Yep it does now. I was thinking of shared behaviours as like an inheritance hierarchy but actually they're more like mixins, if I understand correctly. ( They are ruby not java :D ) Thanks for the quick reply... can get on coding again now! Ashley From work at ashleymoran.me.uk Wed Jun 27 10:10:09 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 27 Jun 2007 15:10:09 +0100 Subject: [rspec-users] shared descriptions -- a couple of issues In-Reply-To: References: Message-ID: <46BBCB5B-4F01-4901-ADA0-D31485137FBB@ashleymoran.me.uk> On 10 May 2007, at 18:02, Greg Spurrier wrote: > a_spec.rb > --------- > describe "shared", :shared => true do > def foobar > 37 > end > > it "foobar should be 37" do > foobar.should == 37 > end > end > > describe "not shared" do > it_should_behave_like "shared" > end > > > yields: > > % spec a_spec.rb > F > > 1) > NameError in 'not shared foobar should be 37' > undefined local variable or method `foobar' for #<#: > 0x1065188> Hi Just wondered if this issue is fixed in trunk? I can't find an RFE and not sure how to interpret the replies to this post (they appear to be before 1.0.4 and we're on 1.0.5 now, but this behaviour is the same) Ashley From work at ashleymoran.me.uk Wed Jun 27 10:38:51 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 27 Jun 2007 15:38:51 +0100 Subject: [rspec-users] Aspects in RSpec 1.0.5 Message-ID: <3CDEC40C-9326-4424-9667-5EC656CD1C3F@ashleymoran.me.uk> Forgot post this when I did it... For anyone else that used the "aspect" method of the rspec-ext gem, here's a New World version of the code to drop into spec_helper.rb. (I'm assuming rspec-ext hasn't been updated since I did this a week or two ago) module Spec module DSL module BehaviourEval module ModuleMethods def aspect(name,&block) Behaviour.aspect << name.to_s yield Behaviour.aspect.pop end end end class Behaviour @@aspect = [] def self.aspect @@aspect end def self.aspect=(new_aspect) @@aspect = new_aspect end alias :original_initialize :initialize def initialize(*args,&context_block) result = original_initialize(*args, &context_block) @name = "(#{self.class.aspect.join("/")}) #{@name}" unless self.class.aspect.empty? result end end end end Ashley From work at ashleymoran.me.uk Wed Jun 27 11:22:49 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 27 Jun 2007 16:22:49 +0100 Subject: [rspec-users] Split controller specs Message-ID: <325A0697-8119-44D7-ABC0-A7987E2C8AA0@ashleymoran.me.uk> Hi, me again... I just wondered, how many people here have found that controller specs become unmanageably long very quickly? I've just started splitting mine up into spec/controllers/my_controller/ my_action_spec.rb etc. Maybe it is just the unusual nature of my app (a wizard-type site that guides you through choosing and paying for an insurance product) - I'm sure as it expands I will end up separating out things into separate controllers. Ashley From work at ashleymoran.me.uk Wed Jun 27 11:33:24 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 27 Jun 2007 16:33:24 +0100 Subject: [rspec-users] Fake SSL in specs when using ssl_requirement plug-in In-Reply-To: <3C9839B8-D668-40CF-B9B3-DDBA8B3606CA@parkerhill.com> References: <0557FB75-BB99-4519-AADC-0BF719086EEA@ashleymoran.me.uk> <6D6DE1EB-4E9B-42FC-9590-AA9FCEDCFE82@ashleymoran.me.uk> <3C9839B8-D668-40CF-B9B3-DDBA8B3606CA@parkerhill.com> Message-ID: <3A599A0E-9623-4E91-96F4-378C8CCB6741@ashleymoran.me.uk> On 26 Jun 2007, at 15:00, Jonathan Linowes wrote: > I wonder if there could be some kind of tool that dumps a potential > call sequence and stack so you could more easily see where stubs > could go. How do you mean exactly? I'm not sure it would be possible - you'd have to know where it should "fail" before you would know what sequence to fail, and if you could do that, you'd know what to do anyway. That's if I understood you? Ashley From dchelimsky at gmail.com Wed Jun 27 11:57:59 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 27 Jun 2007 10:57:59 -0500 Subject: [rspec-users] Aspects in RSpec 1.0.5 In-Reply-To: <3CDEC40C-9326-4424-9667-5EC656CD1C3F@ashleymoran.me.uk> References: <3CDEC40C-9326-4424-9667-5EC656CD1C3F@ashleymoran.me.uk> Message-ID: <57c63afe0706270857k317b943cg2b87184baebcc155@mail.gmail.com> On 6/27/07, Ashley Moran wrote: > Forgot post this when I did it... > > For anyone else that used the "aspect" method of the rspec-ext gem, > here's a New World version of the code to drop into spec_helper.rb. > (I'm assuming rspec-ext hasn't been updated since I did this a week > or two ago) > > module Spec > module DSL > > module BehaviourEval > module ModuleMethods > def aspect(name,&block) > Behaviour.aspect << name.to_s > yield > Behaviour.aspect.pop > end > end > end > > class Behaviour > @@aspect = [] > def self.aspect > @@aspect > end > def self.aspect=(new_aspect) > @@aspect = new_aspect > end > alias :original_initialize :initialize > def initialize(*args,&context_block) > result = original_initialize(*args, &context_block) > @name = "(#{self.class.aspect.join("/")}) #{@name}" unless > self.class.aspect.empty? > result > end > end > > end > end > > Ashley There's an RFE for this in the tracker - wanna contribute this as a patch? If you do, please use "facet" instead of "aspect". http://rubyforge.org/tracker/?func=detail&group_id=797&aid=8654&atid=3152 Cheers, David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Wed Jun 27 12:20:20 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 27 Jun 2007 17:20:20 +0100 Subject: [rspec-users] Aspects in RSpec 1.0.5 In-Reply-To: <57c63afe0706270857k317b943cg2b87184baebcc155@mail.gmail.com> References: <3CDEC40C-9326-4424-9667-5EC656CD1C3F@ashleymoran.me.uk> <57c63afe0706270857k317b943cg2b87184baebcc155@mail.gmail.com> Message-ID: On 27 Jun 2007, at 16:57, David Chelimsky wrote: > There's an RFE for this in the tracker - wanna contribute this as a > patch? If you do, please use "facet" instead of "aspect". Sure - I'll have a go on Sunday if I get chance. From Christian at hoelmer.dk Thu Jun 28 04:21:20 2007 From: Christian at hoelmer.dk (=?ISO-8859-1?Q?Christian_H=F8lmer?=) Date: Thu, 28 Jun 2007 10:21:20 +0200 Subject: [rspec-users] Custom report outputting text, expected and actual on succes? Message-ID: I would like to output the following information when running a spec (_also_ on success): - the description text - the expected value - the actual value After looking through the documentation I thought custom formatters might be the way to go, but unfortunately it does not look like all variables are accessible from there? I need this for an academic report where all testing needs to be documented with expected and actual values. This will probably be one of the only times I need this, so I am prepared for a quick and dirty hack to get it working. Before diving deeper into the code I would like to hear if anyone can think of a clever solution? I thought of creating custom matchers that outputs the information but this seems dumb? Any ideas? From dchelimsky at gmail.com Thu Jun 28 09:09:05 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 28 Jun 2007 08:09:05 -0500 Subject: [rspec-users] Problems translating should_render from 0.8.2 to 1.0.5 In-Reply-To: <57c63afe0706261819l3aa49ca4sc9e424adb4f1e0c7@mail.gmail.com> References: <57c63afe0706261819l3aa49ca4sc9e424adb4f1e0c7@mail.gmail.com> Message-ID: <57c63afe0706280609g2ee0e217uc28f8d9bba93065a@mail.gmail.com> On 6/26/07, David Chelimsky wrote: > On 6/26/07, Jake Scruggs wrote: > > > > -----rspec-users-bounces at rubyforge.org wrote: ----- > > > > >To: rspec-users > > >From: "David Chelimsky" > > >Sent by: rspec-users-bounces at rubyforge.org > > >Date: 06/22/2007 09:54AM > > >Subject: Re: [rspec-users] Problems translating should_render from > > >0.8.2 to 1.0.5 > > > > > > > >On 6/19/07, Jake Scruggs wrote: > > >> I'm working on a large Rails site and we want to move from RSpec > > >0.8.2 to > > >> the latest and greatest. So we ran the translator and yet we're > > >having a > > >> lot of trouble translating should_render. > > >> > > >> I found this on the web: > > >> > > >> We will NOT be supporting the following in the > > new syntax: > > >> controller.should_render > > >> controller.should_redirect_to > > >> > > >> You will be able to use instead: > > >> response.should render_template > > >> response.should render_text > > >> response.should redirect_to > > >> > > >> But the problem I have is that render_template > > doesn't have the > > >> functionality that we used in lots of our should_render > > >expectations. A lot > > >> of our should renders specify an action and and a controller, so > > >now the > > >> change over is slow (we have to figure out which file is being > > >rendered > > >> instead), but the big problem is that when testing actions that > > >render a > > >> partial (mostly for ajax calls) we need to test the locals that get > > >passed > > >> into the template. > > >> > > >> here's a typical spec: > > >> specify "the :start_date should equal the date > > passed in" do > > >> @mock_event_calendar_data = mock('Mock > > event_calendar_data') > > >> > > >> > > >EventCalendarData.should_receive(:new).and_return(@mock_event_calenda > > >r_data) > > >> date = Date.today > > >> controller.should_render :partial => 'calendar', :locals => > > >{:start_date > > >> => date, :event_calendar_data => > > @mock_event_calendar_data} > > >> get 'ajax_calendar', :date => > > Date.today.strftime("%B-%d-%Y") > > >> end > > >> > > >> here's another expectation I don't know how to > > translate: > > >> controller.should_render({:controller=>:content_item, > > >:layout=>"frame", > > >> :action=>:upload_image}) > > >> > > >> Does anybody have any ideas about how to get these things working > > >in the new > > >> RSpec? > > > > > >Sorry for not responding sooner. This was functionality we yanked > > >when > > >we went from should_render to should render_template. > > To keep the > > >matchers simple, I'd suggest we add another matcher named > > >render_action that looked at the hash, or > > render_with_options. WDYT? > > > > That would be cool, because right now we have a lot of tests/specs/examples > > that do things just like the examples I gave and the time involved in > > converting all these of them means that we probably won't leave RSpec 0.82 > > anytime soon (if at all). If there was a render_action, then the conversion > > would be more of a simple mapping and might only take a day -- and I'm > > pretty sure I could convince the business to give up a day. > > > > maybe we could pair on it?, > > That'd be great! So Jake came by last night and we paired on this and got it solved. You can read about the solution here: http://blog.davidchelimsky.net/articles/2007/06/28/template-expects_render Cheers, David > > > -Jake Scruggs > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From zach.dennis at gmail.com Fri Jun 29 00:29:57 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 29 Jun 2007 00:29:57 -0400 Subject: [rspec-users] fixtures :all Message-ID: <85d99afe0706282129k56abe793q7aebb80f21b8439d@mail.gmail.com> Does rspec not understand "fixtures :all" ? If so, has it been requested? If not, can I request it? If you need a patch I can surely submit one. ;) Zach From dchelimsky at gmail.com Fri Jun 29 00:39:14 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 28 Jun 2007 23:39:14 -0500 Subject: [rspec-users] fixtures :all In-Reply-To: <85d99afe0706282129k56abe793q7aebb80f21b8439d@mail.gmail.com> References: <85d99afe0706282129k56abe793q7aebb80f21b8439d@mail.gmail.com> Message-ID: <57c63afe0706282139t4c5d0f2fs3e0b0c08fef7d057@mail.gmail.com> On 6/28/07, Zach Dennis wrote: > Does rspec not understand "fixtures :all" ? If so, has it been > requested? If not, can I request it? Feature requests, patches, bug reports go here: http://rubyforge.org/tracker/?group_id=797 > > If you need a patch I can surely submit one. ;) > > Zach > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tom at hobocentral.net Fri Jun 29 08:01:38 2007 From: tom at hobocentral.net (Tom Locke) Date: Fri, 29 Jun 2007 13:01:38 +0100 Subject: [rspec-users] DOM equal? In-Reply-To: <85d99afe0706282129k56abe793q7aebb80f21b8439d@mail.gmail.com> References: <85d99afe0706282129k56abe793q7aebb80f21b8439d@mail.gmail.com> Message-ID: <17E55868-2510-4D7D-A119-6CDE3C1995CF@hobocentral.net> Is something like Rails' assert_dom_equal available? such that is equal to What I really need is something that will work for a whole fragment of xml, not just a single tag. Google says no, but google doesn't know everything. Or maybe I don't know what the correct question is :-) Tom From dchelimsky at gmail.com Fri Jun 29 08:22:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 29 Jun 2007 07:22:40 -0500 Subject: [rspec-users] DOM equal? In-Reply-To: <17E55868-2510-4D7D-A119-6CDE3C1995CF@hobocentral.net> References: <85d99afe0706282129k56abe793q7aebb80f21b8439d@mail.gmail.com> <17E55868-2510-4D7D-A119-6CDE3C1995CF@hobocentral.net> Message-ID: <57c63afe0706290522p6ee50bcfn9336cd43870a043d@mail.gmail.com> On 6/29/07, Tom Locke wrote: > Is something like Rails' assert_dom_equal available? Well, yes and no. Spec::Rails wraps test/unit, so you can use assert_dom_equal directly. If you'd like to see this in a matcher, feel free to submit an RFE - ideally with a patch. http://rubyforge.org/tracker/?group_id=797 Thanks, David > > such that is equal to > > What I really need is something that will work for a whole fragment > of xml, not just a single tag. > > Google says no, but google doesn't know everything. Or maybe I don't > know what the correct question is :-) > > Tom > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Fri Jun 29 12:28:17 2007 From: cwdinfo at gmail.com (s.ross) Date: Fri, 29 Jun 2007 09:28:17 -0700 Subject: [rspec-users] [Rails] RSpec, controller testing, and routes.rb In-Reply-To: <310c80f00706290920p1357c12aic8c4c3cf9e6c1ab1@mail.gmail.com> References: <310c80f00706290920p1357c12aic8c4c3cf9e6c1ab1@mail.gmail.com> Message-ID: <3F9A3FD5-A72D-48F2-80F2-3EC10F82FC3E@gmail.com> rspec-users at rubyforge.org (cross-posting) On Jun 29, 2007, at 9:20 AM, Bill Kocik wrote: > > I didn't see any forums or lists for RSpec users, so I'm hoping there > are RSpec users on this list who may be able to help. > > I have this in my routes.rb: > > map.signup 'signup/:step', > :controller => 'register', > :action => 'signup', > :step => 1 > > This test in the associated *.rspec file passes: > > it "should assign @step to 1 on a get to 1" do > get 'signup', :step => 1 > assigns[:step].should equal(1) > end > > This one fails: > > it "should assign @step to 1 on a get to /signup" do > get 'signup' > assigns[:step].should equal(1) > end > > Even though that second test fails, when running under mongrel the > controller does the expected thing. If I GET /signup, the @step > variable (which is simply assigned the value of params[:step] by a > before_filter) is set to 1 appropriately. It seems that the default > :step set in the routes.rb works when running in a server, but not > during testing. I find this odd, since I am able to test my routes > with route_for, and they all pass. It seems that during testing, some > of what routes.rb specifies works, and some doesn't. > > Is this to be expected, or have I managed to break something? It's > sort of hard for me to accept that I cannot test behavior of my > controller that relies on mappings in routes.rb, so I'm guessing I've > got something wrong somewhere. > > -- > Bill Kocik > > http://bkocik.net > > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk at googlegroups.com > To unsubscribe from this group, send email to rubyonrails-talk- > unsubscribe at googlegroups.com > For more options, visit this group at http://groups.google.com/ > group/rubyonrails-talk?hl=en > -~----------~----~----~----~------~----~------~--~--- > Steve Ross sross at calicowebdev.com http://www.calicowebdev.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070629/188905f6/attachment.html From jeremy.f.stephens at vanderbilt.edu Fri Jun 29 17:17:15 2007 From: jeremy.f.stephens at vanderbilt.edu (Jeremy Stephens) Date: Fri, 29 Jun 2007 16:17:15 -0500 Subject: [rspec-users] testing instance variables that are set inside views Message-ID: <468576DB.7060803@vanderbilt.edu> Hi all, In my view specs (for Rails), how can I get at instance variables that are set within my view? For example, if my view looks like this: <% @header = "My Header" -%>

some content
How can I get to @header from within my view spec? I've tried @header and assigns[:header] to no avail. TIA, Jeremy -- Jeremy Stephens Computer Systems Analyst I School of Medicine Department of Biostatistics Vanderbilt University From aslak.hellesoy at gmail.com Sat Jun 30 03:52:04 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 30 Jun 2007 09:52:04 +0200 Subject: [rspec-users] testing instance variables that are set inside views In-Reply-To: <468576DB.7060803@vanderbilt.edu> References: <468576DB.7060803@vanderbilt.edu> Message-ID: <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> @header is an implementation detail of your view that you shouldn't care about in your view spec at all. I recommend you use the have_tag matcher instead to verify what content gets rendered as expected. Aslak On 6/29/07, Jeremy Stephens wrote: > Hi all, > > In my view specs (for Rails), how can I get at instance variables that > are set within my view? For example, if my view looks like this: > > <% @header = "My Header" -%> >
some content
> > How can I get to @header from within my view spec? I've tried @header > and assigns[:header] to no avail. > > TIA, > Jeremy > > -- > Jeremy Stephens Computer Systems Analyst I School of Medicine > Department of Biostatistics Vanderbilt University > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nobody at mixmin.net Tue Jun 26 14:30:28 2007 From: nobody at mixmin.net (Anonymous) Date: Tue, 26 Jun 2007 19:30:28 +0100 (BST) Subject: [rspec-users] Acts as Authenticated Message-ID: I am using Acts as Authenticated and I need to call current_user in my views. How do I mock current_user and other methods of Acts as Authenticated in my view specs? From aslak.hellesoy at gmail.com Sat Jun 30 11:09:24 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 30 Jun 2007 17:09:24 +0200 Subject: [rspec-users] Acts as Authenticated In-Reply-To: References: Message-ID: <8d961d900706300809u2d076f73v39426ef9d85c9bc0@mail.gmail.com> On 6/26/07, Anonymous wrote: > I am using Acts as Authenticated and I need to call current_user in my views. > How do I mock current_user and other methods of Acts as Authenticated in my view specs? Hi Anon See "Mocking and stubbing helpers" http://rspec.rubyforge.org/documentation/rails/writing/views.html Aslak > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From barjunk at attglobal.net Sat Jun 30 16:35:10 2007 From: barjunk at attglobal.net (barsalou) Date: Sat, 30 Jun 2007 12:35:10 -0800 Subject: [rspec-users] testing instance variables that are set inside views In-Reply-To: <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> References: <468576DB.7060803@vanderbilt.edu> <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> Message-ID: <20070630123510.rsfz95u3okkks4s4@lcgalaska.com> Quoting aslak hellesoy : > @header is an implementation detail of your view that you shouldn't > care about in your view spec at all. I recommend you use the have_tag > matcher instead to verify what content gets rendered as expected. > > Aslak > Thanks Aslak, I wondered this myself. I looked around here : http://rspec.rubyforge.org/rdoc/index.html for have_tag but didn't find it. Where would be a good place to find some of these matchers? Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From dchelimsky at gmail.com Sat Jun 30 16:41:09 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 30 Jun 2007 15:41:09 -0500 Subject: [rspec-users] testing instance variables that are set inside views In-Reply-To: <20070630123510.rsfz95u3okkks4s4@lcgalaska.com> References: <468576DB.7060803@vanderbilt.edu> <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> <20070630123510.rsfz95u3okkks4s4@lcgalaska.com> Message-ID: <57c63afe0706301341l19d4041bvca9dd519ce3b74fc@mail.gmail.com> On 6/30/07, barsalou wrote: > Quoting aslak hellesoy : > > > @header is an implementation detail of your view that you shouldn't > > care about in your view spec at all. I recommend you use the have_tag > > matcher instead to verify what content gets rendered as expected. > > > > Aslak > > > > Thanks Aslak, I wondered this myself. I looked around here : > http://rspec.rubyforge.org/rdoc/index.html for have_tag but didn't find > it. > > Where would be a good place to find some of these matchers? have_tag is not part of rspec's core, it's in the rails plugin. The rdoc for that is at http://rspec.rubyforge.org/rdoc-rails/index.html Cheers, David > > Mike B. > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From court3nay at gmail.com Sat Jun 30 23:36:22 2007 From: court3nay at gmail.com (court3nay) Date: Sat, 30 Jun 2007 20:36:22 -0700 Subject: [rspec-users] Acts as Authenticated In-Reply-To: <8d961d900706300809u2d076f73v39426ef9d85c9bc0@mail.gmail.com> References: <8d961d900706300809u2d076f73v39426ef9d85c9bc0@mail.gmail.com> Message-ID: <93C10809-2E25-429C-AF2E-560269AADEF6@gmail.com> also see the caboose sample app for a complete integration of acts as auth with rspec. -------- Courtenay Sent from my iPhone On Jun 30, 2007, at 8:09 AM, "aslak hellesoy" wrote: > On 6/26/07, Anonymous wrote: >> I am using Acts as Authenticated and I need to call current_user in >> my views. >> How do I mock current_user and other methods of Acts as >> Authenticated in my view specs? > > Hi Anon > > See "Mocking and stubbing helpers" > http://rspec.rubyforge.org/documentation/rails/writing/views.html > > Aslak > >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users