From apremdas at gmail.com Thu Dec 1 06:07:15 2011 From: apremdas at gmail.com (Andrew Premdas) Date: Thu, 1 Dec 2011 11:07:15 +0000 Subject: [rspec-users] cucumber is_admin? testing In-Reply-To: References: <201a8df12f34c8d36a46c0979314f1e7@ruby-forum.com> Message-ID: On 28 November 2011 15:48, Alex Whiteland wrote: > I sent copy of my issue to cukes at googlegroups.com from > awhiteland at hushmail.com > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I'm a moderator on the Cukes list. There are no outstanding messages awaiting moderation. I suggest you try again. Send your message to cukes at googlegroups.com All best Andrew -- ------------------------ Andrew Premdas blog.andrew.premdas.org From patrick at collinatorstudios.com Thu Dec 1 19:34:06 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Thu, 1 Dec 2011 16:34:06 -0800 (PST) Subject: [rspec-users] problem setting expectation for test with delayed::job Message-ID: I've got something like this: # post_observer.rb after_create # ...stuff Delayed::Job.enqueue(PostSharer.new(post, post.user)) end ... # post_sharer.rb class PostSharer < Struct.new(:post, user) def perform # Delayed::Job calls .perform on the object passed into enqueue end end # post_controller_spec.rb it "shares the post" do PostSharer.expects(:new).once lambda { do_post }.should change(Delayed::Job, :count).by(1) end ... This fails due to the expectation put on PostSharer receiving .new --- if I remove that, then it all works fine... And if I look at the test database, Delayed::Job has created a job for PostSharer, so it is all working as desired.. I just wanted to take it a step further and ensure that the right class is being instantiated. I am assuming this is because setting an expectation on new is somehow changing the structure of the class and confusing delayed job? Maybe because it's a struct? 1) PostsController creating a post sharing shares when it should Failure/Error: post :create, { :submit_action => submit_type.to_s, :post => new_post(post_attributes).attributes } ArgumentError: Cannot enqueue items which do not respond to perform # ./app/observers/post_observer.rb:12:in `after_create' # ./app/models/post.rb:156:in `set_state_to_open_for_free_requests' # ./app/controllers/posts_controller.rb:39:in `create' # ./spec/controllers/post_controller_spec.rb:8:in `do_post' # ./spec/controllers/post_controller_spec.rb:77 # ./spec/controllers/post_controller_spec.rb:75 Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Thu Dec 1 23:43:39 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 1 Dec 2011 22:43:39 -0600 Subject: [rspec-users] problem setting expectation for test with delayed::job In-Reply-To: References: Message-ID: <597D7B47-7DC5-4541-8A23-BF64CED1D0F3@gmail.com> On Dec 1, 2011, at 6:34 PM, Patrick J. Collins wrote: > I've got something like this: > > # post_observer.rb > > after_create > # ...stuff > Delayed::Job.enqueue(PostSharer.new(post, post.user)) > end > > ... > > # post_sharer.rb > > class PostSharer < Struct.new(:post, user) > > def perform > # Delayed::Job calls .perform on the object passed into enqueue > end > > end > > # post_controller_spec.rb > > it "shares the post" do > > PostSharer.expects(:new).once > lambda { do_post }.should change(Delayed::Job, :count).by(1) > > end > > ... > > This fails due to the expectation put on PostSharer receiving .new --- if I > remove that, then it all works fine... And if I look at the test database, > Delayed::Job has created a job for PostSharer, so it is all working as > desired.. You could automate "if I look at the test database" bit as part of the test. > I just wanted to take it a step further and ensure that the right > class is being instantiated. Wouldn't the record in the database be enough? If not, you could do this: Delayed::Job.expects(:enqueue).with(PostSharer.new(post, post.user)) > I am assuming this is because setting an > expectation on new is somehow changing the structure of the class and confusing > delayed job? Maybe because it's a struct? In rspec-mocks, when you say Klass.stub(:new), Klass.new returns a proxy, not an instance of the Klass. I'm pretty sure the same is true of mocha. Cheers, David > 1) PostsController creating a post sharing shares when it should > Failure/Error: post :create, { :submit_action => submit_type.to_s, :post => new_post(post_attributes).attributes } > ArgumentError: > Cannot enqueue items which do not respond to perform > # ./app/observers/post_observer.rb:12:in `after_create' > # ./app/models/post.rb:156:in `set_state_to_open_for_free_requests' > # ./app/controllers/posts_controller.rb:39:in `create' > # ./spec/controllers/post_controller_spec.rb:8:in `do_post' > # ./spec/controllers/post_controller_spec.rb:77 > # ./spec/controllers/post_controller_spec.rb:75 > > Patrick J. Collins > http://collinatorstudios.com From patrick at collinatorstudios.com Fri Dec 2 00:39:35 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Thu, 1 Dec 2011 21:39:35 -0800 (PST) Subject: [rspec-users] problem setting expectation for test with delayed::job In-Reply-To: <597D7B47-7DC5-4541-8A23-BF64CED1D0F3@gmail.com> References: <597D7B47-7DC5-4541-8A23-BF64CED1D0F3@gmail.com> Message-ID: > In rspec-mocks, when you say Klass.stub(:new), Klass.new returns a proxy, not > an instance of the Klass. I'm pretty sure the same is true of mocha. Ok-- I guess I wasn't realizing that Klass.expects(:new) was actually stubbing the class.. I was thinking it was doing something like making a duplicate of the initialize method (making it something like "_initialize") and then overwriting the real initialize method with something that calls _initialize but also sets a flag to indicate that .new had been called... So that's apparently not quite the case? In any event, after reading what you wrote I got my test to pass by doing: PostSharer.expects(:new).once.returns stub("Fake Post Sharer", :perform => true) So this way delayed_job still can call perform on the fake object and everyone is happy (especially me). Patrick J. Collins http://collinatorstudios.com From lists at ruby-forum.com Fri Dec 2 02:49:49 2011 From: lists at ruby-forum.com (Alex Whiteland) Date: Fri, 02 Dec 2011 08:49:49 +0100 Subject: [rspec-users] cucumber is_admin? testing In-Reply-To: <201a8df12f34c8d36a46c0979314f1e7@ruby-forum.com> References: <201a8df12f34c8d36a46c0979314f1e7@ruby-forum.com> Message-ID: <4ada7ec992f368c58715881ba8da9cf4@ruby-forum.com> Hi, Andrew. I resent msg now. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Dec 2 11:25:33 2011 From: lists at ruby-forum.com (Uriel J.) Date: Fri, 02 Dec 2011 17:25:33 +0100 Subject: [rspec-users] Testing Views with Rails 3 and Rspec2 - Can't stub request.path_params[:controller] Message-ID: I am stuck to test a specific view which contains a request.path_parameters[:controller] variable as the example below follows: <%=link_to "Store", admin_stores_url, { :id => "tab-3" ,:class => (admin_stores_path == '/' + request.path_parameters[:controller] && 'active')} %> The rspec view test file: describe "displaying the index file" do it "should have the #tab-3 selector id, for example" do controller.request.path_parameters["controller"].should eq("admin/stores") render rendered.should =~ /#tab-3/ end end The given error: Failure/Error: render ActionView::Template::Error: can't convert nil into String # ./app/views/admin/settings/_menu.html.erb:5:in `+' # ./app/views/admin/settings/_menu.html.erb:5:in `_app_views_admin_settings__menu_html_erb__3443097722112408564_2172534220_4114188497869029268' # ./app/views/admin/stores/index.html.erb:6:in `block in _app_views_admin_stores_index_html_erb___284062528844236588_2236860180__1529683073472994564' # ./app/views/admin/stores/index.html.erb:5:in `_app_views_admin_stores_index_html_erb___284062528844236588_2236860180__1529683073472994564' # ./spec/views/admin/stores/index.html.erb_spec.rb:17:in `block (3 levels) in ' Any ideas about how to stub or simulate the request.path_parameters[:controller]? Thanks. -- Posted via http://www.ruby-forum.com/. From apremdas at gmail.com Sat Dec 3 07:00:24 2011 From: apremdas at gmail.com (Andrew Premdas) Date: Sat, 3 Dec 2011 12:00:24 +0000 Subject: [rspec-users] cucumber is_admin? testing In-Reply-To: <4ada7ec992f368c58715881ba8da9cf4@ruby-forum.com> References: <201a8df12f34c8d36a46c0979314f1e7@ruby-forum.com> <4ada7ec992f368c58715881ba8da9cf4@ruby-forum.com> Message-ID: On 2 December 2011 07:49, Alex Whiteland wrote: > Hi, Andrew. > > I resent msg now. > You are not in banned list or members list and there is no message pending. I suspect you are doing something wrong or possibly your email address is not liked by google. Perhaps you could try another account? All best Andrew > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- ------------------------ Andrew Premdas blog.andrew.premdas.org From antsmailinglist at gmail.com Sun Dec 4 08:48:14 2011 From: antsmailinglist at gmail.com (Ants Pants) Date: Sun, 4 Dec 2011 14:48:14 +0100 Subject: [rspec-users] Having A Problem Understanding mocks with .build Message-ID: Hello everyone, I am trying to do the following .... before(:each) do @valid_attributes = {:foo => 'bar'} @event_type = event_category.event_types.build(@valid_attributes) $stderr.puts "**** #{@event_type.class} *****" end let (:event_category) { mock_model(EventCategory).as_null_object } and the problem I'm having is that @event_type is coming back as EventCategory and not EventType. Because of this problem, I thought, eh, I didn't know Rails did that! So I checked use of .build in the real code and it does return EventType. I'm obviously doing something stupidly wrong in the test but I just can't figure it out. Any pointers would be greatly appreciated, thank you. -ants -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sun Dec 4 08:55:53 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 4 Dec 2011 07:55:53 -0600 Subject: [rspec-users] Having A Problem Understanding mocks with .build In-Reply-To: References: Message-ID: <14CC9A47-DD5A-4CAD-B0F2-17FB81B77D0D@gmail.com> On Dec 4, 2011, at 7:48 AM, Ants Pants wrote: > Hello everyone, > > I am trying to do the following .... > > before(:each) do > @valid_attributes = {:foo => 'bar'} > @event_type = event_category.event_types.build(@valid_attributes) > $stderr.puts "**** #{@event_type.class} *****" > end > > let (:event_category) { mock_model(EventCategory).as_null_object } > > and the problem I'm having is that @event_type is coming back as EventCategory and not EventType. > > Because of this problem, I thought, eh, I didn't know Rails did that! So I checked use of .build in the real code and it does return EventType. > > I'm obviously doing something stupidly wrong in the test but I just can't figure it out. > > Any pointers would be greatly appreciated, thank you. event_category is a mock_model, not an EventCategory. Since it's declared as_null_object, when it receives :event_types, it returns itself, and then does the same for :build. So it's not really even an EventCategory: it's a the same mock_model object, which is designed to lie about it's class in order to be able to work with form builders. HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From antsmailinglist at gmail.com Sun Dec 4 09:37:57 2011 From: antsmailinglist at gmail.com (Ants Pants) Date: Sun, 4 Dec 2011 15:37:57 +0100 Subject: [rspec-users] Having A Problem Understanding mocks with .build In-Reply-To: <14CC9A47-DD5A-4CAD-B0F2-17FB81B77D0D@gmail.com> References: <14CC9A47-DD5A-4CAD-B0F2-17FB81B77D0D@gmail.com> Message-ID: David, Thanks very much for the reply. I was aware I was dealing with a mock, but I thought in this instance it would fool event_types into thinking it was a genuine object to allow the association to be made and return EventType. So what are my options? To add the data to the DB or to build the object the long way round @et = EventType.new(@avalid_attributes) @et.event_category = event_category ## mock @et.save! While I have your ears, is it necessary to replicate the behaviour in the model spec of how a controller builds an object? i.e use .build in the controller and use .new in the spec. I mean, to me, it doesn't matter as all I'm really concerned with is working with the object no matter how it's built. Great piece of software and book, by-the-way. Thanks very much for it. -ants On 4 December 2011 14:55, David Chelimsky wrote: > > On Dec 4, 2011, at 7:48 AM, Ants Pants wrote: > > Hello everyone, > > I am trying to do the following .... > > before(:each) do > @valid_attributes = {:foo => 'bar'} > > @event_type = event_category.event_types.build(@valid_attributes) > $stderr.puts "**** #{@event_type.class} *****" > end > > let (:event_category) { mock_model(EventCategory).as_null_object } > > and the problem I'm having is that @event_type is coming back as > EventCategory and not EventType. > > Because of this problem, I thought, eh, I didn't know Rails did that! So > I checked use of .build in the real code and it does return EventType. > > I'm obviously doing something stupidly wrong in the test but I just can't > figure it out. > > Any pointers would be greatly appreciated, thank you. > > > event_category is a mock_model, not an EventCategory. Since it's declared > as_null_object, when it receives :event_types, it returns itself, and then > does the same for :build. So it's not really even an EventCategory: it's a > the same mock_model object, which is designed to lie about it's class in > order to be able to work with form builders. > > HTH, > 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: From dchelimsky at gmail.com Sun Dec 4 16:39:18 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 4 Dec 2011 15:39:18 -0600 Subject: [rspec-users] Having A Problem Understanding mocks with .build In-Reply-To: References: <14CC9A47-DD5A-4CAD-B0F2-17FB81B77D0D@gmail.com> Message-ID: On Dec 4, 2011, at 8:37 AM, Ants Pants wrote: > On 4 December 2011 14:55, David Chelimsky wrote: > > On Dec 4, 2011, at 7:48 AM, Ants Pants wrote: > >> Hello everyone, >> >> I am trying to do the following .... >> >> before(:each) do >> @valid_attributes = {:foo => 'bar'} >> @event_type = event_category.event_types.build(@valid_attributes) >> $stderr.puts "**** #{@event_type.class} *****" >> end >> >> let (:event_category) { mock_model(EventCategory).as_null_object } >> >> and the problem I'm having is that @event_type is coming back as EventCategory and not EventType. >> >> Because of this problem, I thought, eh, I didn't know Rails did that! So I checked use of .build in the real code and it does return EventType. >> >> I'm obviously doing something stupidly wrong in the test but I just can't figure it out. >> >> Any pointers would be greatly appreciated, thank you. > > event_category is a mock_model, not an EventCategory. Since it's declared as_null_object, when it receives :event_types, it returns itself, and then does the same for :build. So it's not really even an EventCategory: it's a the same mock_model object, which is designed to lie about it's class in order to be able to work with form builders. > David, > > Thanks very much for the reply. I was aware I was dealing with a mock, but I thought in this instance it would fool event_types into thinking it was a genuine object to allow the association to be made and return EventType. > > So what are my options? To add the data to the DB or to build the object the long way round > @et = EventType.new(@avalid_attributes) > @et.event_category = event_category ## mock > @et.save! Depends on where this is. I try to use the db in model specs, but avoid it in controller specs. > While I have your ears, is it necessary to replicate the behaviour in the model spec of how a controller builds an object? i.e use .build in the controller and use .new in the spec. I mean, to me, it doesn't matter as all I'm really concerned with is working with the object no matter how it's built. Generally speaking, I agree, but every situation is a little different. > Great piece of software and book, by-the-way. Thanks very much for it. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From anexiole at gmail.com Sun Dec 4 19:15:08 2011 From: anexiole at gmail.com (Gordon) Date: Sun, 4 Dec 2011 16:15:08 -0800 (PST) Subject: [rspec-users] Understanding of extend/include Message-ID: hi, there I have been looking at https://www.relishapp.com/rspec/rspec-core/docs/helper-methods/define-helper-methods-in-a-module. This is the documentation for usage of extend and include. In the section, "Scenario: extend a module in only some example groups", I refer to the setup in RSpec.configure, "c.extend Helpers, :foo => :bar" implies that the methods in Helpers are available to examples with the metadata, ":foo=>:bar". ------------- Extract start --------------- describe "an example group with matching metadata", :foo => :bar do puts "In a matching group, help is #{help}" it "does not have access to the helper methods defined in the module" do expect { help }.to raise_error(NameError) end end ------------- Extract end --------------- Question: Why is the example expected to fail (ie. raise_error(NameError)) when the meta data matches and it's expected to pass? From dchelimsky at gmail.com Sun Dec 4 19:53:16 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 4 Dec 2011 18:53:16 -0600 Subject: [rspec-users] Understanding of extend/include In-Reply-To: References: Message-ID: <573D1F14-ABFC-4533-812F-AC0CF5E496B8@gmail.com> On Dec 4, 2011, at 6:15 PM, Gordon wrote: > hi, there > > I have been looking at > https://www.relishapp.com/rspec/rspec-core/docs/helper-methods/define-helper-methods-in-a-module. > > This is the documentation for usage of extend and include. > > In the section, "Scenario: extend a module in only some example > groups", > I refer to the setup in RSpec.configure, "c.extend Helpers, :foo > => :bar" > implies that the methods in Helpers are available to examples with the > metadata, ":foo=>:bar". > > ------------- Extract start --------------- > > describe "an example group with matching metadata", :foo => :bar do > puts "In a matching group, help is #{help}" > > it "does not have access to the helper methods defined in the > module" do > expect { help }.to raise_error(NameError) > end > end > > ------------- Extract end --------------- > > Question: Why is the example expected to fail (ie. > raise_error(NameError)) > when the meta data matches and it's expected to pass? In Ruby, when we include modules in classes, their methods are available in instances of those classes. module Helper def help :available end end class Foo include Helper end foo = Foo.new foo.help # => :available We can also make the same methods available by extending an instance of a class. class Bar end bar = Bar.new bar.extend(Helper) bar.help # => :available Now the tricky part is that classes are objects as well - instances of the Class class. This means that when you extend a class, its methods are available as class methods, not as instance methods: class Baz extend Helper end Baz.help # => :available Baz.new.help # => ERROR!!!!!!! In RSpec, an example group is a class, whereas an example is (effectively) an instance of that class. This is not 100% accurate, but let's go with that metaphor for the moment. When you say "config.include SomeModule", it gets included into example groups, making its methods available within examples (instances of the group). When you say "config.extend SomeModule", it extends the example group, making its methods available within at the group level, but not within the examples. In the scenario you cite, the module is used to extend the example group matching :foo => :bar (the first group), so it is available at the group level, as demonstrated by `puts "In a matching group, help is #{help}"` printing out "In a matching group, help is available", but is not available in the other group, as demonstrated by `puts "In a non-matching group, help is #{help rescue 'not available'}"` printing out "In a non-matching group, help is not available", and it is not available to examples (instances) in either group, as demonstrated by `expect { help }.to raise_error(NameError)` passing in both examples. HTH, David From mortenmoellerriis at gmail.com Mon Dec 5 07:04:38 2011 From: mortenmoellerriis at gmail.com (=?iso-8859-1?Q?Morten_M=F8ller_Riis?=) Date: Mon, 5 Dec 2011 13:04:38 +0100 Subject: [rspec-users] Spec'ing a block Message-ID: <7F787408-9E0E-404C-8FC3-16755E6968A9@gmail.com> Hi folks How would you spec something like this: as_user username do FileUtils.chmod_R 0755, "#{directory}/*" end Where as_user fires off a new process (and set uid to username). It seems that this won't catch FileUtils.chmod_R: FileUtils.should_receive(:chmod_R).with(0755, "#{@domain.directory}/*") I guess that is because it is passed in the block and fired off in a seperate process (Process.fork). Mvh Morten M?ller Riis From mortenmoellerriis at gmail.com Mon Dec 5 08:21:43 2011 From: mortenmoellerriis at gmail.com (=?iso-8859-1?Q?Morten_M=F8ller_Riis?=) Date: Mon, 5 Dec 2011 14:21:43 +0100 Subject: [rspec-users] Spec'ing a block In-Reply-To: <7F787408-9E0E-404C-8FC3-16755E6968A9@gmail.com> References: <7F787408-9E0E-404C-8FC3-16755E6968A9@gmail.com> Message-ID: <69E8AE6B-99C6-480F-A86F-F7564F9A78AC@gmail.com> For the moment I have done this: def Process.fork(&block) block.call end So that Process.fork doesn't actually spawn a new process but just runs it in the current one. But any better suggestions are welcome :) Mvh Morten M?ller Riis On Dec 5, 2011, at 1:04 PM, Morten M?ller Riis wrote: > Hi folks > > How would you spec something like this: > > as_user username do > FileUtils.chmod_R 0755, "#{directory}/*" > end > > Where as_user fires off a new process (and set uid to username). > > It seems that this won't catch FileUtils.chmod_R: > > FileUtils.should_receive(:chmod_R).with(0755, "#{@domain.directory}/*") > > I guess that is because it is passed in the block and fired off in a seperate process (Process.fork). > > > Mvh > Morten M?ller Riis > > > From matt at mattwynne.net Mon Dec 5 09:39:39 2011 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 5 Dec 2011 14:39:39 +0000 Subject: [rspec-users] Spec'ing a block In-Reply-To: <7F787408-9E0E-404C-8FC3-16755E6968A9@gmail.com> References: <7F787408-9E0E-404C-8FC3-16755E6968A9@gmail.com> Message-ID: On 5 Dec 2011, at 12:04, Morten M?ller Riis wrote: > Hi folks > > How would you spec something like this: > > as_user username do > FileUtils.chmod_R 0755, "#{directory}/*" > end > > Where as_user fires off a new process (and set uid to username). > > It seems that this won't catch FileUtils.chmod_R: > > FileUtils.should_receive(:chmod_R).with(0755, "#{@domain.directory}/*") > > I guess that is because it is passed in the block and fired off in a seperate process (Process.fork). It depends on what you want to prove. If you want to prove that this bit of code will set the actual flags on the actual file, then why not let it do it, and then check that the file ends up how you want it to? If it's happening in a forked process, you'll need to wait for the process to close to be sure it's done, but otherwise that should be quite straightforward, and will give you confidence that the whole thing is working. Otherwise, you need to put a layer around the whole detail of forking and running the FileUtils command, and put your mock assertion against that layer. Right now you're trying to introduce your mock into the stuff that happens in the forked process, which isn't going to work. cheers, Matt -- Freelance programmer & coach Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Helles?y) Founder, http://relishapp.com +44(0)7974430184 | http://twitter.com/mattwynne From mortenmoellerriis at gmail.com Mon Dec 5 10:13:26 2011 From: mortenmoellerriis at gmail.com (=?iso-8859-1?Q?Morten_M=F8ller_Riis?=) Date: Mon, 5 Dec 2011 16:13:26 +0100 Subject: [rspec-users] Spec'ing a block In-Reply-To: References: <7F787408-9E0E-404C-8FC3-16755E6968A9@gmail.com> Message-ID: Hi Matt Thank you for your reply! I mock things like FileUtils for the following reasons: to avoid testing FileUtils which I reckon has its own test suite and to avoid doing potentially harmful things locally or having specs fail because of insufficient permissions etc. I know the last bit could be worked out, but for things like #rm_r I do like just to mock them. Please let me know if this is not best practice. I know one can "over-mock" a spec suite, but I generally tend to mock things that are tested/spec'ed themselves. Mvh Morten M?ller Riis On Dec 5, 2011, at 3:39 PM, Matt Wynne wrote: > > On 5 Dec 2011, at 12:04, Morten M?ller Riis wrote: > >> Hi folks >> >> How would you spec something like this: >> >> as_user username do >> FileUtils.chmod_R 0755, "#{directory}/*" >> end >> >> Where as_user fires off a new process (and set uid to username). >> >> It seems that this won't catch FileUtils.chmod_R: >> >> FileUtils.should_receive(:chmod_R).with(0755, "#{@domain.directory}/*") >> >> I guess that is because it is passed in the block and fired off in a seperate process (Process.fork). > > > It depends on what you want to prove. > > If you want to prove that this bit of code will set the actual flags on the actual file, then why not let it do it, and then check that the file ends up how you want it to? If it's happening in a forked process, you'll need to wait for the process to close to be sure it's done, but otherwise that should be quite straightforward, and will give you confidence that the whole thing is working. > > Otherwise, you need to put a layer around the whole detail of forking and running the FileUtils command, and put your mock assertion against that layer. Right now you're trying to introduce your mock into the stuff that happens in the forked process, which isn't going to work. > > cheers, > Matt > > -- > Freelance programmer & coach > Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Helles?y) > Founder, http://relishapp.com > +44(0)7974430184 | http://twitter.com/mattwynne > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Dec 5 12:21:34 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 5 Dec 2011 11:21:34 -0600 Subject: [rspec-users] Spec'ing a block In-Reply-To: References: <7F787408-9E0E-404C-8FC3-16755E6968A9@gmail.com> Message-ID: On Mon, Dec 5, 2011 at 9:13 AM, Morten M?ller Riis wrote: > Hi Matt > > Thank you for your reply! > > I mock things like FileUtils for the following reasons: to avoid testing > FileUtils which I reckon has its own test suite and to avoid doing > potentially harmful things locally or having specs fail because of > insufficient permissions etc. I know the last bit could be worked out, but > for things like #rm_r I do like just to mock them. Have you looked at FakeFS? It is faster than actually working on the filesystem, and it avoids problems like accidentally deleting stuff. > Please let me know if this is not best practice. I know one can "over-mock" > a spec suite, but I generally tend to mock things that are tested/spec'ed > themselves. > > Mvh > Morten M?ller Riis > > > > On Dec 5, 2011, at 3:39 PM, Matt Wynne wrote: > > > On 5 Dec 2011, at 12:04, Morten M?ller Riis wrote: > > Hi folks > > > How would you spec something like this: > > > ??as_user username do > > ????FileUtils.chmod_R 0755, "#{directory}/*" > > ??end > > > Where as_user fires off a new process (and set uid to username). > > > It seems that this won't catch FileUtils.chmod_R: > > > FileUtils.should_receive(:chmod_R).with(0755, "#{@domain.directory}/*") > > > I guess that is because it is passed in the block and fired off in a > seperate process (Process.fork). > > > > It depends on what you want to prove. > > If you want to prove that this bit of code will set the actual flags on the > actual file, then why not let it do it, and then check that the file ends up > how you want it to? If it's happening in a forked process, you'll need to > wait for the process to close to be sure it's done, but otherwise that > should be quite straightforward, and will give you confidence that the whole > thing is working. > > Otherwise, you need to put a layer around the whole detail of forking and > running the FileUtils command, and put your mock assertion against that > layer. Right now you're trying to introduce your mock into the stuff that > happens in the forked process, which isn't going to work. > > cheers, > Matt > > -- > Freelance programmer & coach > Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak > Helles?y) > Founder, http://relishapp.com > +44(0)7974430184 | http://twitter.com/mattwynne > > _______________________________________________ > 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 anexiole at gmail.com Mon Dec 5 17:53:29 2011 From: anexiole at gmail.com (Gordon) Date: Mon, 5 Dec 2011 14:53:29 -0800 (PST) Subject: [rspec-users] How to extend common helper methods to view specs? Message-ID: <53a9e7c6-568b-4245-b259-586719c3f2ee@c13g2000vbh.googlegroups.com> Hi, there, I have some methods which I have written as helpers. They are in spec/support/controller_macros.rb (yes, I will change the name soon). The 2 methods, login_user and login_admin_user works in the controller specs BUT fail to work in the view specs when I call them in the view specs. ---------- spec/spec_helper.rb start -------------------------- # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'webrat' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| config.include Devise::TestHelpers, :type => :controller config.extend ControllerMacros, :type => :view config.extend ControllerMacros, :type => :controller config.before(:suite) do DatabaseCleaner.strategy = :transaction DatabaseCleaner.clean_with(:truncation) end config.before(:each) do DatabaseCleaner.start end config.after(:each) do DatabaseCleaner.clean end end ---------- spec/spec_helper.rb end -------------------------- i am already extending it to the view (ie. 'config.extend ControllerMacros, :type => :controller'). What am I missing? Thank you Gordon From jko170 at gmail.com Mon Dec 5 21:00:03 2011 From: jko170 at gmail.com (Justin Ko) Date: Mon, 5 Dec 2011 19:00:03 -0700 Subject: [rspec-users] How to extend common helper methods to view specs? In-Reply-To: <53a9e7c6-568b-4245-b259-586719c3f2ee@c13g2000vbh.googlegroups.com> References: <53a9e7c6-568b-4245-b259-586719c3f2ee@c13g2000vbh.googlegroups.com> Message-ID: <3DBC5853-ADF1-46AC-8051-78F67A01B933@gmail.com> On Dec 5, 2011, at 3:53 PM, Gordon wrote: > Hi, there, > > I have some methods which I have written as helpers. > They are in spec/support/controller_macros.rb (yes, I will change the > name soon). > > The 2 methods, login_user and login_admin_user works in the > controller specs BUT fail to work in the view specs when I call them > in the view specs. > > ---------- spec/spec_helper.rb start -------------------------- > > # This file is copied to spec/ when you run 'rails generate > rspec:install' > ENV["RAILS_ENV"] ||= 'test' > require File.expand_path("../../config/environment", __FILE__) > require 'rspec/rails' > require 'webrat' > > # Requires supporting ruby files with custom matchers and macros, etc, > # in spec/support/ and its subdirectories. > Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} > > RSpec.configure do |config| > > config.include Devise::TestHelpers, :type => :controller > config.extend ControllerMacros, :type => :view > config.extend ControllerMacros, :type => :controller > > config.before(:suite) do > DatabaseCleaner.strategy = :transaction > DatabaseCleaner.clean_with(:truncation) > end > > config.before(:each) do > DatabaseCleaner.start > end > > config.after(:each) do > DatabaseCleaner.clean > end > > > end > > > ---------- spec/spec_helper.rb end -------------------------- > > i am already extending it to the view (ie. 'config.extend > ControllerMacros, :type => :controller'). > > What am I missing? > > Thank you > > Gordon > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users What are you trying to do in the methods? You can probably just stub what you need: https://www.relishapp.com/rspec/rspec-rails/docs/view-specs/view-spec#6 From lists at ruby-forum.com Tue Dec 6 01:14:21 2011 From: lists at ruby-forum.com (Andres M.) Date: Tue, 06 Dec 2011 07:14:21 +0100 Subject: [rspec-users] rspect weird problem Message-ID: Hello everyone, this is really urgent so ill be quick, here is some ruby code that i know works: require 'csv' class Motorcycle attr_reader :name, :weight @@count = 0 def self.find (name) found = nil ObjectSpace.each_object(Motorcycle) { |o| found = o if o.name == name } return found end def self.create File.new('motorcycles.csv').readlines[1..-1].map{ |line| Motorcycle.new( *line.split( ',' ) ) } end def initialize (name, weight) @name = name @weight = weight self.class.count += 1 end def self.count return @@count end def self.count=( count ) @@count = count end def available_colors colors=[] colorsFile = File.read('colors.csv').split("\n").map { |line| line.split(',') } for i in (0..colorsFile.flatten.length) do if (colorsFile.flatten[i].to_s == self.name.to_s) colors.push(colorsFile.flatten[i+1]) end end return colors end def contains (name,color) if(self.name.to_s == name) else return color end end def has_abs? File.open( 'abs.txt' ) do |io| io.each {|line| line.chomp! ; return true if line.include? self.name.to_s} end return false end end Motrocicle.create the code must pass this tests on rspec: describe Motorcycle do describe "loading the motorcycle list" do it "should load 2 motorcycles from the CSV" do Motorcycle.count.should == 2 end end describe "finding a motorcycle by name" do it "should return an instance of the Motorcycle class" do Motorcycle.find("1200 RT").should be_a Motorcycle end end describe "#weight" do it "should have a weight of 800 pounds for the 1200 RT" do Motorcycle.find("1200 RT").weight.should == '800 pounds' end it "should have a weight of 500 pounds for the 600 GS" do Motorcycle.find("600 GS").weight.should == '500 pounds' end end describe "#available colors" do it "should find 'red' and 'black' as available colors for the BMW 1200 RT" do Motorcycle.find("1200 RT").available_colors.should == [ 'red', 'black' ] end it "should find 'green' and 'blue' as available colors for the BMW 600 GS" do Motorcycle.find("600 GS").available_colors.should == [ 'green', 'blue' ] end end describe "#has_abs?" do it "should be true for a motorcycle that appears in abs_motorcycles.txt" do Motorcycle.find("1200 RT").has_abs?.should be_true end it "should be false for a motorcycle that does not appear in abs_motorcycles.txt" do Motorcycle.find("600 GS").has_abs?.should be_false end end end problem is, after the first test (where it counts the amount of motrocicle instances) every instance is a nil, thats t say, every test is failed except for the fist one. here is the output log: Failures: 1) Motorcycle finding a motorcycle by name should return an instance of the Motorcycle class Failure/Error: Unable to find matching line from backtrace expected nil to be a kind of Motorcycle # ./motoapp.rb:76 2) Motorcycle#weight should have a weight of 800 pounds for the 1200 RT Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `weight' for nil:NilClass # ./motoapp.rb:82 3) Motorcycle#weight should have a weight of 500 pounds for the 600 GS Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `weight' for nil:NilClass # ./motoapp.rb:86 4) Motorcycle#available colors should find 'red' and 'black' as available colors for the BMW 1200 RT Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `available_colors' for nil:NilClass # ./motoapp.rb:92 5) Motorcycle#available colors should find 'green' and 'blue' as available colors for the BMW 600 GS Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `available_colors' for nil:NilClass # ./motoapp.rb:96 6) Motorcycle#has_abs? should be true for a motorcycle that appears in abs_motorcycles.txt Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `has_abs?' for nil:NilClass # ./motoapp.rb:102 7) Motorcycle#has_abs? should be false for a motorcycle that does not appear in abs_motorcycles.txt Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `has_abs?' for nil:NilClass # ./motoapp.rb:106 Finished in 0.01223 seconds 8 examples, 7 failures i have been inclined to think this is some kind of bug or something due to my result doing the manual test like this: puts Motorcycle.count puts Motorcycle.find("1200 RT") puts Motorcycle.find("1200 RT").weight puts Motorcycle.find("600 GS").weight puts Motorcycle.find("1200 RT").available_colors puts Motorcycle.find("600 GS").available_colors puts Motorcycle.find("1200 RT").has_abs? puts Motorcycle.find("600 GS").has_abs? which give me this output: 2 # 800 pounds 500 pounds red black green blue true false so i'm really pretty much on a dead end, ?does anyone have a clue as to what could be happening?. -- Posted via http://www.ruby-forum.com/. From patrick at collinatorstudios.com Tue Dec 6 01:56:13 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Mon, 5 Dec 2011 22:56:13 -0800 (PST) Subject: [rspec-users] rspect weird problem In-Reply-To: References: Message-ID: > Motrocicle.create I don't know if this helps, but I am pretty sure "Motrocicle.create" isn't what you intended to call. Also, I'd like to point out that: > def self.find (name) > found = nil > ObjectSpace.each_object(Motorcycle) { |o| > found = o if o.name == name > } > return found > end > Is very inefficient because it's going to keep iterating through all the objects even after it's found the one it's looking for. def self.find(name) ObjectSpace.each_object(Motorcycle) do |o| return o if o.name == name end end Will return found object immediately or nil if nothing is found. Patrick J. Collins http://collinatorstudios.com From lists at ruby-forum.com Tue Dec 6 02:27:51 2011 From: lists at ruby-forum.com (Andres M.) Date: Tue, 06 Dec 2011 08:27:51 +0100 Subject: [rspec-users] rspect weird problem In-Reply-To: References: Message-ID: <7cbe372a9967ce8bcd40794c3df226e6@ruby-forum.com> Patrick Collins wrote in post #1035294: >> Motrocicle.create > > I don't know if this helps, but I am pretty sure "Motrocicle.create" > isn't what > you intended to call. > > Also, I'd like to point out that: > >> def self.find (name) >> found = nil >> ObjectSpace.each_object(Motorcycle) { |o| >> found = o if o.name == name >> } >> return found >> end >> > > Is very inefficient because it's going to keep iterating through all the > objects even after it's found the one it's looking for. > > def self.find(name) > ObjectSpace.each_object(Motorcycle) do |o| > return o if o.name == name > end > end > > Will return found object immediately or nil if nothing is found. > > Patrick J. Collins > http://collinatorstudios.com ok that was just and error when i copy the code to this post this is the rspec output with the problem corrected and the "manual script" also includes, (by the way thanks for the advice, your find method is better, i dont know how could i just miss it, thanks :D). q_ro at thor:~/Escritorio/motorcycle_test_app$ rspec motoapp.rb 2 # 800 pounds 500 pounds red black green blue true false .FFFFFFF Failures: 1) Motorcycle finding a motorcycle by name should return an instance of the Motorcycle class Failure/Error: Unable to find matching line from backtrace expected 0 to be a kind of Motorcycle # ./motoapp.rb:75 2) Motorcycle#weight should have a weight of 800 pounds for the 1200 RT Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `weight' for 0:Fixnum # ./motoapp.rb:81 3) Motorcycle#weight should have a weight of 500 pounds for the 600 GS Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `weight' for 0:Fixnum # ./motoapp.rb:85 4) Motorcycle#available colors should find 'red' and 'black' as available colors for the BMW 1200 RT Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `available_colors' for 0:Fixnum # ./motoapp.rb:91 5) Motorcycle#available colors should find 'green' and 'blue' as available colors for the BMW 600 GS Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `available_colors' for 0:Fixnum # ./motoapp.rb:95 6) Motorcycle#has_abs? should be true for a motorcycle that appears in abs_motorcycles.txt Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `has_abs?' for 0:Fixnum # ./motoapp.rb:101 7) Motorcycle#has_abs? should be false for a motorcycle that does not appear in abs_motorcycles.txt Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `has_abs?' for 0:Fixnum # ./motoapp.rb:105 Finished in 0.0119 seconds 8 examples, 7 failures i really don't get it. -- Posted via http://www.ruby-forum.com/. From patrick at collinatorstudios.com Tue Dec 6 03:20:32 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Tue, 6 Dec 2011 00:20:32 -0800 (PST) Subject: [rspec-users] rspect weird problem In-Reply-To: <7cbe372a9967ce8bcd40794c3df226e6@ruby-forum.com> References: <7cbe372a9967ce8bcd40794c3df226e6@ruby-forum.com> Message-ID: > 1) Motorcycle finding a motorcycle by name should return an instance > of the Motorcycle class > Failure/Error: Unable to find matching line from backtrace > expected 0 to be a kind of Motorcycle > # ./motoapp.rb:75 I also am noticing that you don't have any sort of setup for your test.. In order for your find method to be able to retrieve anything, I believe you are going to need to call .create prior to it. describe Motorcycle do before :each do Motorcycle.create end describe "finding a motorcycle by name" do ...etc end end Patrick J. Collins http://collinatorstudios.com From mortenmoellerriis at gmail.com Tue Dec 6 09:27:55 2011 From: mortenmoellerriis at gmail.com (=?iso-8859-1?Q?Morten_M=F8ller_Riis?=) Date: Tue, 6 Dec 2011 15:27:55 +0100 Subject: [rspec-users] Spec'ing a block In-Reply-To: References: <7F787408-9E0E-404C-8FC3-16755E6968A9@gmail.com> Message-ID: <0C5ED5DA-DAFE-45BB-B286-52C534A74A8B@gmail.com> FakeFS definitely looks like a nice solution! I also like the argument about not tightly coupling the specs to File and FileUtils. Mvh Morten M?ller Riis On Dec 5, 2011, at 6:21 PM, David Chelimsky wrote: > On Mon, Dec 5, 2011 at 9:13 AM, Morten M?ller Riis > wrote: >> Hi Matt >> >> Thank you for your reply! >> >> I mock things like FileUtils for the following reasons: to avoid testing >> FileUtils which I reckon has its own test suite and to avoid doing >> potentially harmful things locally or having specs fail because of >> insufficient permissions etc. I know the last bit could be worked out, but >> for things like #rm_r I do like just to mock them. > > Have you looked at FakeFS? It is faster than actually working on the > filesystem, and it avoids problems like accidentally deleting stuff. > >> Please let me know if this is not best practice. I know one can "over-mock" >> a spec suite, but I generally tend to mock things that are tested/spec'ed >> themselves. >> >> Mvh >> Morten M?ller Riis >> >> >> >> On Dec 5, 2011, at 3:39 PM, Matt Wynne wrote: >> >> >> On 5 Dec 2011, at 12:04, Morten M?ller Riis wrote: >> >> Hi folks >> >> >> How would you spec something like this: >> >> >> as_user username do >> >> FileUtils.chmod_R 0755, "#{directory}/*" >> >> end >> >> >> Where as_user fires off a new process (and set uid to username). >> >> >> It seems that this won't catch FileUtils.chmod_R: >> >> >> FileUtils.should_receive(:chmod_R).with(0755, "#{@domain.directory}/*") >> >> >> I guess that is because it is passed in the block and fired off in a >> seperate process (Process.fork). >> >> >> >> It depends on what you want to prove. >> >> If you want to prove that this bit of code will set the actual flags on the >> actual file, then why not let it do it, and then check that the file ends up >> how you want it to? If it's happening in a forked process, you'll need to >> wait for the process to close to be sure it's done, but otherwise that >> should be quite straightforward, and will give you confidence that the whole >> thing is working. >> >> Otherwise, you need to put a layer around the whole detail of forking and >> running the FileUtils command, and put your mock assertion against that >> layer. Right now you're trying to introduce your mock into the stuff that >> happens in the forked process, which isn't going to work. >> >> cheers, >> Matt >> >> -- >> Freelance programmer & coach >> Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak >> Helles?y) >> Founder, http://relishapp.com >> +44(0)7974430184 | http://twitter.com/mattwynne >> >> _______________________________________________ >> 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: From lists at ruby-forum.com Tue Dec 6 09:59:45 2011 From: lists at ruby-forum.com (Andres M.) Date: Tue, 06 Dec 2011 15:59:45 +0100 Subject: [rspec-users] rspect weird problem In-Reply-To: References: Message-ID: <3f853575831a56fa7fbcc8bb5531ddf2@ruby-forum.com> no, that didn't work, but i found that i may be due to garbage collector taking place before test starts, so the solution was to add a set called instances and then in the initialize method put the following code line "instances << self", this way my instances had a root, preventing the garbage collector from trashing my class instances. -- Posted via http://www.ruby-forum.com/. From forum at erisiandiscord.de Tue Dec 6 15:30:02 2011 From: forum at erisiandiscord.de (Nikolay Sturm) Date: Tue, 6 Dec 2011 21:30:02 +0100 Subject: [rspec-users] modelling roles and responsibilities Message-ID: <20111206203002.GA2453@erisiandiscord.de> Hi, reading "Growing Object-Oriented Software, guided by tests", I came across the distinction of class, role and responsibility. While classes are classes and responsibilities could be mapped to public methods, I wonder how to specify roles in my specs. Does anyone have experiences with this? cheers, Nikolay -- "It's all part of my Can't-Do approach to life." Wally From dchelimsky at gmail.com Tue Dec 6 23:50:55 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 6 Dec 2011 22:50:55 -0600 Subject: [rspec-users] modelling roles and responsibilities In-Reply-To: <20111206203002.GA2453@erisiandiscord.de> References: <20111206203002.GA2453@erisiandiscord.de> Message-ID: <2A8CAD1A-F433-4C2C-8300-5F402A7E17E2@gmail.com> On Dec 6, 2011, at 2:30 PM, Nikolay Sturm wrote: > Hi, > > reading "Growing Object-Oriented Software, guided by tests", I came > across the distinction of class, role and responsibility. > > While classes are classes and responsibilities could be mapped to public > methods, I wonder how to specify roles in my specs. Does anyone have > experiences with this? > > cheers, > > Nikolay https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples From forum at erisiandiscord.de Wed Dec 7 04:57:51 2011 From: forum at erisiandiscord.de (Nikolay Sturm) Date: Wed, 7 Dec 2011 10:57:51 +0100 Subject: [rspec-users] modelling roles and responsibilities In-Reply-To: <2A8CAD1A-F433-4C2C-8300-5F402A7E17E2@gmail.com> References: <20111206203002.GA2453@erisiandiscord.de> <2A8CAD1A-F433-4C2C-8300-5F402A7E17E2@gmail.com> Message-ID: <20111207095751.GA14298@erisiandiscord.de> * David Chelimsky [2011-12-07]: > > reading "Growing Object-Oriented Software, guided by tests", I came > > across the distinction of class, role and responsibility. > > > > While classes are classes and responsibilities could be mapped to public > > methods, I wonder how to specify roles in my specs. Does anyone have > > experiences with this? > > > > cheers, > > > > Nikolay > > https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples Sorry, but I don't see how that helps. In my understanding, roles are a set of related responsibilities. If responsibilities map roughly to public methods, than a role should be a subset of a class' API. I don't see where I should want to share example groups. cheers, Nikolay -- "It's all part of my Can't-Do approach to life." Wally From patmaddox at me.com Wed Dec 7 05:07:07 2011 From: patmaddox at me.com (Pat Maddox) Date: Wed, 07 Dec 2011 02:07:07 -0800 Subject: [rspec-users] modelling roles and responsibilities In-Reply-To: <20111207095751.GA14298@erisiandiscord.de> References: <20111206203002.GA2453@erisiandiscord.de> <2A8CAD1A-F433-4C2C-8300-5F402A7E17E2@gmail.com> <20111207095751.GA14298@erisiandiscord.de> Message-ID: <14B06317-8279-43DB-9690-208FF5E0A5D6@me.com> On Dec 7, 2011, at 1:57 AM, Nikolay Sturm wrote: > * David Chelimsky [2011-12-07]: >>> reading "Growing Object-Oriented Software, guided by tests", I came >>> across the distinction of class, role and responsibility. >>> >>> While classes are classes and responsibilities could be mapped to public >>> methods, I wonder how to specify roles in my specs. Does anyone have >>> experiences with this? >>> >>> cheers, >>> >>> Nikolay >> >> https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples > > Sorry, but I don't see how that helps. In my understanding, roles are a > set of related responsibilities. If responsibilities map roughly to > public methods, than a role should be a subset of a class' API. I don't > see where I should want to share example groups. You can use shared example groups to test a subset of a class's API. Pat From dchelimsky at gmail.com Wed Dec 7 07:40:54 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 7 Dec 2011 06:40:54 -0600 Subject: [rspec-users] modelling roles and responsibilities In-Reply-To: <14B06317-8279-43DB-9690-208FF5E0A5D6@me.com> References: <20111206203002.GA2453@erisiandiscord.de> <2A8CAD1A-F433-4C2C-8300-5F402A7E17E2@gmail.com> <20111207095751.GA14298@erisiandiscord.de> <14B06317-8279-43DB-9690-208FF5E0A5D6@me.com> Message-ID: <66E30423-860A-4233-870F-485166BACA63@gmail.com> On Dec 7, 2011, at 4:07 AM, Pat Maddox wrote: > On Dec 7, 2011, at 1:57 AM, Nikolay Sturm wrote: > >> * David Chelimsky [2011-12-07]: >>>> reading "Growing Object-Oriented Software, guided by tests", I came >>>> across the distinction of class, role and responsibility. >>>> >>>> While classes are classes and responsibilities could be mapped to public >>>> methods, I wonder how to specify roles in my specs. Does anyone have >>>> experiences with this? >>>> >>>> cheers, >>>> >>>> Nikolay >>> >>> https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples >> >> Sorry, but I don't see how that helps. In my understanding, roles are a >> set of related responsibilities. If responsibilities map roughly to >> public methods, than a role should be a subset of a class' API. I don't >> see where I should want to share example groups. > > You can use shared example groups to test a subset of a class's API. Nikolay - just because they're shareable doesn't mean they have to be shared :) As Pat suggests, you can use them to specify a subset of a single object's API. That said, one goal of thinking of roles is code that is easy to extend thanks to polymorphism. You might have onlly one class that satisfies a role now, but you might add another later. Shared examples allow you to just drop in a spec for that part of the new object's responsibilities. I blogged about this a while back: http://blog.davidchelimsky.net/2010/11/07/specifying-mixins-with-shared-example-groups-in-rspec-2/ - the focus of that entry is on Modules, but you could just as easily think in terms of roles (since a Module often represents a role). The stuff about spec'ing the what happens when you include the module doesn't really apply, but the stuff about spec'ing similar behavior across different objects does. HTH, David From lists at ruby-forum.com Wed Dec 7 13:48:37 2011 From: lists at ruby-forum.com (Alex Whiteland) Date: Wed, 07 Dec 2011 19:48:37 +0100 Subject: [rspec-users] cucumber is_admin? testing In-Reply-To: <201a8df12f34c8d36a46c0979314f1e7@ruby-forum.com> References: <201a8df12f34c8d36a46c0979314f1e7@ruby-forum.com> Message-ID: <31e1b9b0ac886acb2a9ffd4276f20a20@ruby-forum.com> hmm... I changed 2 servers to friend with google. wtf? first - 37.com, second - hushmail.com Maybe, google think it is spam and sends to it folder. Can yo find my letters in it? -- Posted via http://www.ruby-forum.com/. From chabgood at gmail.com Wed Dec 7 15:00:52 2011 From: chabgood at gmail.com (Chris Habgood) Date: Wed, 7 Dec 2011 14:00:52 -0600 Subject: [rspec-users] cucumber is_admin? testing In-Reply-To: <31e1b9b0ac886acb2a9ffd4276f20a20@ruby-forum.com> References: <201a8df12f34c8d36a46c0979314f1e7@ruby-forum.com> <31e1b9b0ac886acb2a9ffd4276f20a20@ruby-forum.com> Message-ID: This is an rspec mailing list. On Wed, Dec 7, 2011 at 12:48, Alex Whiteland wrote: > hmm... > > I changed 2 servers to friend with google. wtf? > > first - 37.com, > second - hushmail.com > > Maybe, google think it is spam and sends to it folder. Can yo find my > letters in it? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- *"In matters of style, swim with the current; in matters of principle, stand like a rock." Thomas Jefferson * -------------- next part -------------- An HTML attachment was scrubbed... URL: From joliss42 at gmail.com Thu Dec 8 16:30:54 2011 From: joliss42 at gmail.com (Jo Liss) Date: Thu, 8 Dec 2011 22:30:54 +0100 Subject: [rspec-users] Expecting multiple changes (chaining) Message-ID: Hi RSpec list, I have a question about the "expect { ... }.to change" construct (https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/expect-change): Is there an idiomatic way to test for multiple changes (i.e. chaining)? Right now I'm doing expect { expect { foobuzz }.to change { a } }.to change { b } to test that calling foobuzz changes a and b. Is there a more compact way? (Using tap turns out rather ugly: .tap { |proc| proc.to change { a } }. Not an improvement IMO.) Thanks, Jo -- Jo Liss - http://electicvoting.com/ Blog: http://opinionatedprogrammer.com/ From dchelimsky at gmail.com Thu Dec 8 17:30:58 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 8 Dec 2011 16:30:58 -0600 Subject: [rspec-users] Expecting multiple changes (chaining) In-Reply-To: References: Message-ID: On Thu, Dec 8, 2011 at 3:30 PM, Jo Liss wrote: > Hi RSpec list, > > I have a question about the "expect { ... }.to change" construct > (https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/expect-change): > > Is there an idiomatic way to test for multiple changes (i.e. chaining)? > > Right now I'm doing > > ? ?expect { > ? ? ?expect { > ? ? ? ?foobuzz > ? ? ?}.to change { a } > ? ?}.to change { b } > > to test that calling foobuzz changes a and b. Is there a more compact way? If there are two outcomes, then I like to write two examples: it "changes a" do expect { foobuzz }.to change {a} end it "changes b" do expect { foobuzz }.to change {b} end HTH, David From patrick at collinatorstudios.com Fri Dec 9 02:02:51 2011 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Thu, 8 Dec 2011 23:02:51 -0800 (PST) Subject: [rspec-users] how to test arguments going into a mailer method? Message-ID: Hi, So I am not really interested in testing the content of the actual body of an outgoing email. I trust that Rails' internal mechanisms work, however recently I came across some code that did something that I did want to test: --- class PaypalProcessor def send_email Notifier.paypal_error(@errors, @params.merge(decoded_custom_params)).deliver end end --- ... I simply wanted to verify that the variables being passed into my ActionMailer::Base subclass are exactly what I expect them to be. I felt that this is pretty much all that I need to test (other than verifying that the actual email will be sent). So I wrote the following test: --- before :each do @encoded = Base64.encode64s({ :post_id => @post.id, :user_id => @user.id }).to_json @processor = PaypalProcessor.new(:params => { :custom => @encoded, :foo => "bar" }) end it "sends an email to notify us of invalid data" do @processor.should_not be_valid Notifier.expects(:new).with(:paypal_error, @errors, { :post_id => @post.id, :user_id => @user.id, :foo => "bar", :custom => @encoded }) # note: I wrote the above expectation that way based off of what I saw in # ActionMailer::Base's code.. It uses method missing and does: # new(method, *args).message lambda { @processor.send_email }.should change(ActionMailer::Base.deliveries, :count).by(1) end --- I get this failure: 1) PaypalParamProcessor validation sends an email to notify us of invalid data Failure/Error: lambda { @processor.send_email }.should change(ActionMailer::Base.deliveries, :count).by(1) Mocha::ExpectationError: unexpected invocation: Notifier.new(:paypal_error, ['paypal did not verify the transaction!', 'paypal notified us of a payment with an invalid gross amount!', 'paypal gave a currency code other than USD!', 'paypal shows this transaction as belonging to another business!'], {:post_id => 430, :user_id => 538, :foo => 'bar', :custom => 'eyJwb3N0X2lkIjo0MzAsInVzZXJfaWQiOjUzOH0='}) unsatisfied expectations: - expected exactly once, not yet invoked: Notifier.new(:paypal_error, nil, {:post_id => 430, :user_id => 538, :foo => 'bar', :custom => 'eyJwb3N0X2lkIjo0MzAsInVzZXJfaWQiOjUzOH0='}) satisfied expectations: - allowed any number of times, invoked once: #.acknowledge(any_parameters) - allowed any number of times, invoked once: #.complete?(any_parameters) - allowed any number of times, invoked once: #.gross(any_parameters) - allowed any number of times, not yet invoked: #.acknowledge(any_parameters) - allowed any number of times, invoked once: ActiveMerchant::Billing::Integrations::Paypal::Notification.new(any_parameters) # ./lib/paypal_param_processor.rb:43:in `send_email' # ./spec/lib/paypal_param_processor_spec.rb:63 # ./spec/lib/paypal_param_processor_spec.rb:63 --- So, obviously my approach isn't so great. Can anyone assist me with a better way to do this? Patrick J. Collins http://collinatorstudios.com From forum at erisiandiscord.de Fri Dec 9 02:57:52 2011 From: forum at erisiandiscord.de (Nikolay Sturm) Date: Fri, 9 Dec 2011 08:57:52 +0100 Subject: [rspec-users] modelling roles and responsibilities In-Reply-To: <66E30423-860A-4233-870F-485166BACA63@gmail.com> References: <20111206203002.GA2453@erisiandiscord.de> <2A8CAD1A-F433-4C2C-8300-5F402A7E17E2@gmail.com> <20111207095751.GA14298@erisiandiscord.de> <14B06317-8279-43DB-9690-208FF5E0A5D6@me.com> <66E30423-860A-4233-870F-485166BACA63@gmail.com> Message-ID: <20111209075751.GA5340@erisiandiscord.de> * David Chelimsky [2011-12-07]: > Nikolay - just because they're shareable doesn't mean they have to be > shared :) As Pat suggests, you can use them to specify a subset of a > single object's API. That said, one goal of thinking of roles is code > that is easy to extend thanks to polymorphism. You might have onlly > one class that satisfies a role now, but you might add another later. > Shared examples allow you to just drop in a spec for that part of the > new object's responsibilities. Ah great, the missing pieces! I hadn't thought about polymorphism and roles. This finally makes sense. :) cheers everyone, Nikolay -- "It's all part of my Can't-Do approach to life." Wally From mortenmoellerriis at gmail.com Fri Dec 9 05:03:46 2011 From: mortenmoellerriis at gmail.com (=?iso-8859-1?Q?Morten_M=F8ller_Riis?=) Date: Fri, 9 Dec 2011 11:03:46 +0100 Subject: [rspec-users] how to test arguments going into a mailer method? In-Reply-To: References: Message-ID: <3B8E2E05-5126-4186-AAB6-740C14117020@gmail.com> How about this? paypal_error = mock('paypal_error') paypal_error.should_receive(:deliver) Notifier.should_receive(:paypal_error).with(@errors, hash_including({ :post_id => @post.id, :user_id => @user.id, :foo => "bar", :custom => @encoded })).and_yield(paypal_error) Mvh Morten M?ller Riis On Dec 9, 2011, at 8:02 AM, Patrick J. Collins wrote: > Hi, > > So I am not really interested in testing the content of the actual body of an > outgoing email. I trust that Rails' internal mechanisms work, however recently > I came across some code that did something that I did want to test: > > --- > > class PaypalProcessor > > def send_email > Notifier.paypal_error(@errors, @params.merge(decoded_custom_params)).deliver > end > > end > > --- > > > ... I simply wanted to verify that the variables being passed into my > ActionMailer::Base subclass are exactly what I expect them to be. I felt that > this is pretty much all that I need to test (other than verifying that the > actual email will be sent). So I wrote the following test: > > > --- > > > before :each do > @encoded = Base64.encode64s({ :post_id => @post.id, :user_id => @user.id }).to_json > @processor = PaypalProcessor.new(:params => { :custom => @encoded, :foo => "bar" }) > end > > it "sends an email to notify us of invalid data" do > @processor.should_not be_valid > > Notifier.expects(:new).with(:paypal_error, @errors, { :post_id => @post.id, > :user_id => @user.id, > :foo => "bar", > :custom => @encoded }) > > # note: I wrote the above expectation that way based off of what I saw in > # ActionMailer::Base's code.. It uses method missing and does: > # new(method, *args).message > > lambda { @processor.send_email }.should change(ActionMailer::Base.deliveries, :count).by(1) > end > > > --- > > > I get this failure: > > 1) PaypalParamProcessor validation sends an email to notify us of invalid data > Failure/Error: lambda { @processor.send_email }.should change(ActionMailer::Base.deliveries, :count).by(1) > Mocha::ExpectationError: > unexpected invocation: Notifier.new(:paypal_error, ['paypal did not verify the transaction!', 'paypal notified us of a payment with an invalid gross amount!', 'paypal gave a currency code other than USD!', 'paypal shows this transaction as belonging to another business!'], {:post_id => 430, :user_id => 538, :foo => 'bar', :custom => 'eyJwb3N0X2lkIjo0MzAsInVzZXJfaWQiOjUzOH0='}) > unsatisfied expectations: > - expected exactly once, not yet invoked: Notifier.new(:paypal_error, nil, {:post_id => 430, :user_id => 538, :foo => 'bar', :custom => 'eyJwb3N0X2lkIjo0MzAsInVzZXJfaWQiOjUzOH0='}) > satisfied expectations: > - allowed any number of times, invoked once: #.acknowledge(any_parameters) > - allowed any number of times, invoked once: #.complete?(any_parameters) > - allowed any number of times, invoked once: #.gross(any_parameters) > - allowed any number of times, not yet invoked: #.acknowledge(any_parameters) > - allowed any number of times, invoked once: ActiveMerchant::Billing::Integrations::Paypal::Notification.new(any_parameters) > # ./lib/paypal_param_processor.rb:43:in `send_email' > # ./spec/lib/paypal_param_processor_spec.rb:63 > # ./spec/lib/paypal_param_processor_spec.rb:63 > > --- > > So, obviously my approach isn't so great. Can anyone assist me with a better way to do this? > > Patrick J. Collins > http://collinatorstudios.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From lbocseg at yahoo.com.br Fri Dec 9 12:14:05 2011 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Fri, 09 Dec 2011 15:14:05 -0200 Subject: [rspec-users] Strange time reporting Message-ID: <4EE241DD.5030800@yahoo.com.br> While running some specs of a new fresh Rails 3.1 project with latest Rspec, I'm getting some strange time reporting (using --drb and spork): Finished in 731.67 seconds 10 examples, 0 failures But it actually run "time rake" in less than 2s. "time rspec" runs in about 0.2s. The finished time is always increasing. How do I reset the time on each run with Spork? Yes, I know it is more likely to be a Spork-specific issue, but maybe there are other Rspec users here using Spork that have already some solution to this. Cheers, Rodrigo. From lbocseg at yahoo.com.br Fri Dec 9 12:15:48 2011 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Fri, 09 Dec 2011 15:15:48 -0200 Subject: [rspec-users] Strange time reporting In-Reply-To: <4EE241DD.5030800@yahoo.com.br> References: <4EE241DD.5030800@yahoo.com.br> Message-ID: <4EE24244.3020303@yahoo.com.br> Em 09-12-2011 15:14, Rodrigo Rosenfeld Rosas escreveu: > While running some specs of a new fresh Rails 3.1 project with latest > Rspec, I'm getting some strange time reporting (using --drb and spork): > > Finished in 731.67 seconds > 10 examples, 0 failures > > But it actually run "time rake" in less than 2s. "time rspec" runs in > about 0.2s. Yeah, but "time rspec" doesn't run any specs at all ;) "time rspec spec" finishes in about 0.4s. Sorry... From dchelimsky at gmail.com Fri Dec 9 12:43:37 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 9 Dec 2011 11:43:37 -0600 Subject: [rspec-users] Strange time reporting In-Reply-To: <4EE24244.3020303@yahoo.com.br> References: <4EE241DD.5030800@yahoo.com.br> <4EE24244.3020303@yahoo.com.br> Message-ID: On Dec 9, 2011, at 11:15 AM, Rodrigo Rosenfeld Rosas wrote: > Em 09-12-2011 15:14, Rodrigo Rosenfeld Rosas escreveu: >> While running some specs of a new fresh Rails 3.1 project with latest Rspec, I'm getting some strange time reporting (using --drb and spork): >> >> Finished in 731.67 seconds >> 10 examples, 0 failures >> >> But it actually run "time rake" in less than 2s. "time rspec" runs in about 0.2s. > > Yeah, but "time rspec" doesn't run any specs at all ;) "time rspec spec" finishes in about 0.4s. Sorry... "time rspec" actually does run specs as of 2.7 From lbocseg at yahoo.com.br Fri Dec 9 13:31:45 2011 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Fri, 09 Dec 2011 16:31:45 -0200 Subject: [rspec-users] Strange time reporting In-Reply-To: References: <4EE241DD.5030800@yahoo.com.br> <4EE24244.3020303@yahoo.com.br> Message-ID: <4EE25411.7040805@yahoo.com.br> Em 09-12-2011 15:43, David Chelimsky escreveu: > On Dec 9, 2011, at 11:15 AM, Rodrigo Rosenfeld Rosas wrote: > >> Em 09-12-2011 15:14, Rodrigo Rosenfeld Rosas escreveu: >>> While running some specs of a new fresh Rails 3.1 project with latest Rspec, I'm getting some strange time reporting (using --drb and spork): >>> >>> Finished in 731.67 seconds >>> 10 examples, 0 failures >>> >>> But it actually run "time rake" in less than 2s. "time rspec" runs in about 0.2s. >> Yeah, but "time rspec" doesn't run any specs at all ;) "time rspec spec" finishes in about 0.4s. Sorry... > "time rspec" actually does run specs as of 2.7 I'm using 2.7.1 here and the result of runnin rspec without specifying the spec folder is: No examples found. Finished in 5863.55 seconds 0 examples, 0 failures Ignore the strange time since this is some issue with Spork that I still don't know how to fix... From lbocseg at yahoo.com.br Fri Dec 9 13:43:41 2011 From: lbocseg at yahoo.com.br (Rodrigo Rosenfeld Rosas) Date: Fri, 09 Dec 2011 16:43:41 -0200 Subject: [rspec-users] Strange time reporting In-Reply-To: <4EE25411.7040805@yahoo.com.br> References: <4EE241DD.5030800@yahoo.com.br> <4EE24244.3020303@yahoo.com.br> <4EE25411.7040805@yahoo.com.br> Message-ID: <4EE256DD.4090307@yahoo.com.br> Em 09-12-2011 16:31, Rodrigo Rosenfeld Rosas escreveu: > Em 09-12-2011 15:43, David Chelimsky escreveu: >> On Dec 9, 2011, at 11:15 AM, Rodrigo Rosenfeld >> Rosas wrote: >> >>> Em 09-12-2011 15:14, Rodrigo Rosenfeld Rosas escreveu: >>>> While running some specs of a new fresh Rails 3.1 project with >>>> latest Rspec, I'm getting some strange time reporting (using --drb >>>> and spork): >>>> >>>> Finished in 731.67 seconds >>>> 10 examples, 0 failures >>>> >>>> But it actually run "time rake" in less than 2s. "time rspec" runs >>>> in about 0.2s. >>> Yeah, but "time rspec" doesn't run any specs at all ;) "time rspec >>> spec" finishes in about 0.4s. Sorry... >> "time rspec" actually does run specs as of 2.7 > > I'm using 2.7.1 here and the result of runnin rspec without specifying > the spec folder is: > > No examples found. > > > Finished in 5863.55 seconds > 0 examples, 0 failures > > Ignore the strange time since this is some issue with Spork that I > still don't know how to fix... Actually, it runs the specs unless --drb is specified in .rspec. From dchelimsky at gmail.com Fri Dec 9 14:22:47 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 9 Dec 2011 13:22:47 -0600 Subject: [rspec-users] Strange time reporting In-Reply-To: <4EE25411.7040805@yahoo.com.br> References: <4EE241DD.5030800@yahoo.com.br> <4EE24244.3020303@yahoo.com.br> <4EE25411.7040805@yahoo.com.br> Message-ID: On Fri, Dec 9, 2011 at 12:31 PM, Rodrigo Rosenfeld Rosas wrote: > Em 09-12-2011 15:43, David Chelimsky escreveu: > >> On Dec 9, 2011, at 11:15 AM, Rodrigo Rosenfeld Rosas >> ?wrote: >> >>> Em 09-12-2011 15:14, Rodrigo Rosenfeld Rosas escreveu: >>>> >>>> While running some specs of a new fresh Rails 3.1 project with latest >>>> Rspec, I'm getting some strange time reporting (using --drb and spork): >>>> >>>> Finished in 731.67 seconds >>>> 10 examples, 0 failures >>>> >>>> But it actually run "time rake" in less than 2s. "time rspec" runs in >>>> about 0.2s. >>> >>> Yeah, but "time rspec" doesn't run any specs at all ;) "time rspec spec" >>> finishes in about 0.4s. Sorry... >> >> "time rspec" actually does run specs as of 2.7 > > > I'm using 2.7.1 I mis-spoke - it's 2.8 (which is out as an rc: 2.8.0.rc1). > here and the result of runnin rspec without specifying the > spec folder is: > > No examples found. > > > Finished in 5863.55 seconds > 0 examples, 0 failures > > Ignore the strange time since this is some issue with Spork that I still > don't know how to fix... > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lille.penguini at gmail.com Sun Dec 11 17:02:06 2011 From: lille.penguini at gmail.com (Lille) Date: Sun, 11 Dec 2011 14:02:06 -0800 (PST) Subject: [rspec-users] how can shared examples be shared across gems? Message-ID: <91c10a3b-2338-43dc-8bc5-a46a6d71e80e@t38g2000yqe.googlegroups.com> Hi, I have shared examples in a gem... some_gem_name/spec/some_gem_name/shared_examples.rb ...where the shared examples are contained in a module, e.g., module SharedExamples shared_examples_for ... end How can I include these shared examples in tests in a different gem that depends on my some_gem_name, above? Maybe I can refer to the shared examples in my dependent gem's spec_helper? Thanks, Lille From anexiole at gmail.com Mon Dec 12 06:30:35 2011 From: anexiole at gmail.com (Gordon) Date: Mon, 12 Dec 2011 03:30:35 -0800 (PST) Subject: [rspec-users] recommendations for writing view index spec for a resource which behaves differently for different users Message-ID: <1914bc35-614b-4ae8-b3cd-2b511c18363a@r16g2000prr.googlegroups.com> hi guys, In my index view specs for a given resource, I have successfully written it for admin users. For the given resource, when admin users are looking at the index page, they should see -a link to add a new resource object -links to delete/edit/show for each resource object created My index view specs does this perfectly and it reads: ------- file: begin ----------------------- 192-168-1-4:categories anexiole$ cat index.html.erb_spec.rb require 'spec_helper' describe "categories/index.html.erb" do before(:each) do view.stub(:is_admin).and_return(true) assign( :categories, [ FactoryGirl.create(:category_intakes), FactoryGirl.create(:category_audio), ] ) end it "renders a list of categories" do render assert_select 'tr>td', :text => 'intakes and filters'.to_s, :count => 1 assert_select 'tr>td', :text => 'audio'.to_s, :count => 1 end it 'renders an interface with the new link' do render rendered.should contain ('New Category') end end ------- file: end ----------------------- Now, I would then like to put more specs in the index view spec. When a non-admin user (ie someone who has not logged in) looks at the index page, the user should NOT see -a link to add a new resource object -links to delete/edit/show for each resource object created 1) How can I best write this? 2) Would using ":let" before each different spec (admin and non-admin) be a good way to do it? thank you :) From dchelimsky at gmail.com Mon Dec 12 08:57:47 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 12 Dec 2011 07:57:47 -0600 Subject: [rspec-users] recommendations for writing view index spec for a resource which behaves differently for different users In-Reply-To: <1914bc35-614b-4ae8-b3cd-2b511c18363a@r16g2000prr.googlegroups.com> References: <1914bc35-614b-4ae8-b3cd-2b511c18363a@r16g2000prr.googlegroups.com> Message-ID: <7D313410-D4AD-491B-81FC-D09E71E4003A@gmail.com> On Dec 12, 2011, at 5:30 AM, Gordon wrote: > hi guys, > > In my index view specs for a given resource, I have successfully > written it for admin users. > > For the given resource, when admin users are looking at the index > page, they should see > -a link to add a new resource object > -links to delete/edit/show for each resource object created > > My index view specs does this perfectly and it reads: > > ------- file: begin ----------------------- > > > 192-168-1-4:categories anexiole$ cat index.html.erb_spec.rb > require 'spec_helper' > > describe "categories/index.html.erb" do > before(:each) do > view.stub(:is_admin).and_return(true) ^^ I've been in the habit of using view.stub(:is_admin => true). Also, the Ruby idiom for questions like "is this being viewed by an admin" is a Ruby predicate - a method name with a question mark at the end: view.stub(:admin? => true) Names like is_admin are usually holdovers from Java :) > assign( :categories, [ > FactoryGirl.create(:category_intakes), > FactoryGirl.create(:category_audio), > ] > ) > end > > it "renders a list of categories" do > render > assert_select 'tr>td', :text => 'intakes and filters'.to_s, :count => 1 > assert_select 'tr>td', :text => 'audio'.to_s, :count => 1 ^^ 'intakes and filters' and 'audio' are already strings, so you don't need .to_s. > end > > it 'renders an interface with the new link' do > render > rendered.should contain ('New Category') > end > > end > > ------- file: end ----------------------- > > Now, I would then like to put more specs in the index view spec. > > When a non-admin user (ie someone who has not logged in) looks at the > index page, the user > should NOT see > -a link to add a new resource object > -links to delete/edit/show for each resource object created > > 1) How can I best write this? Best is subjective. One way you can write it is: context "viewed by a non-admin" do before do view.stub(:admin? => false) # set up assigns end it "should not see xxx" do render assert_select selector, .. :count => 0 # or, if you're using Capybara rendered.should_not have_tag(selector) end end > 2) Would using ":let" before each different spec (admin and non-admin) > be a good way to do it? let() is for creating objects, which is not what you're doing here - you're simulating different logins. I'd stick with stubbing :admin? in the before declaration. Cheers, David From dchelimsky at gmail.com Mon Dec 12 09:06:06 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 12 Dec 2011 08:06:06 -0600 Subject: [rspec-users] how can shared examples be shared across gems? In-Reply-To: <91c10a3b-2338-43dc-8bc5-a46a6d71e80e@t38g2000yqe.googlegroups.com> References: <91c10a3b-2338-43dc-8bc5-a46a6d71e80e@t38g2000yqe.googlegroups.com> Message-ID: <83A62540-FF37-429A-993C-24B74921E6AD@gmail.com> On Dec 11, 2011, at 4:02 PM, Lille wrote: > Hi, > > I have shared examples in a gem... > > some_gem_name/spec/some_gem_name/shared_examples.rb > > ...where the shared examples are contained in a module, e.g., > > module SharedExamples > > shared_examples_for ... > > end How does this even work? shared_examples_for is not defined in Module, so unless you're leaving something important out, that should raise an error. > How can I include these shared examples in tests in a different gem > that depends on my some_gem_name, above? Maybe I can refer to the > shared examples in my dependent gem's spec_helper? There are two ways you can do this: shared_examples "stuff" do before { ... } let(:name) { value } it "does something" do # .. end end As long as this file is required somewhere (only once, please) you can use those examples in your gem or any other gem: describe Something do it_behaves_like "stuff" end You can also define a module: module SharedExamples extend RSpec::Core::SharedContext before { ... } let(:name) { value } it "does something" do # .. end end Now you can do a standard Ruby include describe Something do include SharedExamples end see https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples see http://rubydoc.info/github/rspec/rspec-core/master/RSpec/Core/SharedContext HTH, David From dchelimsky at gmail.com Tue Dec 13 07:16:04 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 13 Dec 2011 06:16:04 -0600 Subject: [rspec-users] RSpec TextMate bundle maintainer? Message-ID: <03226B9C-06E9-480C-9019-B3F9FF41C10A@gmail.com> Hi all, I'm looking for volunteers to help maintain the RSpec TextMate bundle. I stopped using TextMate as my main editor two years ago now,* so I don't have day to day experience with it, and I can barely keep up with maintaining the RSpec core libs as it is. We rarely get issues reported on it, so the bare minimum is not a big commitment. And if you have ideas about how to improve it, all the better. You can respond to the group, or email me directly if you're interested. Thanks! Cheers, David * I still use it for global search/replace. But that's it :) From dchelimsky at gmail.com Tue Dec 13 09:26:24 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 13 Dec 2011 08:26:24 -0600 Subject: [rspec-users] RSpec's RDoc Message-ID: <88FFC971-4085-4C00-8DBC-ACDEDD64CA4E@gmail.com> Hey all, I've been (finally) investing some time in RSpec's RDoc. It's gotten a lot better, but there is definitely more work to do. If you're interested in helping out, please peruse the docs for each lib and file github issues for any inaccurate, missing or confusing content. For those unfamiliar w/ http://rubydoc.info, it's broken up into two main sections: http://rubydoc.info/github and http://rubydoc.info/gems. The gems area is for published gems and the github area re-generates the docs from each push to github. Please review the in-progress docs in the github area: http://rubydoc.info/github/rspec/rspec-core/ http://rubydoc.info/github/rspec/rspec-expectations/ http://rubydoc.info/github/rspec/rspec-mocks/ http://rubydoc.info/github/rspec/rspec-rails/ In order to avoid confusion/overlap/etc, please don't worry about making pull requests for this for now. Just an issue in the appropriate tracker (i.e. issues with http://rubydoc.info/github/rspec/rspec-core/ should go to https://github.com/rspec/rspec-core/issues) would be a big help to get everything on the radar so I can prioritize and address. Thanks in advance for your help. Cheers, David From lille.penguini at gmail.com Tue Dec 13 19:30:56 2011 From: lille.penguini at gmail.com (Lille) Date: Tue, 13 Dec 2011 16:30:56 -0800 (PST) Subject: [rspec-users] how can shared examples be shared across gems? In-Reply-To: <83A62540-FF37-429A-993C-24B74921E6AD@gmail.com> References: <91c10a3b-2338-43dc-8bc5-a46a6d71e80e@t38g2000yqe.googlegroups.com> <83A62540-FF37-429A-993C-24B74921E6AD@gmail.com> Message-ID: <1b7239bc-3daf-4586-a6ab-b597b7854584@l24g2000yqm.googlegroups.com> Thank you. Here is what I did to conform my gem spec to the conventions suggested at https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples... my spec/spec_helper.rb... $LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) # Dir["spec/support/**/*.rb"].each {|f| require f} # this did not work... require 'rubygems' require 'rum_92265' require 'rspec' require 'rspec/autorun' require 'support/shared_examples' # this did now, at the top of in lib/rum_92265.rb... require "rum_92265/version" require File.dirname(__FILE__) + "/../spec/support/shared_examples.rb" finally, here are the top lines of the spec/support/ shared_sample.rb... extend RSpec::Core::SharedContext shared_examples_for "Rum92265::A3::PartB" do ... Anyway, I hadn't seen any gems with shared example groups exposed, so this was the best I could come up with -- it worked. It seems weird to require shared_samples.rb from the lib directory, but I couldn't see where else -- gemspec, for example? -- to require it. Lille On Dec 12, 9:06?am, David Chelimsky wrote: > On Dec 11, 2011, at 4:02 PM, Lille wrote: > > > Hi, > > > I have shared examples in a gem... > > > some_gem_name/spec/some_gem_name/shared_examples.rb > > > ...where the shared examples are contained in a module, e.g., > > > module SharedExamples > > > ? shared_examples_for ... > > > end > > How does this even work? shared_examples_for is not defined in Module, so unless you're leaving something important out, that should raise an error. > > > How can I include these shared examples in tests in a different gem > > that depends on my some_gem_name, above? Maybe I can refer to the > > shared examples in my dependent gem's spec_helper? > > There are two ways you can do this: > > shared_examples "stuff" do > ? before { ... } > ? let(:name) { value } > ? it "does something" do > ? ? # .. > ? end > end > > As long as this file is required somewhere (only once, please) you can use those examples in your gem or any other gem: > > describe Something do > ? it_behaves_like "stuff" > end > > You can also define a module: > > module SharedExamples > ? extend RSpec::Core::SharedContext > ? before { ... } > ? let(:name) { value } > ? it "does something" do > ? ? # .. > ? end > end > > Now you can do a standard Ruby include > > describe Something do > ? include SharedExamples > end > > seehttps://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared... > seehttp://rubydoc.info/github/rspec/rspec-core/master/RSpec/Core/SharedC... > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Tue Dec 13 19:39:57 2011 From: lists at ruby-forum.com (Jamie Orchard-hays) Date: Wed, 14 Dec 2011 01:39:57 +0100 Subject: [rspec-users] problem running tests of helpers In-Reply-To: References: Message-ID: <912d19d4e7a61d1fecc76cd8058c6387@ruby-forum.com> Did you ever find a work-around? My Helper Specs are broken in Ruby 1.9.2, Rails 2.3.14, but fine in Ruby 1.8.7. I get undefined method `response=' for nil:NilClass The nil class is @controller. Been pulling my hair out on this. I've been searching the 'net for this problem, but finding almost nothing. (Makes me wonder if people are testing their helper methods ;-) Jamie -- Posted via http://www.ruby-forum.com/. From phillip.koebbe at gmail.com Tue Dec 13 21:41:38 2011 From: phillip.koebbe at gmail.com (Phillip Koebbe) Date: Tue, 13 Dec 2011 20:41:38 -0600 Subject: [rspec-users] problem running tests of helpers In-Reply-To: <912d19d4e7a61d1fecc76cd8058c6387@ruby-forum.com> References: <912d19d4e7a61d1fecc76cd8058c6387@ruby-forum.com> Message-ID: On Dec 13, 2011, at 6:39 PM, Jamie Orchard-hays wrote: > Did you ever find a work-around? My Helper Specs are broken in Ruby > 1.9.2, Rails 2.3.14, but fine in Ruby 1.8.7. > > I get > > undefined method `response=' for nil:NilClass > > The nil class is @controller. > > Been pulling my hair out on this. I've been searching the 'net for this > problem, but finding almost nothing. (Makes me wonder if people are > testing their helper methods ;-) > > Jamie > Jamie, Many people interact with this list by way of email and it's much easier on them if you quote the message when responding. If you don't, we don't have the context and have no idea what you might be asking. I had to go to the web forum to see what it was you were inquiring about. I emailed Art directly a few months ago to ask if he found a solution, and this was his reply: On 2011-09-07 12:49 AM, Art Peel wrote: > Hi Phillip, > > Yes, I did. The problem turned out to be related to bundler. The easiest solution is to run "bundle exec spec" instead of just "spec". > > Another solution is to install the bundler binstubs as described at http://gembundler.com/ and then run "bin/spec" instead of just "spec" > > Hope this helps. > > -- Art This was what worked for Art, but it was unrelated to my experience with the problem (I wasn't using bundler at the time). Unfortunately, I don't recall how I resolved it. So this may work for you, and it may not. Peace. From dchelimsky at gmail.com Tue Dec 13 23:15:00 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 13 Dec 2011 22:15:00 -0600 Subject: [rspec-users] how can shared examples be shared across gems? In-Reply-To: <1b7239bc-3daf-4586-a6ab-b597b7854584@l24g2000yqm.googlegroups.com> References: <91c10a3b-2338-43dc-8bc5-a46a6d71e80e@t38g2000yqe.googlegroups.com> <83A62540-FF37-429A-993C-24B74921E6AD@gmail.com> <1b7239bc-3daf-4586-a6ab-b597b7854584@l24g2000yqm.googlegroups.com> Message-ID: On Dec 13, 2011, at 6:30 PM, Lille wrote: I moved your post to the bottom. Please read http://idallen.com/topposting.html and please bottom post or inline post so readers can more easily follow the thread. > On Dec 12, 9:06 am, David Chelimsky wrote: >> On Dec 11, 2011, at 4:02 PM, Lille wrote: >> >>> Hi, >> >>> I have shared examples in a gem... >> >>> some_gem_name/spec/some_gem_name/shared_examples.rb >> >>> ...where the shared examples are contained in a module, e.g., >> >>> module SharedExamples >> >>> shared_examples_for ... >> >>> end >> >> How does this even work? shared_examples_for is not defined in Module, so unless you're leaving something important out, that should raise an error. >> >>> How can I include these shared examples in tests in a different gem >>> that depends on my some_gem_name, above? Maybe I can refer to the >>> shared examples in my dependent gem's spec_helper? >> >> There are two ways you can do this: >> >> shared_examples "stuff" do >> before { ... } >> let(:name) { value } >> it "does something" do >> # .. >> end >> end >> >> As long as this file is required somewhere (only once, please) you can use those examples in your gem or any other gem: >> >> describe Something do >> it_behaves_like "stuff" >> end >> >> You can also define a module: >> >> module SharedExamples >> extend RSpec::Core::SharedContext >> before { ... } >> let(:name) { value } >> it "does something" do >> # .. >> end >> end >> >> Now you can do a standard Ruby include >> >> describe Something do >> include SharedExamples >> end >> >> seehttps://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared... >> seehttp://rubydoc.info/github/rspec/rspec-core/master/RSpec/Core/SharedC... >> >> HTH, >> David > Thank you. > > Here is what I did to conform my gem spec to the conventions suggested > at https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples... > > my spec/spec_helper.rb... > > $LOAD_PATH.unshift(File.dirname(__FILE__)) > $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) You don't need to modify the ^^ LOAD_PATH ^^ here - it's already done for you by RSpec. > # Dir["spec/support/**/*.rb"].each {|f| require f} # this did not work... I'm assuming you're using Ruby 1.9, which does not include "." on the LOAD_PATH (which is assumed by Dir["spec/support/**/*.rb"]). Either of these would work: Dir["./spec/support/**/*.rb"].each {|f| require f} Dir["support/**/*.rb"].each {|f| require f} I'll update the docs on relishapp.com accordingly. > require 'rubygems' > require 'rum_92265' > require 'rspec' > require 'rspec/autorun' > > require 'support/shared_examples' # this did > > now, at the top of in lib/rum_92265.rb... > > require "rum_92265/version" > require File.dirname(__FILE__) + "/../spec/support/shared_examples.rb" This ^^ is going to get you into trouble because Ruby doesn't see /path/to/x/../spec/support/shared_examples.rb and /path/to/spec/support/shared_examples.rb as the same path (even though they end at the same file). This means that your users will likely end up requiring shared_examples.rb twice, which makes bad things happen. I'd recommend modifying and relying on the LOAD_PATH instead. More below. > > finally, here are the top lines of the spec/support/ > shared_sample.rb... > > extend RSpec::Core::SharedContext > > shared_examples_for "Rum92265::A3::PartB" do You don't need both "extend RSpec::Core::SharedContext" and "shared_examples_for". Just one or the other. > Anyway, I hadn't seen any gems with shared example groups exposed, so > this was the best I could come up with -- it worked. It seems weird to > require shared_samples.rb from the lib directory, but I couldn't see > where else -- gemspec, for example? -- to require it. > > Lille If the idea here is to expose shared_examples to users of your gem, I'd actually store them under lib. Something like: lib/rum_92265/spec_support.rb # requires rum_92265/spec_support/shared_examples.rb lib/rum_92265/spec_support/shared_examples.rb Now you can require 'rum_92265/spec_support' in your own spec/spec_helper.rb, and you can tell your users to do the same. HTH, David From lists at ruby-forum.com Wed Dec 14 11:39:23 2011 From: lists at ruby-forum.com (Jamie Orchard-hays) Date: Wed, 14 Dec 2011 17:39:23 +0100 Subject: [rspec-users] problem running tests of helpers In-Reply-To: References: <912d19d4e7a61d1fecc76cd8058c6387@ruby-forum.com> Message-ID: <1ba6911315c3dd6c958760535959d9ae@ruby-forum.com> Hey Phillip, thanks for the information and sorry about not quoting. I'll have a go at this. Much appreciated, Jamie Phillip Koebbe wrote in post #1036638: > On Dec 13, 2011, at 6:39 PM, Jamie Orchard-hays wrote: > >> problem, but finding almost nothing. (Makes me wonder if people are >> testing their helper methods ;-) >> >> Jamie >> > > Jamie, > > Many people interact with this list by way of email and it's much easier > on them if you quote the message when responding. If you don't, we don't > have the context and have no idea what you might be asking. I had to go > to the web forum to see what it was you were inquiring about. > > I emailed Art directly a few months ago to ask if he found a solution, > and this was his reply: > > On 2011-09-07 12:49 AM, Art Peel wrote: >> Hi Phillip, >> >> Yes, I did. The problem turned out to be related to bundler. The easiest > solution is to run "bundle exec spec" instead of just "spec". >> >> Another solution is to install the bundler binstubs as described at > http://gembundler.com/ and then run "bin/spec" instead of just "spec" >> >> Hope this helps. >> >> -- Art > > This was what worked for Art, but it was unrelated to my experience with > the problem (I wasn't using bundler at the time). Unfortunately, I don't > recall how I resolved it. So this may work for you, and it may not. > > Peace. -- Posted via http://www.ruby-forum.com/. From transfire at gmail.com Wed Dec 14 11:51:42 2011 From: transfire at gmail.com (Trans) Date: Wed, 14 Dec 2011 11:51:42 -0500 Subject: [rspec-users] [ANN] rspec-ontap Message-ID: Hi-- I just released "RSpec On Tap". It is a TAP-Y/J formatter for RSpec that one can use with TapOut to produce a variety of test reports. TAP-Y/J provides a standard format which test frameworks can produce and test report formats can consume, thus allowing the same formats to work across multiple test frameworks. Learn more at: * rspec-ontap * tapout From lists at ruby-forum.com Wed Dec 14 13:19:55 2011 From: lists at ruby-forum.com (Jamie Orchard-hays) Date: Wed, 14 Dec 2011 19:19:55 +0100 Subject: [rspec-users] problem running tests of helpers In-Reply-To: References: <912d19d4e7a61d1fecc76cd8058c6387@ruby-forum.com> Message-ID: <093bbeddb6e18d07934c1830ef01d8b8@ruby-forum.com> I'm not using bundler either. If you happen to recall your solution, I'd love to read about it. Rather vexing, to say the least. > I emailed Art directly a few months ago to ask if he found a solution, > and this was his reply: > > On 2011-09-07 12:49 AM, Art Peel wrote: >> Hi Phillip, >> >> Yes, I did. The problem turned out to be related to bundler. The easiest > solution is to run "bundle exec spec" instead of just "spec". >> >> Another solution is to install the bundler binstubs as described at > http://gembundler.com/ and then run "bin/spec" instead of just "spec" >> >> Hope this helps. >> >> -- Art > > This was what worked for Art, but it was unrelated to my experience with > the problem (I wasn't using bundler at the time). Unfortunately, I don't > recall how I resolved it. So this may work for you, and it may not. > > Peace. -- Posted via http://www.ruby-forum.com/. From jrepenning at collab.net Wed Dec 14 14:13:29 2011 From: jrepenning at collab.net (Jack Repenning) Date: Wed, 14 Dec 2011 11:13:29 -0800 Subject: [rspec-users] Difference between "get '/path/'" and "get :symbol"? Message-ID: <03450774-9536-4C3D-BC0A-94BEF7ECBC19@collab.net> What's the difference between these two forms, in a spec file? get '/prefix/resources' # get index of resources get :index # get index of resources I have some tests that work one way, some that work the other way, and seems like none work any way but the way they're presently written. But I'm perilously close to having to try a form at random until I find which one works! A bit more specifically, In spec/controllers/some_resource_controller_spec.rb, I have > describe SomeResourcesController do > describe "some behavior" do > it "should return index of SomeResources" do > get :index (Using the path form here results in 'No route matches {:controller=>"some_resources", :action="/some_resources"}') But in spec/integration/some_others_resource_spec.rb, I have > describe "some other resource" do > describe "GET /some_others" > it "should return index of SomeOthers" do > get "/some_others" (Using the symbol form here results in 'bad argument(expected URI object or URI string)'.) Is it the difference between living in controllers/ vs. integration/ that determines the get form? Or the difference in whether I name the class in the outermost "describe"? Something else? Some combination? -==- Jack Repenning Technologist CollabNet Cloud Services CollabNet, Inc. 8000 Marina Boulevard, Suite 600 Brisbane, California 94005 office: +1 650.228.2562 twitter: http://twitter.com/jrep From dchelimsky at gmail.com Wed Dec 14 15:47:01 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 14 Dec 2011 14:47:01 -0600 Subject: [rspec-users] Difference between "get '/path/'" and "get :symbol"? In-Reply-To: <03450774-9536-4C3D-BC0A-94BEF7ECBC19@collab.net> References: <03450774-9536-4C3D-BC0A-94BEF7ECBC19@collab.net> Message-ID: On Wed, Dec 14, 2011 at 1:13 PM, Jack Repenning wrote: > What's the difference between these two forms, in a spec file? > > ?get '/prefix/resources' # get index of resources > ?get :index ? ? ? ? ? ? ?# get index of resources > > I have some tests that work one way, some that work the other way, and seems like none work any way but the way they're presently written. But I'm perilously close to having to try a form at random until I find which one works! > > A bit more specifically, > > In spec/controllers/some_resource_controller_spec.rb, I have >> describe SomeResourcesController do >> ? describe "some behavior" do >> ? ? it "should return index of SomeResources" do >> ? ? ? get :index > > (Using the path form here results in 'No route matches {:controller=>"some_resources", :action="/some_resources"}') > > But in spec/integration/some_others_resource_spec.rb, I have >> describe "some other resource" do >> ? describe "GET /some_others" >> ? ? it "should return index of SomeOthers" do >> ? ? ? get "/some_others" > > (Using the symbol form here results in 'bad argument(expected URI object or URI string)'.) > > Is it the difference between living in controllers/ vs. integration/ that determines the get form? Yes. Integration specs are built on top of Rails integration tests, which are not bound to any one controller, and therefore require the full path that you would use in the browser. Controller specs are built on top of Rails functional tests (which are now implemented in ActionController::TestCase, so they may as well be called controller tests), which are controller aware. I think the confusion is that we type "get" for both, but we're simulating an http get in integration specs, whereas we're doing something closer to directly invoking an action on a controller in controller specs. A new method for controller specs, like "invoke" might clear the air, but I think we're all so accustomed to using the "get/post/put/delete" abstractions (leaky though they are in this case), that most users would not support a change like that. Also, controller specs _do_ care about the http verb, even though the action is being invoked (almost) directly. This is probably not necessary to serve the purpose of a controller, but Rails has always blurred the lines between what is routing and what is controller, so trying to impose a cleaner separation between them would be hard to stomach for many Rails users. And so here we are! FWIW - I have the same problems managing RSpec. There are a lot of things I'd like to rip out, but doing so would be more disruptive than helpful, even though they might lead to a cleaner simpler model. HTH, David > Or the difference in whether I name the class in the outermost "describe"? Something else? Some combination? From lists at ruby-forum.com Thu Dec 15 10:37:37 2011 From: lists at ruby-forum.com (Jaime Bellmyer) Date: Thu, 15 Dec 2011 16:37:37 +0100 Subject: [rspec-users] Strange time reporting In-Reply-To: <4EE241DD.5030800@yahoo.com.br> References: <4EE241DD.5030800@yahoo.com.br> Message-ID: <40d56b1e04fba2aa7d3a81fd936d0565@ruby-forum.com> Just to add some helpful info to this post, I noticed the time given is the total time since spork was fired up. So fire up spork, wait 10 minutes, and your tests will say they took 10 minutes to run. I just thought I'd offer this in case it gets anyone closer to a solution. -- Posted via http://www.ruby-forum.com/. From lille.penguini at gmail.com Thu Dec 15 20:06:30 2011 From: lille.penguini at gmail.com (Lille) Date: Thu, 15 Dec 2011 17:06:30 -0800 (PST) Subject: [rspec-users] how can shared examples be shared across gems? In-Reply-To: References: <91c10a3b-2338-43dc-8bc5-a46a6d71e80e@t38g2000yqe.googlegroups.com> <83A62540-FF37-429A-993C-24B74921E6AD@gmail.com> <1b7239bc-3daf-4586-a6ab-b597b7854584@l24g2000yqm.googlegroups.com> Message-ID: <4d05a94c-ff1b-4db1-a721-80cd48118afa@v29g2000yqv.googlegroups.com> > > Here is what I did to conform my gem spec to the conventions suggested > > athttps://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared...... > > > my spec/spec_helper.rb... > > > $LOAD_PATH.unshift(File.dirname(__FILE__)) > > $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) > > You don't need to modify the ^^ LOAD_PATH ^^ here - it's already done for you by RSpec. OK - I made this change, thanks... > > finally, here are the top lines of the spec/support/ > > shared_sample.rb... > > > extend RSpec::Core::SharedContext > > > shared_examples_for "Rum92265::A3::PartB" do > > You don't need both "extend RSpec::Core::SharedContext" and "shared_examples_for". Just one or the other. ...and made this change... > If the idea here is to expose shared_examples to users of your gem, I'd actually store them under lib. Something like: > > lib/rum_92265/spec_support.rb # requires rum_92265/spec_support/shared_examples.rb > lib/rum_92265/spec_support/shared_examples.rb > > Now you can require 'rum_92265/spec_support' in your own spec/spec_helper.rb, and you can tell your users to do the same. ...finally, I did this, too. These steps added up to a successful result for me. Thank you very much for your detailed and helpful response. Lille From marko at renderedtext.com Mon Dec 19 08:36:45 2011 From: marko at renderedtext.com (Marko Anastasov) Date: Mon, 19 Dec 2011 14:36:45 +0100 Subject: [rspec-users] rake spec aborted, how to debug In-Reply-To: References: Message-ID: For the record, the issue was accidentally assigning a mock User to Time.zone in a controller spec. Rails and RSpec would go in an endless loop of calling and recording a message. On Thu, Nov 24, 2011 at 21:38, Marko Anastasov wrote: > Hello, > > I'm having an issue running specs on a Rails project. Here's how > bundle exec rake spec --trace ends at a random point after some > seconds of hanging with a high CPU usage: > https://gist.github.com/1392208 > > I say "a random point" because I can run the problematic spec alone > without problems, and if I delete its content and run the entire suite > again the error will happen during another spec's example. Given that > doesn't change, it always repeats on the same example though. > > My setup is Ubuntu 10.04 on a Mac VirtualBox, bundler 1.0.18. Other > people in my team have the same setup (but not entirely the same ruby > patch level version etc), and do not have this issue. I'd very much > appreciate any hint how to solve this. From antsmailinglist at gmail.com Mon Dec 19 12:00:25 2011 From: antsmailinglist at gmail.com (Ants Pants) Date: Mon, 19 Dec 2011 18:00:25 +0100 Subject: [rspec-users] Problem with RSpec, Rails or Me? (I know the answer is me!!) Message-ID: This could just be my lack of knowledge of how Rails works but from the following code in my RSpec test .... $stderr.puts "BEFORE: #{@invitation.meeting.event.event_type.event_type_time_units.inspect}" @invitation.save! EventTypeTimeUnit.all.each {|rec| $stderr.puts rec.inspect } $stderr.puts "AFTER REC INSPECT #{@invitation.meeting.event.event_type.inspect}" $stderr.puts "AFTER LIST INSPECT #{@invitation.meeting.event.event_type.event_type_time_units.inspect}" ................ I get the following output. The thing that is not right, is that there is no data for the association event_type_time_units. The data is in the DB, the ids, foreign keys are correct but I just can't get the data from the association. BEFORE: [#, #, #] # # # AFTER REC INSPECT # AFTER LIST INSPECT [] Can someone please put me out of my ignorant misery, please. Thank you. -ants -------------- next part -------------- An HTML attachment was scrubbed... URL: From patmaddox at me.com Mon Dec 19 14:45:36 2011 From: patmaddox at me.com (Pat Maddox) Date: Mon, 19 Dec 2011 13:45:36 -0600 Subject: [rspec-users] Problem with RSpec, Rails or Me? (I know the answer is me!!) In-Reply-To: References: Message-ID: <12556EFE-8593-4CD0-B95A-B6370560F54C@me.com> On Dec 19, 2011, at 11:00 AM, Ants Pants wrote: > This could just be my lack of knowledge of how Rails works but from the following code in my RSpec test .... > > $stderr.puts "BEFORE: #{@invitation.meeting.event.event_type.event_type_time_units.inspect}" Can you please share your RSpec code that doesn't do what you expect it to? Pat From antsmailinglist at gmail.com Mon Dec 19 15:32:19 2011 From: antsmailinglist at gmail.com (Ants Pants) Date: Mon, 19 Dec 2011 21:32:19 +0100 Subject: [rspec-users] Problem with RSpec, Rails or Me? (I know the answer is me!!) In-Reply-To: <12556EFE-8593-4CD0-B95A-B6370560F54C@me.com> References: <12556EFE-8593-4CD0-B95A-B6370560F54C@me.com> Message-ID: On 19 December 2011 20:45, Pat Maddox wrote: > On Dec 19, 2011, at 11:00 AM, Ants Pants wrote: > > > This could just be my lack of knowledge of how Rails works but from the > following code in my RSpec test .... > > > > $stderr.puts "BEFORE: > #{@invitation.meeting.event.event_type.event_type_time_units.inspect}" > > Can you please share your RSpec code that doesn't do what you expect it to? > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I've added the necessary code. I've shown that before the save! the event_type.event_type_time_units association returns data (from a Factory build). After the save!, EventTypeTimeUnit.all shows that the data is in the DB and all keys look okay, I've then whacked in two puts; the first showing that event_type returns the correct id; and the second puts returns an empty list. This is simply in an it block with nothing special going on. The code is in the order as it's in the block. Nothing going on in between. It's not an RSpec problem (I don't think) It's just running in that environment. Thanks for taking an interest but to be honest, dont waste any time on it, I'll sort it out. But to me, it's a strange one!! -ants -------------- next part -------------- An HTML attachment was scrubbed... URL: From antsmailinglist at gmail.com Tue Dec 20 05:07:05 2011 From: antsmailinglist at gmail.com (Ants Pants) Date: Tue, 20 Dec 2011 11:07:05 +0100 Subject: [rspec-users] Problem with RSpec, Rails or Me? (I know the answer is me!!) In-Reply-To: References: <12556EFE-8593-4CD0-B95A-B6370560F54C@me.com> Message-ID: On 19 December 2011 21:32, Ants Pants wrote: > > > On 19 December 2011 20:45, Pat Maddox wrote: > >> On Dec 19, 2011, at 11:00 AM, Ants Pants wrote: >> >> > This could just be my lack of knowledge of how Rails works but from the >> following code in my RSpec test .... >> > >> > $stderr.puts "BEFORE: >> #{@invitation.meeting.event.event_type.event_type_time_units.inspect}" >> >> Can you please share your RSpec code that doesn't do what you expect it >> to? >> >> Pat >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > I've added the necessary code. I've shown that before the save! the > event_type.event_type_time_units association returns data (from a Factory > build). After the save!, EventTypeTimeUnit.all shows that the data is in > the DB and all keys look okay, I've then whacked in two puts; the first > showing that event_type returns the correct id; and the second puts returns > an empty list. > > This is simply in an it block with nothing special going on. The code is > in the order as it's in the block. Nothing going on in between. > > It's not an RSpec problem (I don't think) It's just running in that > environment. > > Thanks for taking an interest but to be honest, dont waste any time on it, > I'll sort it out. But to me, it's a strange one!! > > -ants > > > In the end, I just used #reload to reload the attributes from the DB and it works. Should I have to do this, I don't know, but my test is now passing. -ants -------------- next part -------------- An HTML attachment was scrubbed... URL: From jarl at softace.dk Tue Dec 20 05:51:54 2011 From: jarl at softace.dk (Jarl Friis) Date: Tue, 20 Dec 2011 11:51:54 +0100 Subject: [rspec-users] Matcher for testing file content. Message-ID: Hi. Is there any matcher for test file content, anything like file("/path/to/file.txt").should contain("File content") or file("/path/to/file.txt").content.should == "File content" or file_content("/path/to/file.txt").should == "File content" or something else? Jarl From mguterl at gmail.com Tue Dec 20 07:40:39 2011 From: mguterl at gmail.com (Michael Guterl) Date: Tue, 20 Dec 2011 07:40:39 -0500 Subject: [rspec-users] Matcher for testing file content. In-Reply-To: References: Message-ID: On Tue, Dec 20, 2011 at 5:51 AM, Jarl Friis wrote: > Hi. > > Is there any matcher for test file content, anything like > > file("/path/to/file.txt").should contain("File content") > or > file("/path/to/file.txt").content.should == "File content" > or > file_content("/path/to/file.txt").should == "File content" > > or something else? > File.read("/path/to/file") will give you a string of the entire contents of the file. File.read("/path/to/file").should match "content" File.read("/path/to/file").should include "content" etc. Does that help? Best, Michael Guterl From jarl at softace.dk Tue Dec 20 08:43:11 2011 From: jarl at softace.dk (Jarl Friis) Date: Tue, 20 Dec 2011 14:43:11 +0100 Subject: [rspec-users] Matcher for testing file content. In-Reply-To: References: Message-ID: Yes, that certainly did the trick... I use File.read("/path/to/file").should == "content" Thanks. 2011/12/20 Michael Guterl : > On Tue, Dec 20, 2011 at 5:51 AM, Jarl Friis wrote: >> Hi. >> >> Is there any matcher for test file content, anything like >> >> file("/path/to/file.txt").should contain("File content") >> or >> file("/path/to/file.txt").content.should == "File content" >> or >> file_content("/path/to/file.txt").should == "File content" >> >> or something else? >> > File.read("/path/to/file") will give you a string of the entire > contents of the file. > > File.read("/path/to/file").should match "content" > File.read("/path/to/file").should include "content" > > etc. > > Does that help? > > Best, > Michael Guterl > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- Jarl Friis Softace ApS R?dhustorvet 7, 2. 3520 Farum LinkedIn: http://dk.linkedin.com/in/jarlfriis From bradleyrobertson at gmail.com Wed Dec 7 11:03:03 2011 From: bradleyrobertson at gmail.com (Bradley) Date: Wed, 7 Dec 2011 08:03:03 -0800 (PST) Subject: [rspec-users] Excluding tags with a Rake task in Rails with rspec-rails 2.7 Message-ID: <20360136.555.1323273783712.JavaMail.geo-discussion-forums@yqq16> I'm trying to get a new spec task defined that is 'fast': that is, it skips all :type => :integration tests and any tests that have :slow => true set. We're using spec/integration instead of spec/requests, but I thought I read somewhere that they're equivalent, ie that they would both be automagically tagged with :type => :integration and :type => :request. (I personally find 'integration' far more intuitive than 'request' so that's what we've chosen to use.) First question: Is this true? Does rspec automagically tag my spec/requests and spec/integration with the proper type. If so, is this only true when using `rake`, or is it the same with using `rspec` Next: I've written a task like so: desc "Run all but slow (including integration) specs" RSpec::Core::RakeTask.new(:fast => 'db:test:prepare') do |t| t.rspec_opts = '--tag ~slow --tag ~type:request --tag ~type:integration' end Oddly enough, when the tests run, they say Run filtered excluding {:slow=>true, :type=>"integration"} So second question: Is it not possible to filter out multiple tags of a type (ie --tag ~type:request --tag ~type:integration) Next, it appears that when I use :type => :integration, nothing gets filtered, but when I use :type => :request it does. So third question: What make :request so special such that :integration does not work the same way. Any help on these matters is greatly appreciated! Brad -------------- next part -------------- An HTML attachment was scrubbed... URL: From astjohn at gmail.com Mon Dec 12 12:16:54 2011 From: astjohn at gmail.com (astjohn) Date: Mon, 12 Dec 2011 09:16:54 -0800 (PST) Subject: [rspec-users] render_template on create and update action - unexpected result with namespaced controllers Message-ID: <65faf8fb-df22-495c-97cb-3efaba40c011@l19g2000yqc.googlegroups.com> All, I've been having issues with my namespaced controllers and specs. I receive the following errors only on my create and update actions (with invalid parameters) and only on my namespaced controllers. My non-namespaced controllers have similar specs and work well. The application works as expected, but the specs are reporting: Failures: 1) Management::CountriesController POST create with invalid params re-renders the 'new' template Failure/Error: response.should render_template(:new) expecting <"new"> but rendering with <""> # ./spec/controllers/management/countries_controller_spec.rb: 169:in `block (4 levels) in ' 2) Management::CountriesController PUT update with invalid params re- renders the 'edit' template Failure/Error: response.should render_template(:edit) expecting <"edit"> but rendering with <""> # ./spec/controllers/management/countries_controller_spec.rb: 240:in `block (4 levels) in ' Here's a gist to help my explanation: https://gist.github.com/1468233 I'm using the Devise/CanCan combo. Any help is greatly appreciated. I've been ignoring these for a while and it's time to fix them. Cheers, Adam From bill.christian at gmail.com Tue Dec 13 22:32:51 2011 From: bill.christian at gmail.com (Bill Christian) Date: Tue, 13 Dec 2011 19:32:51 -0800 (PST) Subject: [rspec-users] Advice on using Rspec as a data validation engine Message-ID: <11845012.229.1323833571679.JavaMail.geo-discussion-forums@yqba2> I have a project that collects various application configurations across a couple thousand servers and wants to validate settings are following recommended values. For example, all weblogic servers should have a minimum memory heap size of 512M. Any violators should be reported. Being very impressed with the RSpec DSL, I am using RSpec to validate these data rules. I pre-populate an object with all configurations for a given server and use RSpec expectations to ensure they match the recommended values. My current runner loads each instance and runs RSpec. Of course this is not truly performing unit testing, but it appears to be an easy way to expressively define data rules and run expectations. I've gotten it to work. However, this is my first time at instrumenting RSpec outside of rake and creating my own custom formatter. I am curious if I am mangling the use of RSpec and/or complete missing a better way of scripting RSpec to perform data validation rules. I would really appreciate any feedback on how I am using RSpec, or the runner code I put together, or suggestions on looking at other projects automating RSpec executions for inspiration. Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From transfire at gmail.com Wed Dec 14 02:34:59 2011 From: transfire at gmail.com (TR NS) Date: Tue, 13 Dec 2011 23:34:59 -0800 (PST) Subject: [rspec-users] Custom Formatter Namespace Message-ID: <18134474.14.1323848099575.JavaMail.geo-discussion-forums@yqiq4> Is there a proper naming scheme for custom formatters? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From lgensert at gmail.com Fri Dec 16 05:59:36 2011 From: lgensert at gmail.com (leifg) Date: Fri, 16 Dec 2011 02:59:36 -0800 (PST) Subject: [rspec-users] custom error handling Message-ID: <95be3829-19e3-468d-83ec-006ad802d081@4g2000yqu.googlegroups.com> Hello everyone, I'm currently using rspec2 wit capybara to do some selenium tests. I want to put this on a CI server and run the tests regularly. capybara already has a functionality to save a screenshot. I'd like to save a screenshot whenever a test does not pass. So my question is: How do i customize the default error handling of rspec to do some custom actions, before the test actually fails (getting an id or the string of the name would also be very cool). From leequarella at gmail.com Fri Dec 16 10:46:04 2011 From: leequarella at gmail.com (LeeQ) Date: Fri, 16 Dec 2011 07:46:04 -0800 (PST) Subject: [rspec-users] Sending rails errors to rspec output Message-ID: <8250f341-fc6f-4ffa-9ddc-1228764ad622@j10g2000vbe.googlegroups.com> I am using Capybara in combination with rspec for integration testing of rails apps. I would like any errors (routing errors, errors in a controller, anything) generated during a test to be printed the same as "puts" statements in rspec's output. Is this possible? Additionally, is this a reasonable idea, or am I just being silly? From dchelimsky at gmail.com Thu Dec 22 00:22:01 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 21 Dec 2011 23:22:01 -0600 Subject: [rspec-users] Excluding tags with a Rake task in Rails with rspec-rails 2.7 In-Reply-To: <20360136.555.1323273783712.JavaMail.geo-discussion-forums@yqq16> References: <20360136.555.1323273783712.JavaMail.geo-discussion-forums@yqq16> Message-ID: <1AD464C6-7672-4C2B-8EA2-A4056FED9894@gmail.com> On Dec 7, 2011, at 10:03 AM, Bradley wrote: > I'm trying to get a new spec task defined that is 'fast': that is, it skips all :type => :integration tests and any tests that have :slow => true set. > > We're using spec/integration instead of spec/requests, but I thought I read somewhere that they're equivalent, ie that they would both be automagically tagged with :type => :integration and :type => :request. (I personally find 'integration' far more intuitive than 'request' so that's what we've chosen to use.) See https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example.rb#L29-31 Specs in spec/request or spec/integration get assigned :type => :request. We added support for implicit treatment of files in spec/integration the same as spec/request, but assigning both types is problematic. > First question: Is this true? Does rspec automagically tag my spec/requests and spec/integration with the proper type. If so, is this only true when using `rake`, or is it the same with using `rspec` > > Next: I've written a task like so: > > desc "Run all but slow (including integration) specs" > RSpec::Core::RakeTask.new(:fast => 'db:test:prepare') do |t| > t.rspec_opts = '--tag ~slow --tag ~type:request --tag ~type:integration' > end Keep the specs in spec/integration if you like, but get rid of ~type:integration (~type:request covers you). > > Oddly enough, when the tests run, they say > > Run filtered excluding {:slow=>true, :type=>"integration"} > > So second question: Is it not possible to filter out multiple tags of a type (ie --tag ~type:request --tag ~type:integration) No. You can only attach one value to each key. I'm open to enhancing that in the future, but that's how it works now. > Next, it appears that when I use :type => :integration, nothing gets filtered, but when I use :type => :request it does. Right - :type => :integration doesn't mean anything to rspec. :type => :request does. > So third question: What make :request so special such that :integration does not work the same way. Integration doesn't mean anything precise. There is an unfortunate convention in the Rails community, that it means something closer to end-to-end than functional, but this is backwards from definitions that existed prior to rails: integration meant two or more non-trivial components (meaning that Rails unit tests are integration tests) and function tests meant functionality as a user sees it. The word "request" came out of the Merb project, and it made perfect sense to me when I saw it, so I incorporated it into rspec-rails-2. I still think it's a more precise word than integration, but as time passes I think "scenario" might be even better, since it really lives in the same space as a Cucumber feature. > Any help on these matters is greatly appreciated! HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Thu Dec 22 02:32:31 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 22 Dec 2011 00:32:31 -0700 Subject: [rspec-users] Sending rails errors to rspec output In-Reply-To: <8250f341-fc6f-4ffa-9ddc-1228764ad622@j10g2000vbe.googlegroups.com> References: <8250f341-fc6f-4ffa-9ddc-1228764ad622@j10g2000vbe.googlegroups.com> Message-ID: <1ECE3EAD-758F-4C56-8D3B-DAF4AF3E207A@gmail.com> On Dec 16, 2011, at 8:46 AM, LeeQ wrote: > I am using Capybara in combination with rspec for integration testing > of rails apps. Even though you are using Capybara, they are still just specs. No reason why "puts" won't work. > > I would like any errors (routing errors, errors in a controller, > anything) generated during a test to be printed the same as "puts" > statements in rspec's output. Is this possible? Additionally, is this > a reasonable idea, or am I just being silly? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jko170 at gmail.com Thu Dec 22 02:50:06 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 22 Dec 2011 00:50:06 -0700 Subject: [rspec-users] render_template on create and update action - unexpected result with namespaced controllers In-Reply-To: <65faf8fb-df22-495c-97cb-3efaba40c011@l19g2000yqc.googlegroups.com> References: <65faf8fb-df22-495c-97cb-3efaba40c011@l19g2000yqc.googlegroups.com> Message-ID: On Dec 12, 2011, at 10:16 AM, astjohn wrote: > All, > > I've been having issues with my namespaced controllers and specs. I > receive the following errors only on my create and update actions > (with invalid parameters) and only on my namespaced controllers. My > non-namespaced controllers have similar specs and work well. The > application works as expected, but the specs are reporting: > > > Failures: > > 1) Management::CountriesController POST create with invalid params > re-renders the 'new' template > Failure/Error: response.should render_template(:new) > expecting <"new"> but rendering with <""> > # ./spec/controllers/management/countries_controller_spec.rb: > 169:in `block (4 levels) in ' > > 2) Management::CountriesController PUT update with invalid params re- > renders the 'edit' template > Failure/Error: response.should render_template(:edit) > expecting <"edit"> but rendering with <""> > # ./spec/controllers/management/countries_controller_spec.rb: > 240:in `block (4 levels) in ' > > > > Here's a gist to help my explanation: > https://gist.github.com/1468233 > > I'm using the Devise/CanCan combo. > > Any help is greatly appreciated. I've been ignoring these for a while > and it's time to fix them. > > Cheers, > Adam > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users An empty response body tells me it's redirecting. Couple ways to check that: 1.) Use "puts" and "raise" to see if it even gets to the `respond_with` 2.) Look at the test logs to see what it's responding with. 3.) Use `response.response_code.should eq(200)` From leequarella at gmail.com Thu Dec 22 10:25:30 2011 From: leequarella at gmail.com (LeeQ) Date: Thu, 22 Dec 2011 07:25:30 -0800 (PST) Subject: [rspec-users] Sending rails errors to rspec output In-Reply-To: <1ECE3EAD-758F-4C56-8D3B-DAF4AF3E207A@gmail.com> References: <8250f341-fc6f-4ffa-9ddc-1228764ad622@j10g2000vbe.googlegroups.com> <1ECE3EAD-758F-4C56-8D3B-DAF4AF3E207A@gmail.com> Message-ID: <20211648.546.1324567530980.JavaMail.geo-discussion-forums@vbxw7> Puts does work. That's not what I'm looking for. I want all error messages (like `undefined local variable or method `junk' for...` ) to show up in my rspec out put in *the same way as* `puts`. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Thu Dec 22 13:22:40 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 22 Dec 2011 11:22:40 -0700 Subject: [rspec-users] Sending rails errors to rspec output In-Reply-To: <20211648.546.1324567530980.JavaMail.geo-discussion-forums@vbxw7> References: <8250f341-fc6f-4ffa-9ddc-1228764ad622@j10g2000vbe.googlegroups.com> <1ECE3EAD-758F-4C56-8D3B-DAF4AF3E207A@gmail.com> <20211648.546.1324567530980.JavaMail.geo-discussion-forums@vbxw7> Message-ID: <49AE29BA-9C18-4109-B73C-FCD0A28AA4C8@gmail.com> On Dec 22, 2011, at 8:25 AM, LeeQ wrote: > Puts does work. That's not what I'm looking for. > > I want all error messages (like `undefined local variable or method `junk' for...` ) to show up in my rspec out put in the same way as `puts`. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users So basically you want the exception message to display in the output, but then have things "continue on" like it *wasn't* an exception? I don't see the point in that, but you could do it with `rescue`. -------------- next part -------------- An HTML attachment was scrubbed... URL: From leequarella at gmail.com Thu Dec 22 13:33:38 2011 From: leequarella at gmail.com (LeeQ) Date: Thu, 22 Dec 2011 10:33:38 -0800 (PST) Subject: [rspec-users] Sending rails errors to rspec output In-Reply-To: <49AE29BA-9C18-4109-B73C-FCD0A28AA4C8@gmail.com> References: <8250f341-fc6f-4ffa-9ddc-1228764ad622@j10g2000vbe.googlegroups.com> <1ECE3EAD-758F-4C56-8D3B-DAF4AF3E207A@gmail.com> <20211648.546.1324567530980.JavaMail.geo-discussion-forums@vbxw7> <49AE29BA-9C18-4109-B73C-FCD0A28AA4C8@gmail.com> Message-ID: <20028771.713.1324578818837.JavaMail.geo-discussion-forums@vbbdf9> Ah, I see what you are saying. But no, I still want the exception to act like an exception. My problem is that I'll have a test fail for reasons unknown, and I then I need to open the test logs to find the exception. I'd like those exceptions to show up in my test output so I don't have to dig for them. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jko170 at gmail.com Thu Dec 22 14:40:58 2011 From: jko170 at gmail.com (Justin Ko) Date: Thu, 22 Dec 2011 12:40:58 -0700 Subject: [rspec-users] Sending rails errors to rspec output In-Reply-To: <20028771.713.1324578818837.JavaMail.geo-discussion-forums@vbbdf9> References: <8250f341-fc6f-4ffa-9ddc-1228764ad622@j10g2000vbe.googlegroups.com> <1ECE3EAD-758F-4C56-8D3B-DAF4AF3E207A@gmail.com> <20211648.546.1324567530980.JavaMail.geo-discussion-forums@vbxw7> <49AE29BA-9C18-4109-B73C-FCD0A28AA4C8@gmail.com> <20028771.713.1324578818837.JavaMail.geo-discussion-forums@vbbdf9> Message-ID: On Dec 22, 2011, at 11:33 AM, LeeQ wrote: > Ah, I see what you are saying. But no, I still want the exception to act like an exception. My problem is that I'll have a test fail for reasons unknown, and I then I need to open the test logs to find the exception. I'd like those exceptions to show up in my test output so I don't have to dig for them._______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Okay I see what you're talking about now. Take a look at this: https://github.com/jnicklas/capybara/issues/358 From patmaddox at me.com Thu Dec 22 14:54:14 2011 From: patmaddox at me.com (Pat Maddox) Date: Thu, 22 Dec 2011 13:54:14 -0600 Subject: [rspec-users] Advice on using Rspec as a data validation engine In-Reply-To: <11845012.229.1323833571679.JavaMail.geo-discussion-forums@yqba2> References: <11845012.229.1323833571679.JavaMail.geo-discussion-forums@yqba2> Message-ID: <639A8209-17EA-4585-AE94-C57E4916C740@me.com> On Dec 13, 2011, at 9:32 PM, Bill Christian wrote: > I have a project that collects various application configurations across a couple thousand servers and wants to validate settings are following recommended values. For example, all weblogic servers should have a minimum memory heap size of 512M. Any violators should be reported. > > Being very impressed with the RSpec DSL, I am using RSpec to validate these data rules. I pre-populate an object with all configurations for a given server and use RSpec expectations to ensure they match the recommended values. My current runner loads each instance and runs RSpec. > > Of course this is not truly performing unit testing, but it appears to be an easy way to expressively define data rules and run expectations. I've gotten it to work. However, this is my first time at instrumenting RSpec outside of rake and creating my own custom formatter. I am curious if I am mangling the use of RSpec and/or complete missing a better way of scripting RSpec to perform data validation rules. > > I would really appreciate any feedback on how I am using RSpec, or the runner code I put together, or suggestions on looking at other projects automating RSpec executions for inspiration. > > Thanks in advance. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users I can't comment on the specifics of your configuration but I think this is a fine use of RSpec. I love using RSpec for stuff like this. Unit tests aren't the only things in the world that need automated checks :) Pat -------------- next part -------------- An HTML attachment was scrubbed... URL: From patmaddox at me.com Thu Dec 22 15:00:07 2011 From: patmaddox at me.com (Pat Maddox) Date: Thu, 22 Dec 2011 14:00:07 -0600 Subject: [rspec-users] Sending rails errors to rspec output In-Reply-To: <20028771.713.1324578818837.JavaMail.geo-discussion-forums@vbbdf9> References: <8250f341-fc6f-4ffa-9ddc-1228764ad622@j10g2000vbe.googlegroups.com> <1ECE3EAD-758F-4C56-8D3B-DAF4AF3E207A@gmail.com> <20211648.546.1324567530980.JavaMail.geo-discussion-forums@vbxw7> <49AE29BA-9C18-4109-B73C-FCD0A28AA4C8@gmail.com> <20028771.713.1324578818837.JavaMail.geo-discussion-forums@vbbdf9> Message-ID: On Dec 22, 2011, at 12:33 PM, LeeQ wrote: > Ah, I see what you are saying. But no, I still want the exception to act like an exception. My problem is that I'll have a test fail for reasons unknown, and I then I need to open the test logs to find the exception. I'd like those exceptions to show up in my test output so I don't have to dig for them. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users You need to configure the logger to log to standard out. Check out this link & modify as appropriate for your Rails version: http://stackoverflow.com/questions/4800032/how-to-change-the-rails-logger-to-use-standard-out-from-rake-tasks-rails2 Pat From lists at ruby-forum.com Fri Dec 23 09:24:01 2011 From: lists at ruby-forum.com (Rodrigo Emygdio) Date: Fri, 23 Dec 2011 15:24:01 +0100 Subject: [rspec-users] Problem with stub Message-ID: <0706ab0099b0c6a2a3ea141a4d30363c@ruby-forum.com> Respecting the Dry principle, I posted the link of my question as follow: http://stackoverflow.com/questions/8616186/problems-with-stubs If anybody know about this issue, please, give me some help -- Posted via http://www.ruby-forum.com/. From antsmailinglist at gmail.com Mon Dec 26 11:06:01 2011 From: antsmailinglist at gmail.com (Ants Pants) Date: Mon, 26 Dec 2011 17:06:01 +0100 Subject: [rspec-users] First Model Macro Message-ID: Hello all, I trust you are having a good one. I'm just trying out macros and my first one is taken from the RSpec book which replaces ..... @obj.should_not be_valid @obj.should have(1).error_on(:attr) with the macro.... should_require_attribute Model, :attribute My first attempt is basic but already I have problems. The following is called as it_should_require_attribute Model, :attribute but I would rather call if as it_should_require_attribute @model, :attribute. I prefer this call as I want to use what has been setup in my before(:each) block -- setting @model and all other housekeeping stuff required for the tests -- and I can then remove dut_instance = dut.new from the macro. Alas, my before(:each) block is not being called!! I thought it would be called when the it in the macro is met. module ModelMacros ## dut - Domain Under Test ## aut - Attribute Under Test def it_should_require_attribute(dut, aut) it "is not valid with missing #{aut}" do dut_instance = dut.new dut_instance.send("#{aut}=", nil) dut_instance.should_not be_valid dut_instance.should have(1).error_on(aut.to_sym) end end end Could anyone give me some tips on how to approach macros better for seamless integration into my tests. Thank you -ants -------------- next part -------------- An HTML attachment was scrubbed... URL: From phillip.koebbe at gmail.com Mon Dec 26 12:01:31 2011 From: phillip.koebbe at gmail.com (Phillip Koebbe) Date: Mon, 26 Dec 2011 11:01:31 -0600 Subject: [rspec-users] First Model Macro In-Reply-To: References: Message-ID: <9375EAD1-88C0-4143-9C05-7F0A40A35B4F@gmail.com> On Dec 26, 2011, at 10:06 AM, Ants Pants wrote: > Hello all, > > I trust you are having a good one. > > I'm just trying out macros and my first one is taken from the RSpec book which replaces ..... > > @obj.should_not be_valid > @obj.should have(1).error_on(:attr) > > with the macro.... > > should_require_attribute Model, :attribute > > My first attempt is basic but already I have problems. > > The following is called as > > it_should_require_attribute Model, :attribute > > but I would rather call if as > > it_should_require_attribute @model, :attribute. > > I prefer this call as I want to use what has been setup in my before(:each) block -- setting @model and all other housekeeping stuff required for the tests -- and I can then remove dut_instance = dut.new from the macro. > > Alas, my before(:each) block is not being called!! I thought it would be called when the it in the macro is met. > > module ModelMacros > ## dut - Domain Under Test > ## aut - Attribute Under Test > > def it_should_require_attribute(dut, aut) > it "is not valid with missing #{aut}" do > dut_instance = dut.new > dut_instance.send("#{aut}=", nil) > dut_instance.should_not be_valid > dut_instance.should have(1).error_on(aut.to_sym) > end > end > end > > Could anyone give me some tips on how to approach macros better for seamless integration into my tests. > I like to use self.described_class instead of passing classes or instances in. Here is an example: def it_should_require_attribute(attribute) klass = self.described_class instance = klass.new instance.send("#{attribute}=", nil) instance.should_not be_valid instance.should have(1).error_on(attribute.to_sym) end describe MyModel do it_should_require_attribute :some_attribute end I'm still using RSpec 1.x on Rails 2.3.x projects and have no idea if this is supported in RSpec 2.x. Peace. From antsmailinglist at gmail.com Mon Dec 26 13:09:01 2011 From: antsmailinglist at gmail.com (Ants Pants) Date: Mon, 26 Dec 2011 19:09:01 +0100 Subject: [rspec-users] First Model Macro In-Reply-To: <9375EAD1-88C0-4143-9C05-7F0A40A35B4F@gmail.com> References: <9375EAD1-88C0-4143-9C05-7F0A40A35B4F@gmail.com> Message-ID: On 26 December 2011 18:01, Phillip Koebbe wrote: > > On Dec 26, 2011, at 10:06 AM, Ants Pants wrote: > > > Hello all, > > > > I trust you are having a good one. > > > > I'm just trying out macros and my first one is taken from the RSpec book > which replaces ..... > > > > @obj.should_not be_valid > > @obj.should have(1).error_on(:attr) > > > > with the macro.... > > > > should_require_attribute Model, :attribute > > > > My first attempt is basic but already I have problems. > > > > The following is called as > > > > it_should_require_attribute Model, :attribute > > > > but I would rather call if as > > > > it_should_require_attribute @model, :attribute. > > > > I prefer this call as I want to use what has been setup in my > before(:each) block -- setting @model and all other housekeeping stuff > required for the tests -- and I can then remove dut_instance = dut.new from > the macro. > > > > Alas, my before(:each) block is not being called!! I thought it would be > called when the it in the macro is met. > > > > module ModelMacros > > ## dut - Domain Under Test > > ## aut - Attribute Under Test > > > > def it_should_require_attribute(dut, aut) > > it "is not valid with missing #{aut}" do > > dut_instance = dut.new > > dut_instance.send("#{aut}=", nil) > > dut_instance.should_not be_valid > > dut_instance.should have(1).error_on(aut.to_sym) > > end > > end > > end > > > > Could anyone give me some tips on how to approach macros better for > seamless integration into my tests. > > > > I like to use self.described_class instead of passing classes or instances > in. Here is an example: > > def it_should_require_attribute(attribute) > klass = self.described_class > instance = klass.new > instance.send("#{attribute}=", nil) > instance.should_not be_valid > instance.should have(1).error_on(attribute.to_sym) > end > > describe MyModel do > it_should_require_attribute :some_attribute > end > > I'm still using RSpec 1.x on Rails 2.3.x projects and have no idea if this > is supported in RSpec 2.x. > > Peace. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Thanks for your reply. Firstly, I was mistaken, my before block is being called when the it block is met in my macro. I'm using rspec-rails 1.3.4 and Rails 2.3.11 Your code doesn't really help, though. It's just another way of addressing what I'm already doing. As I now know my before block is begin called and I have access to an instance variable, I tried a generic name @dut (Domain Under Test) and that works. But, I have now lost a meaningful instance variable name for non macro tests. Maybe I could just #dup them. Is there a better way? I reckon there is and will find it while playing. -ants -------------- next part -------------- An HTML attachment was scrubbed... URL: From phillip.koebbe at gmail.com Mon Dec 26 16:09:16 2011 From: phillip.koebbe at gmail.com (Phillip Koebbe) Date: Mon, 26 Dec 2011 15:09:16 -0600 Subject: [rspec-users] First Model Macro In-Reply-To: References: <9375EAD1-88C0-4143-9C05-7F0A40A35B4F@gmail.com> Message-ID: On Dec 26, 2011, at 12:09 PM, Ants Pants wrote: > > > On 26 December 2011 18:01, Phillip Koebbe wrote: > > On Dec 26, 2011, at 10:06 AM, Ants Pants wrote: > > > Hello all, > > > > I trust you are having a good one. > > > > I'm just trying out macros and my first one is taken from the RSpec book which replaces ..... > > > > @obj.should_not be_valid > > @obj.should have(1).error_on(:attr) > > > > with the macro.... > > > > should_require_attribute Model, :attribute > > > > My first attempt is basic but already I have problems. > > > > The following is called as > > > > it_should_require_attribute Model, :attribute > > > > but I would rather call if as > > > > it_should_require_attribute @model, :attribute. > > > > I prefer this call as I want to use what has been setup in my before(:each) block -- setting @model and all other housekeeping stuff required for the tests -- and I can then remove dut_instance = dut.new from the macro. > > > > Alas, my before(:each) block is not being called!! I thought it would be called when the it in the macro is met. > > > > module ModelMacros > > ## dut - Domain Under Test > > ## aut - Attribute Under Test > > > > def it_should_require_attribute(dut, aut) > > it "is not valid with missing #{aut}" do > > dut_instance = dut.new > > dut_instance.send("#{aut}=", nil) > > dut_instance.should_not be_valid > > dut_instance.should have(1).error_on(aut.to_sym) > > end > > end > > end > > > > Could anyone give me some tips on how to approach macros better for seamless integration into my tests. > > > > I like to use self.described_class instead of passing classes or instances in. Here is an example: > > def it_should_require_attribute(attribute) > klass = self.described_class > instance = klass.new > instance.send("#{attribute}=", nil) > instance.should_not be_valid > instance.should have(1).error_on(attribute.to_sym) > end > > describe MyModel do > it_should_require_attribute :some_attribute > end > > I'm still using RSpec 1.x on Rails 2.3.x projects and have no idea if this is supported in RSpec 2.x. > > Peace. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > Thanks for your reply. > > Firstly, I was mistaken, my before block is being called when the it block is met in my macro. > > I'm using rspec-rails 1.3.4 and Rails 2.3.11 > > Your code doesn't really help, though. It's just another way of addressing what I'm already doing. As I now know my before block is begin called and I have access to an instance variable, I tried a generic name @dut (Domain Under Test) and that works. But, I have now lost a meaningful instance variable name for non macro tests. Maybe I could just #dup them. > Sorry, I should have been more specific. I wasn't addressing the issue you were having with the before block. I was addressing this: > Could anyone give me some tips on how to approach macros better for seamless integration into my tests. Which I understood to mean that if anyone had any ideas about how to make the tests simpler/dryer/etc, you'd be happy to hear them. Sorry if I misunderstood and you didn't find it useful. Peace. -------------- next part -------------- An HTML attachment was scrubbed... URL: From antsmailinglist at gmail.com Tue Dec 27 05:53:27 2011 From: antsmailinglist at gmail.com (Ants Pants) Date: Tue, 27 Dec 2011 11:53:27 +0100 Subject: [rspec-users] First Model Macro In-Reply-To: References: <9375EAD1-88C0-4143-9C05-7F0A40A35B4F@gmail.com> Message-ID: On 26 December 2011 22:09, Phillip Koebbe wrote: > > On Dec 26, 2011, at 12:09 PM, Ants Pants wrote: > > > > On 26 December 2011 18:01, Phillip Koebbe wrote: > >> >> On Dec 26, 2011, at 10:06 AM, Ants Pants wrote: >> >> > Hello all, >> > >> > I trust you are having a good one. >> > >> > I'm just trying out macros and my first one is taken from the RSpec >> book which replaces ..... >> > >> > @obj.should_not be_valid >> > @obj.should have(1).error_on(:attr) >> > >> > with the macro.... >> > >> > should_require_attribute Model, :attribute >> > >> > My first attempt is basic but already I have problems. >> > >> > The following is called as >> > >> > it_should_require_attribute Model, :attribute >> > >> > but I would rather call if as >> > >> > it_should_require_attribute @model, :attribute. >> > >> > I prefer this call as I want to use what has been setup in my >> before(:each) block -- setting @model and all other housekeeping stuff >> required for the tests -- and I can then remove dut_instance = dut.new from >> the macro. >> > >> > Alas, my before(:each) block is not being called!! I thought it would >> be called when the it in the macro is met. >> > >> > module ModelMacros >> > ## dut - Domain Under Test >> > ## aut - Attribute Under Test >> > >> > def it_should_require_attribute(dut, aut) >> > it "is not valid with missing #{aut}" do >> > dut_instance = dut.new >> > dut_instance.send("#{aut}=", nil) >> > dut_instance.should_not be_valid >> > dut_instance.should have(1).error_on(aut.to_sym) >> > end >> > end >> > end >> > >> > Could anyone give me some tips on how to approach macros better for >> seamless integration into my tests. >> > >> >> I like to use self.described_class instead of passing classes or >> instances in. Here is an example: >> >> def it_should_require_attribute(attribute) >> klass = self.described_class >> instance = klass.new >> instance.send("#{attribute}=", nil) >> instance.should_not be_valid >> instance.should have(1).error_on(attribute.to_sym) >> end >> >> describe MyModel do >> it_should_require_attribute :some_attribute >> end >> >> I'm still using RSpec 1.x on Rails 2.3.x projects and have no idea if >> this is supported in RSpec 2.x. >> >> Peace. >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > Thanks for your reply. > > Firstly, I was mistaken, my before block is being called when the it block > is met in my macro. > > I'm using rspec-rails 1.3.4 and Rails 2.3.11 > > Your code doesn't really help, though. It's just another way of addressing > what I'm already doing. As I now know my before block is begin called and I > have access to an instance variable, I tried a generic name @dut (Domain > Under Test) and that works. But, I have now lost a meaningful instance > variable name for non macro tests. Maybe I could just #dup them. > > > Sorry, I should have been more specific. I wasn't addressing the issue you > were having with the before block. I was addressing this: > > Could anyone give me some tips on how to approach macros better for > seamless integration into my tests. > > > Which I understood to mean that if anyone had any ideas about how to make > the tests simpler/dryer/etc, you'd be happy to hear them. Sorry if I > misunderstood and you didn't find it useful. > > Peace. > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I always find replies useful and I thanked you for it. I didn't know about described_class, for example, so I learned something there. My request for having my macros more seamless was to do with them using the current environment they were running in (before blocks etc.) I have solved that by not being so dupid. I think too much good food over Christmas has made me even softer. -ants -------------- next part -------------- An HTML attachment was scrubbed... URL: From jaipratik29 at gmail.com Fri Dec 23 01:08:08 2011 From: jaipratik29 at gmail.com (JP) Date: Thu, 22 Dec 2011 22:08:08 -0800 (PST) Subject: [rspec-users] /gems/ZenTest-4.6.2/lib/autotest.rb:315:in `load': /Users/jayparteek/.autotest:7: invalid multibyte char (US-ASCII) (SyntaxError) Message-ID: <30bbce3a-eaa5-4004-9c48-a7ac1b27abbe@q7g2000prl.googlegroups.com> I am using latest version for rspec-rails, ZenTest. I am getting following error, when ever I try to run autotest. Please help -head at mhart6/gems/ZenTest-4.6.2/lib/autotest.rb:315:in `load': /Users/ jayparteek/.autotest:7: invalid multibyte char (US-ASCII) (SyntaxError) From dchelimsky at gmail.com Tue Dec 27 07:28:27 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 27 Dec 2011 06:28:27 -0600 Subject: [rspec-users] /gems/ZenTest-4.6.2/lib/autotest.rb:315:in `load': /Users/jayparteek/.autotest:7: invalid multibyte char (US-ASCII) (SyntaxError) In-Reply-To: <30bbce3a-eaa5-4004-9c48-a7ac1b27abbe@q7g2000prl.googlegroups.com> References: <30bbce3a-eaa5-4004-9c48-a7ac1b27abbe@q7g2000prl.googlegroups.com> Message-ID: On Dec 23, 2011, at 12:08 AM, JP wrote: > I am using latest version for rspec-rails, ZenTest. I am getting > following error, when ever I try to run autotest. > > Please help > > > -head at mhart6/gems/ZenTest-4.6.2/lib/autotest.rb:315:in `load': /Users/ > jayparteek/.autotest:7: invalid multibyte char (US-ASCII) > (SyntaxError) What's on line 7 of ~/.autotest ? From niku at niku.name Thu Dec 29 19:06:08 2011 From: niku at niku.name (niku -E:)) Date: Thu, 29 Dec 2011 16:06:08 -0800 (PST) Subject: [rspec-users] rspec can't be finish when cause StopIteration Message-ID: <7959272.1522.1325203568679.JavaMail.geo-discussion-forums@prfc16> When I execute following spec file, rspec can't be finish(can't display shell prompt). How do I check StopIteration? I'm using /Users/niku% ruby -v ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0] /Users/niku% rspec -v 2.7.1 describe do subject { [1,2].to_enum } it do # expect { 2.times{ subject.next } }. # failure, but it can be finish expect { 3.times{ subject.next } }. to raise_error(StopIteration) end end -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Dec 30 16:43:43 2011 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 30 Dec 2011 15:43:43 -0600 Subject: [rspec-users] rspec can't be finish when cause StopIteration In-Reply-To: <7959272.1522.1325203568679.JavaMail.geo-discussion-forums@prfc16> References: <7959272.1522.1325203568679.JavaMail.geo-discussion-forums@prfc16> Message-ID: <9ED04752-A113-4BC4-95D6-8BDAE78E9D27@gmail.com> On Dec 29, 2011, at 6:06 PM, niku -E:) wrote: > When I execute following spec file, rspec can't be finish(can't display shell prompt). > How do I check StopIteration? > > I'm using > /Users/niku% ruby -v > ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0] > /Users/niku% rspec -v > 2.7.1 > > describe do > subject { [1,2].to_enum } > it do > # expect { 2.times{ subject.next } }. # failure, but it can be finish > expect { 3.times{ subject.next } }. > to raise_error(StopIteration) > end > end I can't reproduce this. Having copied your example as/is, I get the following: ============================= $ ruby -v ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0] [david: tmp]$ gem list rspec *** LOCAL GEMS *** rspec (2.7.0) rspec-core (2.7.1) rspec-expectations (2.7.0) rspec-mocks (2.7.0) [david: tmp]$ rspec example_spec.rb . Finished in 0.13401 seconds 1 example, 0 failures [david: tmp]$ ============================= Anybody else? From niku at niku.name Fri Dec 30 19:58:20 2011 From: niku at niku.name (niku -E:)) Date: Fri, 30 Dec 2011 16:58:20 -0800 (PST) Subject: [rspec-users] rspec can't be finish when cause StopIteration In-Reply-To: <9ED04752-A113-4BC4-95D6-8BDAE78E9D27@gmail.com> References: <7959272.1522.1325203568679.JavaMail.geo-discussion-forums@prfc16> <9ED04752-A113-4BC4-95D6-8BDAE78E9D27@gmail.com> Message-ID: <26317848.72.1325293100044.JavaMail.geo-discussion-forums@preg25> Thank you David I took commands. It seems to me similar environment. But different results. Regards ==== /Users/niku% ruby -v ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0] /Users/niku% gem list rspec *** LOCAL GEMS *** rspec (2.7.0) rspec-core (2.7.1) rspec-expectations (2.7.0) rspec-mocks (2.7.0) /Users/niku% cat stop_iteration_spec.rb describe do subject { [1,2].to_enum } it do # expect { 2.times{ subject.next } }. # failure, but it can be finish expect { 3.times{ subject.next } }. to raise_error(StopIteration) end end /Users/niku% rspec stop_iteration_spec.rb should raise StopIteration Finished in 0.13396 seconds 1 example, 0 failures ^C Exiting... Interrupt again to exit immediately. /Users/niku% ==== -------------- next part -------------- An HTML attachment was scrubbed... URL: