From pafahim at gmail.com Thu Aug 2 05:14:26 2012 From: pafahim at gmail.com (Fahim Patel) Date: Thu, 2 Aug 2012 10:44:26 +0530 Subject: [rspec-users] hiiiiiii...........lots of question .. Message-ID: i implement all this question but i dont have knowledge perfectly .......ok........ explain with example code............ tell me what is mock and stub ? stub_model and mock_model ? mock and mock_model? what to use first rspec or cucumber?? which is best rspec or cucumber?? how to write spec in controller,view and model?? i m new born baby and i started crying ........stop my crying .. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ken.chien at gmail.com Thu Aug 2 13:58:42 2012 From: ken.chien at gmail.com (Ken Chien) Date: Thu, 2 Aug 2012 09:58:42 -0400 Subject: [rspec-users] hiiiiiii...........lots of question .. In-Reply-To: References: Message-ID: Hi Fahim, Have you looked at the documentation here [https://www.relishapp.com/rspec/] ? There are lots of great examples. Regards, Ken On Thu, Aug 2, 2012 at 1:14 AM, Fahim Patel wrote: > i implement all this question but i dont have knowledge perfectly > .......ok........ > > explain with example code............ > tell me what is mock and stub ? > stub_model and mock_model ? > mock and mock_model? > > > what to use first rspec or cucumber?? > which is best rspec or cucumber?? > > > how to write spec in controller,view and model?? > > > i m new born baby and i started crying ........stop my crying .. > > > > _______________________________________________ > 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 curtis at ram9.cc Thu Aug 2 15:02:46 2012 From: curtis at ram9.cc (Curtis Schofield) Date: Thu, 2 Aug 2012 08:02:46 -0700 Subject: [rspec-users] hiiiiiii...........lots of question .. In-Reply-To: References: Message-ID: Hi Fahim These are from wiki Mock http://en.m.wikipedia.org/wiki/Mock_object Stub http://en.m.wikipedia.org/wiki/Test_stub I think of stub as a change to an existing object to isolate specific paths that a method may take. If you are testing a method - it can help to stub out the responses that another method may respond with. A mock is an object that is being used by another object under test that will pretend to be a particular instance with particular responses - a mock object has stubbed methods. I think this is in general - I can get confused about stub and mock . -- Curtis J Schofield BlazingCloud.net "Creativity can solve anything" - George Lois (source: art & copy) On Aug 1, 2012, at 10:14 PM, Fahim Patel wrote: > i implement all this question but i dont have knowledge perfectly .......ok........ > > explain with example code............ > tell me what is mock and stub ? > stub_model and mock_model ? > mock and mock_model? > > > what to use first rspec or cucumber?? > which is best rspec or cucumber?? > > > how to write spec in controller,view and model?? > > > i m new born baby and i started crying ........stop my crying .. > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From patrick at collinatorstudios.com Thu Aug 2 20:24:43 2012 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Thu, 2 Aug 2012 13:24:43 -0700 (PDT) Subject: [rspec-users] "config.before(:each)" is not run after "let!" ? Message-ID: I have a model with an observer that emails out upon creation, and I want to do some testing of emails that get generated via various actions... So I was hoping I could do: # spec_helper.rb config.before(:each) do ActionMailer::base.deliveries.clear end # my_phat_observer_spec.rb let!(:yo_momma) { create_yo_momma } describe "after_update" do it "sends an email when it knows your daddy" do expect { yo_momma.update_attribute(:daddy => create_daddy) }.to change(ActionMailer::Base, :deliveries).by(1) end end ... However, inside that example group, ActionMailer::Base.deliveries is populated from the create_yo_momma method-- before the expectation is even declared. Is there a way to make a config.before(:each) that actually runs as the *LAST* before callback prior to the actual example group? Thank you. Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Thu Aug 2 21:05:48 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Aug 2012 17:05:48 -0400 Subject: [rspec-users] "config.before(:each)" is not run after "let!" ? In-Reply-To: References: Message-ID: On Thu, Aug 2, 2012 at 4:24 PM, Patrick J. Collins wrote: > I have a model with an observer that emails out upon creation, and I > want to do some testing of emails that get generated via various > actions... So I was hoping I could do: > > # spec_helper.rb > > config.before(:each) do > ActionMailer::base.deliveries.clear > end > > # my_phat_observer_spec.rb > > let!(:yo_momma) { create_yo_momma } > > describe "after_update" do > it "sends an email when it knows your daddy" do > expect { yo_momma.update_attribute(:daddy => create_daddy) }.to > change(ActionMailer::Base, :deliveries).by(1) > end > end > > ... > > > However, inside that example group, ActionMailer::Base.deliveries is populated from the create_yo_momma > method-- before the expectation is even declared. > > Is there a way to make a config.before(:each) that actually runs as the > *LAST* before callback prior to the actual example group? let! adds a before hook and before hooks get run in the order they're declared, so just declare them in the other order: let!(:yo_momma) { create_yo_momma } config.before(:each) do ActionMailer::base.deliveries.clear end HTH, David From patrick at collinatorstudios.com Thu Aug 2 22:29:19 2012 From: patrick at collinatorstudios.com (Patrick J. Collins) Date: Thu, 2 Aug 2012 15:29:19 -0700 (PDT) Subject: [rspec-users] "config.before(:each)" is not run after "let!" ? In-Reply-To: References: Message-ID: > let! adds a before hook and before hooks get run in the order they're > declared, so just declare them in the other order: > > let!(:yo_momma) { create_yo_momma } > config.before(:each) do > ActionMailer::base.deliveries.clear > end Hmm.. The way that I usually work is that my "lets" are specific to a spec... # some_spec.rb let!(:xyz) { "XYZ" } # some_other_spec.rb let!(:foo) { "foobar!" } ... So, my goal is to not have to clutter my actual spec files with things like ActionMailer::Base.deliveries.clear ... That's something that I want to always assure is blank at the beginning of an example regardless of the what spec file I am running. I was hoping there was some way to change the order of hook execution, and make the stuff in spec_helper happen last... Patrick J. Collins http://collinatorstudios.com From dchelimsky at gmail.com Thu Aug 2 22:33:15 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Aug 2012 18:33:15 -0400 Subject: [rspec-users] "config.before(:each)" is not run after "let!" ? In-Reply-To: References: Message-ID: On Thu, Aug 2, 2012 at 6:29 PM, Patrick J. Collins wrote: >> let! adds a before hook and before hooks get run in the order they're >> declared, so just declare them in the other order: >> >> let!(:yo_momma) { create_yo_momma } >> config.before(:each) do >> ActionMailer::base.deliveries.clear >> end > > Hmm.. The way that I usually work is that my "lets" are specific to a > spec... > > # some_spec.rb > > let!(:xyz) { "XYZ" } > > # some_other_spec.rb > > let!(:foo) { "foobar!" } > > ... > > So, my goal is to not have to clutter my actual spec files with things > like ActionMailer::Base.deliveries.clear ... That's something that I > want to always assure is blank at the beginning of an example regardless > of the what spec file I am running. > > I was hoping there was some way to change the order of hook execution, > and make the stuff in spec_helper happen last... Nope. Global befores will always run before the ones declared locally. From isignin at gmail.com Fri Aug 3 13:33:07 2012 From: isignin at gmail.com (Steve Loo) Date: Fri, 3 Aug 2012 09:33:07 -0400 Subject: [rspec-users] Mock_model not recognizing act_as_mappable Message-ID: I am using mock_model in my tests, and I encountered a situation where my stub is failing. Here's the scenario: Controller: @locations = Location.al(:bounds=>bounds)l @locations.sort_by_distance_from([bounds.center.lat,bounds.center.lng]) Rspec: @location = mock_model(Location) Location.stub(:all).and_return([@location]) @location.stub!(:sort_by_distance_from).and_return([@location]) Within real model: Location act_as_mappable .... the :sort_by_distance_from is a method from within act_as_mappable. Upon investigation, when I compare the available methods for both the Location model and the mock_model, I found act_as_mappable is missing from the mock_model. Which accounts for why it was failing in the stub @location.stub!(:sort_by_distance_from). It gives an error "unexpected message :distance_to" and the :distance_to method comes from act_as_mappable. When I switch to using Factory for the @location instance, the test passed. How should I go about using the mock_model for a situation as this, without resorting to using Factory? I believe this issue also the same for other act_as_ situations because I also noted that a number of my act_as.. are not available in the mock_model as they are in the actual model. Thanks for the help Steve -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Aug 3 14:28:36 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Aug 2012 10:28:36 -0400 Subject: [rspec-users] Mock_model not recognizing act_as_mappable In-Reply-To: References: Message-ID: On Fri, Aug 3, 2012 at 9:33 AM, Steve Loo wrote: > I am using mock_model in my tests, and I encountered a situation where my > stub is failing. You want stub_model for this case because you're counting on functionality that is built into your real model. See https://www.relishapp.com/rspec/rspec-rails/docs/mocks/mock-model and https://www.relishapp.com/rspec/rspec-rails/docs/mocks/stub-model for more info. > Here's the scenario: > > Controller: > > @locations = Location.al(:bounds=>bounds)l > > @locations.sort_by_distance_from([bounds.center.lat,bounds.center.lng]) > > > Rspec: > > @location = mock_model(Location) > > Location.stub(:all).and_return([@location]) > > @location.stub!(:sort_by_distance_from).and_return([@location]) > > > Within real model: Location > > act_as_mappable > > .... > > > the :sort_by_distance_from is a method from within act_as_mappable. > > Upon investigation, when I compare the available methods for both the > Location model and the mock_model, I found act_as_mappable is missing from > the mock_model. > > Which accounts for why it was failing in the stub > @location.stub!(:sort_by_distance_from). It gives an error "unexpected > message :distance_to" and the :distance_to method comes from > act_as_mappable. > > > When I switch to using Factory for the @location instance, the test passed. > > How should I go about using the mock_model for a situation as this, without > resorting to using Factory? I believe this issue also the same for other > act_as_ situations because I also noted that a number of my act_as.. are not > available in the mock_model as they are in the actual model. > > > Thanks for the help > > Steve > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From abonec at gmail.com Sat Aug 4 17:46:03 2012 From: abonec at gmail.com (Alexander Baronec) Date: Sat, 4 Aug 2012 21:46:03 +0400 Subject: [rspec-users] should_receive with block or proc? Message-ID: Hello. How can I test object to receive message and compare arguments of this message with value evaluated at present time? It is possible? For example: should_receive(:api_send).with( -> { players.count } ) And players.count will be called and evaluated only when api_send is received. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sun Aug 5 07:28:56 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 5 Aug 2012 03:28:56 -0400 Subject: [rspec-users] should_receive with block or proc? In-Reply-To: References: Message-ID: On Sat, Aug 4, 2012 at 1:46 PM, Alexander Baronec wrote: > Hello. > How can I test object to receive message and compare arguments of this > message with value evaluated at present time? It is possible? > > For example: > > should_receive(:api_send).with( -> { players.count } ) And players.count > will be called and evaluated only when api_send is received. Look at Fake Implementation on https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/method-stubs. You can do the same thing w/ should_receive, e.g. foo.should_receive(:api_send) do |player_count| player_count.should eq players.count end HTH, David From abonec at gmail.com Mon Aug 6 07:48:45 2012 From: abonec at gmail.com (Alexander Baronec) Date: Mon, 6 Aug 2012 11:48:45 +0400 Subject: [rspec-users] should_receive with block or proc? In-Reply-To: References: Message-ID: It don't work when object received few messages. I described it there: http://stackoverflow.com/questions/11669979/should-recieve-alongside-other-messages 2012/8/5 David Chelimsky > On Sat, Aug 4, 2012 at 1:46 PM, Alexander Baronec > wrote: > > Hello. > > How can I test object to receive message and compare arguments of this > > message with value evaluated at present time? It is possible? > > > > For example: > > > > should_receive(:api_send).with( -> { players.count } ) And players.count > > will be called and evaluated only when api_send is received. > > Look at Fake Implementation on > https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/method-stubs. > You can do the same thing w/ should_receive, e.g. > > foo.should_receive(:api_send) do |player_count| > player_count.should eq players.count > end > > 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 Mon Aug 6 10:42:51 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Aug 2012 06:42:51 -0400 Subject: [rspec-users] should_receive with block or proc? In-Reply-To: References: Message-ID: On Mon, Aug 6, 2012 at 3:48 AM, Alexander Baronec wrote: > 2012/8/5 David Chelimsky >> >> On Sat, Aug 4, 2012 at 1:46 PM, Alexander Baronec >> wrote: >> > Hello. >> > How can I test object to receive message and compare arguments of this >> > message with value evaluated at present time? It is possible? >> > >> > For example: >> > >> > should_receive(:api_send).with( -> { players.count } ) And players.count >> > will be called and evaluated only when api_send is received. >> >> Look at Fake Implementation on >> https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/method-stubs. >> You can do the same thing w/ should_receive, e.g. >> >> foo.should_receive(:api_send) do |player_count| >> player_count.should eq players.count >> end >> >> HTH, >> David > It don't work when object received few messages. I described it there: > http://stackoverflow.com/questions/11669979/should-recieve-alongside-other-messages should_receive, by default, expects exactly one call, but there are a number of ways for you to specify more than one call. One possibility would be: foo.should_receive(:api_send).ordered foo.should_receive(:api_send).with(2).ordered See http://rubydoc.info/gems/rspec-mocks for more info From abonec at gmail.com Mon Aug 6 13:21:38 2012 From: abonec at gmail.com (Alexander Baronec) Date: Mon, 6 Aug 2012 17:21:38 +0400 Subject: [rspec-users] should_receive with block or proc? In-Reply-To: References: Message-ID: I wan't to test order of received messages. I want to test only one message of few and compare it with real-time value. It's not possible? 2012/8/6 David Chelimsky > On Mon, Aug 6, 2012 at 3:48 AM, Alexander Baronec > wrote: > > 2012/8/5 David Chelimsky > >> > >> On Sat, Aug 4, 2012 at 1:46 PM, Alexander Baronec > >> wrote: > >> > Hello. > >> > How can I test object to receive message and compare arguments of this > >> > message with value evaluated at present time? It is possible? > >> > > >> > For example: > >> > > >> > should_receive(:api_send).with( -> { players.count } ) And > players.count > >> > will be called and evaluated only when api_send is received. > >> > >> Look at Fake Implementation on > >> https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/method-stubs. > >> You can do the same thing w/ should_receive, e.g. > >> > >> foo.should_receive(:api_send) do |player_count| > >> player_count.should eq players.count > >> end > >> > >> HTH, > >> David > > > It don't work when object received few messages. I described it there: > > > http://stackoverflow.com/questions/11669979/should-recieve-alongside-other-messages > > should_receive, by default, expects exactly one call, but there are a > number of ways for you to specify more than one call. One possibility > would be: > > foo.should_receive(:api_send).ordered > foo.should_receive(:api_send).with(2).ordered > > See http://rubydoc.info/gems/rspec-mocks for more info > _______________________________________________ > 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 Aug 6 13:47:06 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Aug 2012 09:47:06 -0400 Subject: [rspec-users] should_receive with block or proc? In-Reply-To: References: Message-ID: On Mon, Aug 6, 2012 at 9:21 AM, Alexander Baronec wrote: > 2012/8/6 David Chelimsky >> >> On Mon, Aug 6, 2012 at 3:48 AM, Alexander Baronec >> wrote: >> > 2012/8/5 David Chelimsky >> >> >> >> On Sat, Aug 4, 2012 at 1:46 PM, Alexander Baronec >> >> wrote: >> >> > Hello. >> >> > How can I test object to receive message and compare arguments of >> >> > this >> >> > message with value evaluated at present time? It is possible? >> >> > >> >> > For example: >> >> > >> >> > should_receive(:api_send).with( -> { players.count } ) And >> >> > players.count >> >> > will be called and evaluated only when api_send is received. >> >> >> >> Look at Fake Implementation on >> >> https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/method-stubs. >> >> You can do the same thing w/ should_receive, e.g. >> >> >> >> foo.should_receive(:api_send) do |player_count| >> >> player_count.should eq players.count >> >> end >> >> >> >> HTH, >> >> David >> >> > It don't work when object received few messages. I described it there: >> > >> > http://stackoverflow.com/questions/11669979/should-recieve-alongside-other-messages >> >> should_receive, by default, expects exactly one call, but there are a >> number of ways for you to specify more than one call. One possibility >> would be: >> >> foo.should_receive(:api_send).ordered >> foo.should_receive(:api_send).with(2).ordered >> >> See http://rubydoc.info/gems/rspec-mocks for more info > I wan't to test order of received messages. I want to test only one message > of few and compare it with real-time value. > It's not possible? It is, but you have to specify which time it should care if you're going to compare it to a real time value. From matt at mattwynne.net Tue Aug 7 15:51:50 2012 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 7 Aug 2012 16:51:50 +0100 Subject: [rspec-users] hiiiiiii...........lots of question .. In-Reply-To: References: Message-ID: <4F67BCBF-868A-4D68-9443-568FAB157108@mattwynne.net> On 2 Aug 2012, at 06:14, Fahim Patel wrote: > i implement all this question but i dont have knowledge perfectly .......ok........ > > explain with example code............ > tell me what is mock and stub ? > stub_model and mock_model ? > mock and mock_model? > > > what to use first rspec or cucumber?? > which is best rspec or cucumber?? > > > how to write spec in controller,view and model?? > > > i m new born baby and i started crying ........stop my crying .. I would highly recommend buying a copy of The RSpec Book. It will answer all of these questions any many many more. http://pragprog.com/book/achbd/the-rspec-book cheers, Matt -- Freelance programmer & coach Author, http://pragprog.com/book/hwcuc/the-cucumber-book Teacher, http://bddkickstart.com Founder, http://www.relishapp.com/ Twitter, https://twitter.com/mattwynne From iainspeed at gmail.com Fri Aug 10 12:22:41 2012 From: iainspeed at gmail.com (Iain Barnett) Date: Fri, 10 Aug 2012 13:22:41 +0100 Subject: [rspec-users] Specing a method that returns a lambda Message-ID: <95D727DD-6704-4BBD-AE9F-E2AD1F4A5D7D@gmail.com> Hello, I have a class that takes callbacks and stores them for later use. It supplies a default block for all the other methods to use, and you can set a new default if you like. I want to check that the new default is being set and that it's the same block as the one given. When I try and spec this, however, I get the following message: > When you call a matcher in an example without a String, like this: specify { object.should matcher } or this: it { should matcher } RSpec expects the matcher to have a #description method. You should either add a String to the example this matcher is being used in, or give it a description method. Then you won't have to suffer this lengthy warning again. The code is as like this: DEFAULT_BLOCK = ->(klass,field){ ->(term) { klass.filter(field.to_sym => /#{term}.*/i).select(Sequel.as(field,"value")) } } def default_suggester=(block) @default_block = block end def default_suggester @default_block ||= DEFAULT_BLOCK end and the spec I had that gave that message: describe "Adding a default suggester" do include_context "All pages" # this loads the Sinatra app the code runs in and puts it in a variable called "app". let(:my_default) { ->(klass,field) { ->(term) { klass.filter( Sequel.like(field.to_sym, "#{term}%") ).select(Sequel.as(field,"value")) } } } context "When given a new default suggester" do before :all do app.suggesters.clear app.default_suggester = my_default end it "should be a lambda/proc" do app.default_suggester.should respond_to? :call end it "should be the same as my_default" do app.default_suggester.should.equal? my_default end after :all do app.suggesters.clear end end end It appears to me that because it's a lambda that RSpec thinks it's a matcher? Is there a way to change this to do what I intend? Any suggestions or help would be much appreciated. I'm running Ruby v1.9.3-p194 and RSpec 2.11.0 Regards, Iain From dchelimsky at gmail.com Sat Aug 11 11:07:04 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 11 Aug 2012 07:07:04 -0400 Subject: [rspec-users] Specing a method that returns a lambda In-Reply-To: <95D727DD-6704-4BBD-AE9F-E2AD1F4A5D7D@gmail.com> References: <95D727DD-6704-4BBD-AE9F-E2AD1F4A5D7D@gmail.com> Message-ID: On Fri, Aug 10, 2012 at 8:22 AM, Iain Barnett wrote: > Hello, > > I have a class that takes callbacks and stores them for later use. It supplies a default block for all the other methods to use, and you can set a new default if you like. I want to check that the new default is being set and that it's the same block as the one given. When I try and spec this, however, I get the following message: > >> When you call a matcher in an example without a String, like this: > > specify { object.should matcher } > > or this: > > it { should matcher } or this: specify { expect(object).to matcher w000t! > > RSpec expects the matcher to have a #description method. You should either > add a String to the example this matcher is being used in, or give it a > description method. Then you won't have to suffer this lengthy warning again. > > > The code is as like this: > > DEFAULT_BLOCK = ->(klass,field){ > ->(term) { > klass.filter(field.to_sym => /#{term}.*/i).select(Sequel.as(field,"value")) > } > } > > > def default_suggester=(block) > @default_block = block > end > > > def default_suggester > @default_block ||= DEFAULT_BLOCK > end > > > and the spec I had that gave that message: > > describe "Adding a default suggester" do > include_context "All pages" # this loads the Sinatra app the code runs in and puts it in a variable called "app". > let(:my_default) { ->(klass,field) { > ->(term) { > klass.filter( > Sequel.like(field.to_sym, "#{term}%") > ).select(Sequel.as(field,"value")) > } > } > } > > context "When given a new default suggester" do > before :all do > app.suggesters.clear > app.default_suggester = my_default > end > it "should be a lambda/proc" do > app.default_suggester.should respond_to? :call > end > it "should be the same as my_default" do > app.default_suggester.should.equal? my_default > end > after :all do > app.suggesters.clear > end > end > end > > It appears to me that because it's a lambda that RSpec thinks it's a matcher? Is there a way to change this to do what I intend? That sounds like a red herring, but I'm not sure. > > Any suggestions or help would be much appreciated. I'm running Ruby v1.9.3-p194 and RSpec 2.11.0 My guess is that it's related to the context being included and the fact that you're using before :all. Try it with before :each and see if that works. If not, please run the spec with the --backtrace flag and post the full backtrace, along with the code in the included context. From pafahim at gmail.com Mon Aug 13 04:55:37 2012 From: pafahim at gmail.com (Fahim Patel) Date: Mon, 13 Aug 2012 10:25:37 +0530 Subject: [rspec-users] thanks......but more question Message-ID: 1. model spec only consist a spec of validation only????? or we can write more different type of spec in it..... 2. please tell me that or give category that what kind of spec is expecting in Model spec,controller spec ,view spec ,request,helper, (spec directory structure) .... thanks Fahim Babar Patel -------------- next part -------------- An HTML attachment was scrubbed... URL: From alindeman at gmail.com Mon Aug 13 11:51:45 2012 From: alindeman at gmail.com (Andy Lindeman) Date: Mon, 13 Aug 2012 07:51:45 -0400 Subject: [rspec-users] thanks......but more question In-Reply-To: References: Message-ID: On Mon, Aug 13, 2012 at 12:55 AM, Fahim Patel wrote: > 1. model spec only consist a spec of validation only????? or we can write > more different type of spec in it..... RSpec places no restrictions on what types of tests you write in your model specs. I've seen tests against validations, but also against other logic that is in the model. > 2. please tell me that or give category that what kind of spec is expecting > in Model spec,controller spec ,view spec ,request,helper, > (spec directory structure) .... Model specs test models; controller tests test controllers; view tests test views; helper specs test helpers. These are ideally all unit tests that take one object and test it in isolation or near isolation; however, there's nothing in RSpec that restricts you to that either. Request specs are meant to be full-stack or close to full-stack tests that interact with the application via HTTP requests. These requests run through the entire system and you usually assert either against the state afterward (e.g., I expect this request to create a user in the database) or against the state a client could observe (e.g., I expect this request to return an HTML table of users). -- Andy Lindeman http://www.andylindeman.com/ From pafahim at gmail.com Thu Aug 16 04:35:00 2012 From: pafahim at gmail.com (Fahim Patel) Date: Thu, 16 Aug 2012 10:05:00 +0530 Subject: [rspec-users] more question Message-ID: 1. i read some thing about cucumber .What is this??? 2. it is better than rspec????? 3. what is diff between rspec and cucumber???? 4. are this both are dependent on each other?????if not than which one is best???? thanks may Allah bless u all -------------- next part -------------- An HTML attachment was scrubbed... URL: From pafahim at gmail.com Thu Aug 16 06:06:04 2012 From: pafahim at gmail.com (Fahim Patel) Date: Thu, 16 Aug 2012 11:36:04 +0530 Subject: [rspec-users] error Message-ID: let me explain this problem ........ -------------------rails destroy----------------------------this command destroy model,scaffold etc ..... problem is that if a model or other structure is exist than ,this command will destroy all the related file to it.......good ..till now no problem........... but problem is that if a model etc is not exist than till this command remove the file ...it should not be done.....there is no such a file name exist.......... some error or exception should be execute at this time .... i think this a problem??? if not than expalin me.......... Regards Fahim Babar Patel -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Aug 16 11:12:02 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 16 Aug 2012 06:12:02 -0500 Subject: [rspec-users] error In-Reply-To: References: Message-ID: On Thu, Aug 16, 2012 at 1:06 AM, Fahim Patel wrote: > let me explain this problem ........ > -------------------rails destroy---------------------------- Please post questions about Rails to the Rails mailing list: https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-talk From lists at iDIAcomputing.com Thu Aug 16 22:44:57 2012 From: lists at iDIAcomputing.com (George Dinwiddie) Date: Thu, 16 Aug 2012 17:44:57 -0500 Subject: [rspec-users] more question In-Reply-To: References: Message-ID: <502D77E9.9080209@iDIAcomputing.com> Fahim, On 8/15/12 11:35 PM, Fahim Patel wrote: > > 1. i read some thing about cucumber .What is this??? > 2. it is better than rspec????? > 3. what is diff between rspec and cucumber???? > 4. are this both are dependent on each other?????if not than which one I think you'll find your answers at http://rspec.info/ and http://cukes.info/ -- ---------------------------------------------------------------------- * George Dinwiddie * http://blog.gdinwiddie.com Software Development http://www.idiacomputing.com Consultant and Coach http://www.agilemaryland.org ---------------------------------------------------------------------- From iainspeed at gmail.com Mon Aug 20 16:21:54 2012 From: iainspeed at gmail.com (Iain Barnett) Date: Mon, 20 Aug 2012 17:21:54 +0100 Subject: [rspec-users] Specing a method that returns a lambda In-Reply-To: References: <95D727DD-6704-4BBD-AE9F-E2AD1F4A5D7D@gmail.com> Message-ID: <0BD93184-F140-4DC4-93FA-F8D03D2F1F6A@gmail.com> Thanks for replying, and my apologies for the delay in my reply. On 11 Aug 2012, at 12:07, David Chelimsky wrote: > > My guess is that it's related to the context being included and the > fact that you're using before :all. Try it with before :each and see > if that works. If not, please run the spec with the --backtrace flag > and post the full backtrace, along with the code in the included > context. I changed it to `before :each` as you suggested, which is a good move, and then I took the pragmatic route of using `be_a_kind_of Proc` along with arity, instead of `respond_to`, and that works. If the problem arises again later I'll delve deeper and post the backtrace. Regards, Iain From apremdas at gmail.com Tue Aug 21 20:02:10 2012 From: apremdas at gmail.com (Andrew Premdas) Date: Tue, 21 Aug 2012 21:02:10 +0100 Subject: [rspec-users] How do I specify that a class does not receive any message Message-ID: I want to write it "should ..." do Client.should_not_receive(any_message) # do something here that might do Client.xxx end TIA Andrew -- ------------------------ Andrew Premdas blog.andrew.premdas.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From me at jbrains.ca Tue Aug 21 20:12:09 2012 From: me at jbrains.ca (J. B. Rainsberger) Date: Tue, 21 Aug 2012 17:12:09 -0300 Subject: [rspec-users] How do I specify that a class does not receive any message In-Reply-To: References: Message-ID: On Tue, Aug 21, 2012 at 5:02 PM, Andrew Premdas wrote: > I want to write > > it "should ..." do > Client.should_not_receive(any_message) > # do something here that might do Client.xxx > end > I might be wrong, but if you use a mock object and set no expectations on it, it will expect no messages. Have you tried that? -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Author, JUnit Recipes Free Your Mind to Do Great Work :: http://www.freeyourmind-dogreatwork.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From basv at odd-e.com Wed Aug 22 02:37:36 2012 From: basv at odd-e.com (Bas Vodde) Date: Wed, 22 Aug 2012 10:37:36 +0800 Subject: [rspec-users] How do I specify that a class does not receive any message In-Reply-To: References: Message-ID: <597ADB75-A32F-4B99-9434-EF0EC13D9FD1@odd-e.com> JB is right. Sometimes, for clarity, it is useful to add should_not, but for functionality it is usually not needed. Bas On 22 Aug, 2012, at 4:12 AM, J. B. Rainsberger wrote: > On Tue, Aug 21, 2012 at 5:02 PM, Andrew Premdas wrote: > I want to write > > it "should ..." do > Client.should_not_receive(any_message) > # do something here that might do Client.xxx > end > > I might be wrong, but if you use a mock object and set no expectations on it, it will expect no messages. Have you tried that? > -- > J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: > http://blog.thecodewhisperer.com > Author, JUnit Recipes > Free Your Mind to Do Great Work :: http://www.freeyourmind-dogreatwork.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pafahim at gmail.com Wed Aug 22 05:40:24 2012 From: pafahim at gmail.com (Fahim Patel) Date: Wed, 22 Aug 2012 11:10:24 +0530 Subject: [rspec-users] Fwd: [Rails] Re: hii friends, , , , , i m new to rails......i think there is a problem in destroy command . In-Reply-To: References: <057ce95f-c44d-4776-ac4a-b979968e97fd@googlegroups.com> Message-ID: friends there is no reply from Rails community.Lots of days are gone. can u answer this problem. Regards Fahim Babar Patel ---------- Forwarded message ---------- From: Fahim Patel Date: Fri, Aug 17, 2012 at 10:49 AM Subject: [Rails] Re: hii friends,,,,,i m new to rails......i think there is a problem in destroy command . To: rubyonrails-talk at googlegroups.com thanks for reply.....let me explain .... there is no such a testing model present rails destroy model testing invoke active_record remove migration.rb remove app/models/testing.rb invoke rspec remove spec/models/testing_spec.rb invoke factory_girl remove spec/factories/testings.rb but it is still removing files..... one more example rails destroy controller testing remove app/controllers/testing_controller.rb invoke erb remove app/views/testing invoke rspec remove spec/controllers/testing_controller_spec.rb invoke helper remove app/helpers/testing_helper.rb invoke rspec remove spec/helpers/testing_helper_spec.rb invoke assets invoke coffee remove app/assets/javascripts/testing.js.coffee invoke scss remove app/assets/stylesheets/testing.css.scss there is no testing controller prsent..... this thing is happen with all directory structure.... scaffold also do the same thing...... there should be any exception or error ?????????? On Thursday, August 16, 2012 10:33:47 AM UTC+5:30, Fahim Patel wrote: > > let me explain this problem ........ > -------------------rails destroy-----------------------**-----this > command destroy model,scaffold etc ..... > problem is that if a model or other structure is exist than ,this command > will destroy all the related file to it.......good ..till now no > problem........... > but problem is that if a model etc is not exist than till this command > remove the file ...it should not be done.....there is no such a file name > exist.......... > some error or exception should be execute at this time .... > > i think this a problem??? > if not than expalin me.......... > > Regards > Fahim Babar Patel > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk at googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe at googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/SuNnoKhq9TgJ. For more options, visit https://groups.google.com/groups/opt_out. -------------- next part -------------- An HTML attachment was scrubbed... URL: From basv at odd-e.com Wed Aug 22 05:56:21 2012 From: basv at odd-e.com (Bas Vodde) Date: Wed, 22 Aug 2012 13:56:21 +0800 Subject: [rspec-users] and_raise with a message Message-ID: <97D81BFE-072B-4FFA-982D-EC472C540F7E@odd-e.com> Hiya all, I was trying to get and_raise to raise an exception filled with a message and I was struggling with the API for a while (not on the latest RSpec, but assume it didn't change). Based on that, I have a suggestion for improvement. My first attempt was to mirror how I use raise, so I tried: subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed, "execution error: System Events got an error: Access for assistive devices is disabled. (-25211)") This didn't work as the and_raise only has one parameter. Eventually I figured out this works: subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed.new ("execution error: System Events got an error: Access for assistive devices is disabled. (-25211)")) And it does what I want it to do. Still? I would have prefered the first one to work too :) Implementing that ought to be reasonably trivial, correct? (didn't implement it myself yet this time). Comments? Or is there anyone way of doing this? Thanks! Bas From dchelimsky at gmail.com Wed Aug 22 10:49:49 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 22 Aug 2012 05:49:49 -0500 Subject: [rspec-users] Fwd: [Rails] Re: hii friends, , , , , i m new to rails......i think there is a problem in destroy command . In-Reply-To: References: <057ce95f-c44d-4776-ac4a-b979968e97fd@googlegroups.com> Message-ID: On Wed, Aug 22, 2012 at 12:40 AM, Fahim Patel wrote: > friends there is no reply from Rails community.Lots of days are gone. > can u answer this problem. > Regards > Fahim Babar Patel > > > ---------- Forwarded message ---------- > From: Fahim Patel > Date: Fri, Aug 17, 2012 at 10:49 AM > Subject: [Rails] Re: hii friends,,,,,i m new to rails......i think there is > a problem in destroy command . > To: rubyonrails-talk at googlegroups.com > > > thanks for reply.....let me explain .... > > there is no such a testing model present > rails destroy model testing > invoke active_record > remove migration.rb > remove app/models/testing.rb > invoke rspec > remove spec/models/testing_spec.rb > invoke factory_girl > remove spec/factories/testings.rb > > > but it is still removing files..... > > one more example > rails destroy controller testing > remove app/controllers/testing_controller.rb > invoke erb > remove app/views/testing > invoke rspec > remove spec/controllers/testing_controller_spec.rb > invoke helper > remove app/helpers/testing_helper.rb > invoke rspec > remove spec/helpers/testing_helper_spec.rb > invoke assets > invoke coffee > remove app/assets/javascripts/testing.js.coffee > invoke scss > remove app/assets/stylesheets/testing.css.scss > > there is no testing controller prsent..... > this thing is happen with all directory structure.... > scaffold also do the same thing...... > > there should be any exception or error ?????????? > > On Thursday, August 16, 2012 10:33:47 AM UTC+5:30, Fahim Patel wrote: >> >> let me explain this problem ........ >> -------------------rails destroy----------------------------this command >> destroy model,scaffold etc ..... >> problem is that if a model or other structure is exist than ,this command >> will destroy all the related file to it.......good ..till now no >> problem........... >> but problem is that if a model etc is not exist than till this command >> remove the file ...it should not be done.....there is no such a file name >> exist.......... >> some error or exception should be execute at this time .... >> >> i think this a problem??? >> if not than expalin me.......... >> >> Regards >> Fahim Babar Patel Did you see https://groups.google.com/d/msg/rubyonrails-talk/R0A9Oid_I8M/FIO9RzriiXkJ ? I think it answers your question. From dchelimsky at gmail.com Wed Aug 22 11:25:27 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 22 Aug 2012 06:25:27 -0500 Subject: [rspec-users] and_raise with a message In-Reply-To: <97D81BFE-072B-4FFA-982D-EC472C540F7E@odd-e.com> References: <97D81BFE-072B-4FFA-982D-EC472C540F7E@odd-e.com> Message-ID: On Wed, Aug 22, 2012 at 12:56 AM, Bas Vodde wrote: > > Hiya all, > > I was trying to get and_raise to raise an exception filled with a message and I was struggling with the API for a while (not on the latest RSpec, but assume it didn't change). > > Based on that, I have a suggestion for improvement. My first attempt was to mirror how I use raise, so I tried: > > subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed, "execution error: System Events got an error: Access for assistive devices is disabled. (-25211)") > > This didn't work as the and_raise only has one parameter. Eventually I figured out this works: > > subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed.new ("execution error: System Events got an error: Access for assistive devices is disabled. (-25211)")) > > And it does what I want it to do. Still? I would have prefered the first one to work too :) Implementing that ought to be reasonably trivial, correct? > (didn't implement it myself yet this time). > > Comments? Or is there anyone way of doing this? > > Thanks! > > Bas Documentation here: http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/MessageExpectation#and_raise-instance_method. That has been the API for something like 5 years so I'm not sure I want to change it. It is used to prepare an exception to raise, not compare with one that was already raised, so we'd have to support n args, e.g. and_raise(AnException, with_one_arg) and_raise(AnException, with_one_arg, and_another_arg) etc. I think this would be friendly, but it might also be confusing because we'd effectively have 2 completely different APIs for the same method. Also, I'm not sure that either of those examples are much better than: and_raise(AnException.new with_one_arg) and_raise(AnException.new with_one_arg, and_another_arg) I'm open to the idea though for one reason: the rspec-expectations raise_exception method can accept 1 or two args, so I can imagine something like: describe Foo do it "raises when x happens" do foo = Foo.new(Bar.new) expect { Foo.do_something_bad }.to raise_exception(FooException, "with this message") end it "does x when its bar raises" do bar = double foo = Foo.new(bar) bar.should_receive(:msg).and_raise(BarException, "with this message") end end Your suggestion makes these two APIs align better if the exception initializer accepts one argument and raise_exception gets a String. But raise_exception can also take a regex, and exception initializers can take more than one arg. Consider: InsufficientFunds.new(50, :USD). The way things are today, you might see these two near each other (hopefully not in the same example): expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/) source_account.should_receive(:withdraw).and_raise(InsufficientFunds.new 50, :USD) With what you propose it would be this: expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/) source_account.should_receive(:withdraw).and_raise(InsufficientFunds, 50, :USD) I think the way it is now tells a better story about what's really going on (i.e. that you're supplying an initialized object to and_raise) than the proposed change. But that's one opinion. Any others out there? From basv at odd-e.com Wed Aug 22 11:43:16 2012 From: basv at odd-e.com (Bas Vodde) Date: Wed, 22 Aug 2012 19:43:16 +0800 Subject: [rspec-users] and_raise with a message In-Reply-To: References: <97D81BFE-072B-4FFA-982D-EC472C540F7E@odd-e.com> Message-ID: Hi David, My main thinking was to make it consistent with the Kernel.raise. Like, in my production code, I have: raise Osaka::SystemCommandFailed, output_message so, it would make sense to the mock to work the same with: and_raise Osaka::SystemCommandFailed, "Fake output message" I figured it would be a relative minor change as it would add one extra parameter which could default to an empty string. (as reference, see Kernel raise: http://www.ruby-doc.org/core-1.9.3/Kernel.html) I had not considered the consistency with and_raise_exception, but I just noticed that this was one of the cases where my default excepted behavior from RSpec was different from what the API wanted. Therefore, I had to dive in the RSpec doc to see how I could pass the message?. Bas On 22 Aug, 2012, at 7:25 PM, David Chelimsky wrote: > On Wed, Aug 22, 2012 at 12:56 AM, Bas Vodde wrote: >> >> Hiya all, >> >> I was trying to get and_raise to raise an exception filled with a message and I was struggling with the API for a while (not on the latest RSpec, but assume it didn't change). >> >> Based on that, I have a suggestion for improvement. My first attempt was to mirror how I use raise, so I tried: >> >> subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed, "execution error: System Events got an error: Access for assistive devices is disabled. (-25211)") >> >> This didn't work as the and_raise only has one parameter. Eventually I figured out this works: >> >> subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed.new ("execution error: System Events got an error: Access for assistive devices is disabled. (-25211)")) >> >> And it does what I want it to do. Still? I would have prefered the first one to work too :) Implementing that ought to be reasonably trivial, correct? >> (didn't implement it myself yet this time). >> >> Comments? Or is there anyone way of doing this? >> >> Thanks! >> >> Bas > > Documentation here: > http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/MessageExpectation#and_raise-instance_method. > > That has been the API for something like 5 years so I'm not sure I > want to change it. It is used to prepare an exception to raise, not > compare with one that was already raised, so we'd have to support n > args, e.g. > > and_raise(AnException, with_one_arg) > and_raise(AnException, with_one_arg, and_another_arg) > > etc. I think this would be friendly, but it might also be confusing > because we'd effectively have 2 completely different APIs for the same > method. Also, I'm not sure that either of those examples are much > better than: > > and_raise(AnException.new with_one_arg) > and_raise(AnException.new with_one_arg, and_another_arg) > > I'm open to the idea though for one reason: the rspec-expectations > raise_exception method can accept 1 or two args, so I can imagine > something like: > > describe Foo do > it "raises when x happens" do > foo = Foo.new(Bar.new) > expect { Foo.do_something_bad }.to raise_exception(FooException, > "with this message") > end > > it "does x when its bar raises" do > bar = double > foo = Foo.new(bar) > bar.should_receive(:msg).and_raise(BarException, "with this message") > end > end > > Your suggestion makes these two APIs align better if the exception > initializer accepts one argument and raise_exception gets a String. > But raise_exception can also take a regex, and exception initializers > can take more than one arg. Consider: InsufficientFunds.new(50, :USD). > The way things are today, you might see these two near each other > (hopefully not in the same example): > > expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/) > source_account.should_receive(:withdraw).and_raise(InsufficientFunds.new > 50, :USD) > > With what you propose it would be this: > > expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/) > source_account.should_receive(:withdraw).and_raise(InsufficientFunds, > 50, :USD) > > I think the way it is now tells a better story about what's really > going on (i.e. that you're supplying an initialized object to > and_raise) than the proposed change. But that's one opinion. > > Any others out there? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Aug 22 11:55:39 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 22 Aug 2012 06:55:39 -0500 Subject: [rspec-users] and_raise with a message In-Reply-To: References: <97D81BFE-072B-4FFA-982D-EC472C540F7E@odd-e.com> Message-ID: On Wed, Aug 22, 2012 at 6:43 AM, Bas Vodde wrote: > > On 22 Aug, 2012, at 7:25 PM, David Chelimsky wrote: > >> On Wed, Aug 22, 2012 at 12:56 AM, Bas Vodde wrote: >>> >>> Hiya all, >>> >>> I was trying to get and_raise to raise an exception filled with a message and I was struggling with the API for a while (not on the latest RSpec, but assume it didn't change). >>> >>> Based on that, I have a suggestion for improvement. My first attempt was to mirror how I use raise, so I tried: >>> >>> subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed, "execution error: System Events got an error: Access for assistive devices is disabled. (-25211)") >>> >>> This didn't work as the and_raise only has one parameter. Eventually I figured out this works: >>> >>> subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed.new ("execution error: System Events got an error: Access for assistive devices is disabled. (-25211)")) >>> >>> And it does what I want it to do. Still? I would have prefered the first one to work too :) Implementing that ought to be reasonably trivial, correct? >>> (didn't implement it myself yet this time). >>> >>> Comments? Or is there anyone way of doing this? >>> >>> Thanks! >>> >>> Bas >> >> Documentation here: >> http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/MessageExpectation#and_raise-instance_method. >> >> That has been the API for something like 5 years so I'm not sure I >> want to change it. It is used to prepare an exception to raise, not >> compare with one that was already raised, so we'd have to support n >> args, e.g. >> >> and_raise(AnException, with_one_arg) >> and_raise(AnException, with_one_arg, and_another_arg) >> >> etc. I think this would be friendly, but it might also be confusing >> because we'd effectively have 2 completely different APIs for the same >> method. Also, I'm not sure that either of those examples are much >> better than: >> >> and_raise(AnException.new with_one_arg) >> and_raise(AnException.new with_one_arg, and_another_arg) >> >> I'm open to the idea though for one reason: the rspec-expectations >> raise_exception method can accept 1 or two args, so I can imagine >> something like: >> >> describe Foo do >> it "raises when x happens" do >> foo = Foo.new(Bar.new) >> expect { Foo.do_something_bad }.to raise_exception(FooException, >> "with this message") >> end >> >> it "does x when its bar raises" do >> bar = double >> foo = Foo.new(bar) >> bar.should_receive(:msg).and_raise(BarException, "with this message") >> end >> end >> >> Your suggestion makes these two APIs align better if the exception >> initializer accepts one argument and raise_exception gets a String. >> But raise_exception can also take a regex, and exception initializers >> can take more than one arg. Consider: InsufficientFunds.new(50, :USD). >> The way things are today, you might see these two near each other >> (hopefully not in the same example): >> >> expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/) >> source_account.should_receive(:withdraw).and_raise(InsufficientFunds.new >> 50, :USD) >> >> With what you propose it would be this: >> >> expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/) >> source_account.should_receive(:withdraw).and_raise(InsufficientFunds, >> 50, :USD) >> >> I think the way it is now tells a better story about what's really >> going on (i.e. that you're supplying an initialized object to >> and_raise) than the proposed change. But that's one opinion. >> >> Any others out there? > > Hi David, > > My main thinking was to make it consistent with the Kernel.raise. > > Like, in my production code, I have: > > raise Osaka::SystemCommandFailed, output_message > > so, it would make sense to the mock to work the same with: > > and_raise Osaka::SystemCommandFailed, "Fake output message" > > I figured it would be a relative minor change as it would add one extra parameter which could default to an empty string. > (as reference, see Kernel raise: http://www.ruby-doc.org/core-1.9.3/Kernel.html) > > I had not considered the consistency with and_raise_exception, but I just noticed that this was one of the cases where my default excepted behavior from RSpec was different from what the API wanted. Therefore, I had to dive in the RSpec doc to see how I could pass the message?. > > Bas Unfortunately, the Kernel#raise API also accepts a 3rd argument, which is an Array of caller information (the backtrace): http://www.ruby-doc.org/core-1.9.3/Kernel.html#method-i-raise. What that doc doesn't tell you is that the first arg can actually be an initialized exception: raise InsufficientFunds.new(49, :USD) I can't remember where I heard this but there was some advice from a respected software developer that said something like "APIs should be loose with what they accept and strict with what they return." Based on that advice, we should support your suggestion. It's not like if you use one API or the other you're going to get a different result. Beginning to lean in favor. More opinions? From dchelimsky at gmail.com Wed Aug 22 11:59:48 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 22 Aug 2012 06:59:48 -0500 Subject: [rspec-users] and_raise with a message In-Reply-To: References: <97D81BFE-072B-4FFA-982D-EC472C540F7E@odd-e.com> Message-ID: On Wed, Aug 22, 2012 at 6:55 AM, David Chelimsky wrote: > On Wed, Aug 22, 2012 at 6:43 AM, Bas Vodde wrote: >> >> On 22 Aug, 2012, at 7:25 PM, David Chelimsky wrote: >> >>> On Wed, Aug 22, 2012 at 12:56 AM, Bas Vodde wrote: >>>> >>>> Hiya all, >>>> >>>> I was trying to get and_raise to raise an exception filled with a message and I was struggling with the API for a while (not on the latest RSpec, but assume it didn't change). >>>> >>>> Based on that, I have a suggestion for improvement. My first attempt was to mirror how I use raise, so I tried: >>>> >>>> subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed, "execution error: System Events got an error: Access for assistive devices is disabled. (-25211)") >>>> >>>> This didn't work as the and_raise only has one parameter. Eventually I figured out this works: >>>> >>>> subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed.new ("execution error: System Events got an error: Access for assistive devices is disabled. (-25211)")) >>>> >>>> And it does what I want it to do. Still? I would have prefered the first one to work too :) Implementing that ought to be reasonably trivial, correct? >>>> (didn't implement it myself yet this time). >>>> >>>> Comments? Or is there anyone way of doing this? >>>> >>>> Thanks! >>>> >>>> Bas >>> >>> Documentation here: >>> http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/MessageExpectation#and_raise-instance_method. >>> >>> That has been the API for something like 5 years so I'm not sure I >>> want to change it. It is used to prepare an exception to raise, not >>> compare with one that was already raised, so we'd have to support n >>> args, e.g. >>> >>> and_raise(AnException, with_one_arg) >>> and_raise(AnException, with_one_arg, and_another_arg) >>> >>> etc. I think this would be friendly, but it might also be confusing >>> because we'd effectively have 2 completely different APIs for the same >>> method. Also, I'm not sure that either of those examples are much >>> better than: >>> >>> and_raise(AnException.new with_one_arg) >>> and_raise(AnException.new with_one_arg, and_another_arg) >>> >>> I'm open to the idea though for one reason: the rspec-expectations >>> raise_exception method can accept 1 or two args, so I can imagine >>> something like: >>> >>> describe Foo do >>> it "raises when x happens" do >>> foo = Foo.new(Bar.new) >>> expect { Foo.do_something_bad }.to raise_exception(FooException, >>> "with this message") >>> end >>> >>> it "does x when its bar raises" do >>> bar = double >>> foo = Foo.new(bar) >>> bar.should_receive(:msg).and_raise(BarException, "with this message") >>> end >>> end >>> >>> Your suggestion makes these two APIs align better if the exception >>> initializer accepts one argument and raise_exception gets a String. >>> But raise_exception can also take a regex, and exception initializers >>> can take more than one arg. Consider: InsufficientFunds.new(50, :USD). >>> The way things are today, you might see these two near each other >>> (hopefully not in the same example): >>> >>> expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/) >>> source_account.should_receive(:withdraw).and_raise(InsufficientFunds.new >>> 50, :USD) >>> >>> With what you propose it would be this: >>> >>> expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/) >>> source_account.should_receive(:withdraw).and_raise(InsufficientFunds, >>> 50, :USD) >>> >>> I think the way it is now tells a better story about what's really >>> going on (i.e. that you're supplying an initialized object to >>> and_raise) than the proposed change. But that's one opinion. >>> >>> Any others out there? >> >> Hi David, >> >> My main thinking was to make it consistent with the Kernel.raise. >> >> Like, in my production code, I have: >> >> raise Osaka::SystemCommandFailed, output_message >> >> so, it would make sense to the mock to work the same with: >> >> and_raise Osaka::SystemCommandFailed, "Fake output message" >> >> I figured it would be a relative minor change as it would add one extra parameter which could default to an empty string. >> (as reference, see Kernel raise: http://www.ruby-doc.org/core-1.9.3/Kernel.html) >> >> I had not considered the consistency with and_raise_exception, but I just noticed that this was one of the cases where my default excepted behavior from RSpec was different from what the API wanted. Therefore, I had to dive in the RSpec doc to see how I could pass the message?. >> >> Bas > > Unfortunately, the Kernel#raise API also accepts a 3rd argument, which > is an Array of caller information (the backtrace): > http://www.ruby-doc.org/core-1.9.3/Kernel.html#method-i-raise. > > What that doc doesn't tell you is that the first arg can actually be > an initialized exception: > > raise InsufficientFunds.new(49, :USD) > > I can't remember where I heard this but there was some advice from a > respected software developer that said something like "APIs should be > loose with what they accept and strict with what they return." Based > on that advice, we should support your suggestion. It's not like if > you use one API or the other you're going to get a different result. > Beginning to lean in favor. > > More opinions? Then again ... raise InsufficientFunds, 50, :USD # raises ArgumentError and_raise InsufficientFunds, 50, :USD # currently raises ArgumentError, would not if we implement this suggestion So it depends on what we want to align with. From me at jbrains.ca Wed Aug 22 12:52:36 2012 From: me at jbrains.ca (J. B. Rainsberger) Date: Wed, 22 Aug 2012 09:52:36 -0300 Subject: [rspec-users] How do I specify that a class does not receive any message In-Reply-To: <597ADB75-A32F-4B99-9434-EF0EC13D9FD1@odd-e.com> References: <597ADB75-A32F-4B99-9434-EF0EC13D9FD1@odd-e.com> Message-ID: On Tue, Aug 21, 2012 at 11:37 PM, Bas Vodde wrote: > > JB is right. > > Sometimes, for clarity, it is useful to add should_not, but for > functionality it is usually not needed. > I know JMock has never() for this people. Should RSpec-mocks have something like object.should_receive(:nothing). -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Author, JUnit Recipes Free Your Mind to Do Great Work :: http://www.freeyourmind-dogreatwork.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Aug 22 13:07:30 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 22 Aug 2012 08:07:30 -0500 Subject: [rspec-users] How do I specify that a class does not receive any message In-Reply-To: References: <597ADB75-A32F-4B99-9434-EF0EC13D9FD1@odd-e.com> Message-ID: On Wed, Aug 22, 2012 at 7:52 AM, J. B. Rainsberger wrote: > On Tue, Aug 21, 2012 at 11:37 PM, Bas Vodde wrote: >> >> >> JB is right. >> >> Sometimes, for clarity, it is useful to add should_not, but for >> functionality it is usually not needed. > > > I know JMock has never() for this people. Should RSpec-mocks have something > like object.should_receive(:nothing). never() is not a catch all for _all_ messages. It is for a specific message, just like it is in rspec-mocks # rspec object.should_receive(:msg).never #jmock never(object).msg() > -- > J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: > http://blog.thecodewhisperer.com > Author, JUnit Recipes > Free Your Mind to Do Great Work :: http://www.freeyourmind-dogreatwork.com > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From me at jbrains.ca Wed Aug 22 14:16:46 2012 From: me at jbrains.ca (J. B. Rainsberger) Date: Wed, 22 Aug 2012 11:16:46 -0300 Subject: [rspec-users] How do I specify that a class does not receive any message In-Reply-To: References: <597ADB75-A32F-4B99-9434-EF0EC13D9FD1@odd-e.com> Message-ID: On Wed, Aug 22, 2012 at 10:07 AM, David Chelimsky wrote: > On Wed, Aug 22, 2012 at 7:52 AM, J. B. Rainsberger wrote: > > On Tue, Aug 21, 2012 at 11:37 PM, Bas Vodde wrote: > >> > >> > >> JB is right. > >> > >> Sometimes, for clarity, it is useful to add should_not, but for > >> functionality it is usually not needed. > > > > > > I know JMock has never() for this people. Should RSpec-mocks have > something > > like object.should_receive(:nothing). > > never() is not a catch all for _all_ messages. It is for a specific > message, just like it is in rspec-mocks > > # rspec > object.should_receive(:msg).never > > #jmock > never(object).msg() > In JMock, you can write this: never(object); and this means "never anything". Just like ignoring(object); allowing(object); which each equate to mock().as_null_object(). -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Author, JUnit Recipes Free Your Mind to Do Great Work :: http://www.freeyourmind-dogreatwork.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Aug 22 14:36:43 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 22 Aug 2012 09:36:43 -0500 Subject: [rspec-users] How do I specify that a class does not receive any message In-Reply-To: References: <597ADB75-A32F-4B99-9434-EF0EC13D9FD1@odd-e.com> Message-ID: On Wed, Aug 22, 2012 at 9:16 AM, J. B. Rainsberger wrote: > On Wed, Aug 22, 2012 at 10:07 AM, David Chelimsky > wrote: >> >> On Wed, Aug 22, 2012 at 7:52 AM, J. B. Rainsberger wrote: >> > On Tue, Aug 21, 2012 at 11:37 PM, Bas Vodde wrote: >> >> >> >> >> >> JB is right. >> >> >> >> Sometimes, for clarity, it is useful to add should_not, but for >> >> functionality it is usually not needed. >> > >> > >> > I know JMock has never() for this people. Should RSpec-mocks have >> > something >> > like object.should_receive(:nothing). >> >> never() is not a catch all for _all_ messages. It is for a specific >> message, just like it is in rspec-mocks >> >> # rspec >> object.should_receive(:msg).never >> >> #jmock >> never(object).msg() > > > In JMock, you can write this: > > never(object); > > and this means "never anything". Just like > > ignoring(object); > allowing(object); > > which each equate to mock().as_null_object(). Perhaps it goes without saying, but I was not aware of that ;) As you noted earlier this thread (not quoted above) RSpec::Mocks::Mock instances (returned by double(), mock(), or stub()) are strict by default - e.g. they'll complain about any unexpected messages. Obviously that does not account for any real objects. I'm open to adding an API for this, but not object.should_receive(:nothing) since that syntax is for declaring expected messages. Other ideas welcome. From me at jbrains.ca Wed Aug 22 15:11:58 2012 From: me at jbrains.ca (J. B. Rainsberger) Date: Wed, 22 Aug 2012 12:11:58 -0300 Subject: [rspec-users] How do I specify that a class does not receive any message In-Reply-To: References: <597ADB75-A32F-4B99-9434-EF0EC13D9FD1@odd-e.com> Message-ID: On Wed, Aug 22, 2012 at 11:36 AM, David Chelimsky wrote: > On Wed, Aug 22, 2012 at 9:16 AM, J. B. Rainsberger wrote: > > On Wed, Aug 22, 2012 at 10:07 AM, David Chelimsky > > wrote: > >> > >> On Wed, Aug 22, 2012 at 7:52 AM, J. B. Rainsberger > wrote: > >> > On Tue, Aug 21, 2012 at 11:37 PM, Bas Vodde wrote: > >> >> > >> >> > >> >> JB is right. > >> >> > >> >> Sometimes, for clarity, it is useful to add should_not, but for > >> >> functionality it is usually not needed. > >> > > >> > > >> > I know JMock has never() for this people. Should RSpec-mocks have > >> > something > >> > like object.should_receive(:nothing). > >> > >> never() is not a catch all for _all_ messages. It is for a specific > >> message, just like it is in rspec-mocks > >> > >> # rspec > >> object.should_receive(:msg).never > >> > >> #jmock > >> never(object).msg() > > > > > > In JMock, you can write this: > > > > never(object); > > > > and this means "never anything". Just like > > > > ignoring(object); > > allowing(object); > > > > which each equate to mock().as_null_object(). > > Perhaps it goes without saying, but I was not aware of that ;) > I am at your service. > As you noted earlier this thread (not quoted above) RSpec::Mocks::Mock > instances (returned by double(), mock(), or stub()) are strict by > default - e.g. they'll complain about any unexpected messages. > Obviously that does not account for any real objects. > > I'm open to adding an API for this, but not > object.should_receive(:nothing) since that syntax is for declaring > expected messages. > I agree that that doesn't work. Is object.should_receive_nothing completely out of the question? -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Author, JUnit Recipes Free Your Mind to Do Great Work :: http://www.freeyourmind-dogreatwork.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From lenny at aps.org Wed Aug 22 17:38:34 2012 From: lenny at aps.org (Lenny Marks) Date: Wed, 22 Aug 2012 13:38:34 -0400 Subject: [rspec-users] How do I specify that a class does not receive any message In-Reply-To: References: <597ADB75-A32F-4B99-9434-EF0EC13D9FD1@odd-e.com> Message-ID: <4B966B71-A37B-44DE-A503-6364AC55DE5D@aps.org> On Aug 22, 2012, at 10:36 AM, David Chelimsky wrote: > On Wed, Aug 22, 2012 at 9:16 AM, J. B. Rainsberger wrote: >> On Wed, Aug 22, 2012 at 10:07 AM, David Chelimsky >> wrote: >>> >>> On Wed, Aug 22, 2012 at 7:52 AM, J. B. Rainsberger wrote: >>>> On Tue, Aug 21, 2012 at 11:37 PM, Bas Vodde wrote: >>>>> >>>>> >>>>> JB is right. >>>>> >>>>> Sometimes, for clarity, it is useful to add should_not, but for >>>>> functionality it is usually not needed. >>>> >>>> >>>> I know JMock has never() for this people. Should RSpec-mocks have >>>> something >>>> like object.should_receive(:nothing). >>> >>> never() is not a catch all for _all_ messages. It is for a specific >>> message, just like it is in rspec-mocks >>> >>> # rspec >>> object.should_receive(:msg).never >>> >>> #jmock >>> never(object).msg() >> >> >> In JMock, you can write this: >> >> never(object); >> >> and this means "never anything". Just like >> >> ignoring(object); >> allowing(object); >> >> which each equate to mock().as_null_object(). > > Perhaps it goes without saying, but I was not aware of that ;) > > As you noted earlier this thread (not quoted above) RSpec::Mocks::Mock > instances (returned by double(), mock(), or stub()) are strict by > default - e.g. they'll complain about any unexpected messages. > Obviously that does not account for any real objects. > > I'm open to adding an API for this, but not > object.should_receive(:nothing) since that syntax is for declaring > expected messages. > +1 for me. I've found myself on occasion using should_not_receive(:some_message). OK, see a failing spec, make it pass, but what about when the collaborator method is renamed. All those should_not_receive expectations will still pass no matter what. It would be great to have object.should_receive(:nothing) instead. This would make life easier when collaborators are stubbed out with :as_null_object stubs. -lenny > Other ideas welcome. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lenny at aps.org Wed Aug 22 18:08:40 2012 From: lenny at aps.org (Lenny Marks) Date: Wed, 22 Aug 2012 14:08:40 -0400 Subject: [rspec-users] How do I specify that a class does not receive any message In-Reply-To: <4B966B71-A37B-44DE-A503-6364AC55DE5D@aps.org> References: <597ADB75-A32F-4B99-9434-EF0EC13D9FD1@odd-e.com> <4B966B71-A37B-44DE-A503-6364AC55DE5D@aps.org> Message-ID: <76AF4A1F-4C38-4324-A017-B03B98E19D9F@aps.org> On Aug 22, 2012, at 1:38 PM, Lenny Marks wrote: > > On Aug 22, 2012, at 10:36 AM, David Chelimsky wrote: > >> On Wed, Aug 22, 2012 at 9:16 AM, J. B. Rainsberger wrote: >>> On Wed, Aug 22, 2012 at 10:07 AM, David Chelimsky >>> wrote: >>>> >>>> On Wed, Aug 22, 2012 at 7:52 AM, J. B. Rainsberger wrote: >>>>> On Tue, Aug 21, 2012 at 11:37 PM, Bas Vodde wrote: >>>>>> >>>>>> >>>>>> JB is right. >>>>>> >>>>>> Sometimes, for clarity, it is useful to add should_not, but for >>>>>> functionality it is usually not needed. >>>>> >>>>> >>>>> I know JMock has never() for this people. Should RSpec-mocks have >>>>> something >>>>> like object.should_receive(:nothing). >>>> >>>> never() is not a catch all for _all_ messages. It is for a specific >>>> message, just like it is in rspec-mocks >>>> >>>> # rspec >>>> object.should_receive(:msg).never >>>> >>>> #jmock >>>> never(object).msg() >>> >>> >>> In JMock, you can write this: >>> >>> never(object); >>> >>> and this means "never anything". Just like >>> >>> ignoring(object); >>> allowing(object); >>> >>> which each equate to mock().as_null_object(). >> >> Perhaps it goes without saying, but I was not aware of that ;) >> >> As you noted earlier this thread (not quoted above) RSpec::Mocks::Mock >> instances (returned by double(), mock(), or stub()) are strict by >> default - e.g. they'll complain about any unexpected messages. >> Obviously that does not account for any real objects. >> >> I'm open to adding an API for this, but not >> object.should_receive(:nothing) since that syntax is for declaring >> expected messages. >> > > +1 for me. I've found myself on occasion using should_not_receive(:some_message). OK, see a failing spec, make it pass, but what about when the collaborator method is renamed. All those should_not_receive expectations will still pass no matter what. It would be great to have object.should_receive(:nothing) instead. This would make life easier when collaborators are stubbed out with :as_null_object stubs. I mean some equivalent to object.should_receive(:nothing). Maybe object.should_receive_nothing ?? > > -lenny > >> Other ideas welcome. >> _______________________________________________ >> 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 basv at odd-e.com Thu Aug 23 03:37:34 2012 From: basv at odd-e.com (Bas Vodde) Date: Thu, 23 Aug 2012 11:37:34 +0800 Subject: [rspec-users] and_raise with a message In-Reply-To: References: <97D81BFE-072B-4FFA-982D-EC472C540F7E@odd-e.com> Message-ID: <7DF05AB9-33A5-4365-975A-AA40718C185A@odd-e.com> Hola, I went ahead and wrote some code instead of emails and implemented it and send a pull request. The way I implemented was just pretty simple: - and_raise has a second parameter which is an empty string by default - when raise_exception is called and the exception passed is a Class, then it will pass the message - The spec that didn't allow for exception classes with constructor arguments has been changed to allow for 1, the message The pull request stayed close to the original code. However, an alternative implementation would be: - The and_raise itself creates an object when a class is passed. This allows for the "too much arguments" check to be done earlier and it would fail earlier. - The raise_exception would simply raise an object (always) and never a Class This does change the behavior from late fail to early fail. I'm not sure if there is a good reason to the current late fail, so I sticked with the original implementation. Pull request done. Feel free to decline it if you want it implemented differently. If you want to see the alternative, I can make a new pull request with the alternative implementation. Thanks, Bas ps. If you want to ignore it completely, thats also ok with me. It is not a major point, it just was one of the surprises I had working with rspec, and surprise usually suggest a potential API improvement :) On 22 Aug, 2012, at 7:59 PM, David Chelimsky wrote: > On Wed, Aug 22, 2012 at 6:55 AM, David Chelimsky wrote: >> On Wed, Aug 22, 2012 at 6:43 AM, Bas Vodde wrote: >>> >>> On 22 Aug, 2012, at 7:25 PM, David Chelimsky wrote: >>> >>>> On Wed, Aug 22, 2012 at 12:56 AM, Bas Vodde wrote: >>>>> >>>>> Hiya all, >>>>> >>>>> I was trying to get and_raise to raise an exception filled with a message and I was struggling with the API for a while (not on the latest RSpec, but assume it didn't change). >>>>> >>>>> Based on that, I have a suggestion for improvement. My first attempt was to mirror how I use raise, so I tried: >>>>> >>>>> subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed, "execution error: System Events got an error: Access for assistive devices is disabled. (-25211)") >>>>> >>>>> This didn't work as the and_raise only has one parameter. Eventually I figured out this works: >>>>> >>>>> subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed.new ("execution error: System Events got an error: Access for assistive devices is disabled. (-25211)")) >>>>> >>>>> And it does what I want it to do. Still? I would have prefered the first one to work too :) Implementing that ought to be reasonably trivial, correct? >>>>> (didn't implement it myself yet this time). >>>>> >>>>> Comments? Or is there anyone way of doing this? >>>>> >>>>> Thanks! >>>>> >>>>> Bas >>>> >>>> Documentation here: >>>> http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/MessageExpectation#and_raise-instance_method. >>>> >>>> That has been the API for something like 5 years so I'm not sure I >>>> want to change it. It is used to prepare an exception to raise, not >>>> compare with one that was already raised, so we'd have to support n >>>> args, e.g. >>>> >>>> and_raise(AnException, with_one_arg) >>>> and_raise(AnException, with_one_arg, and_another_arg) >>>> >>>> etc. I think this would be friendly, but it might also be confusing >>>> because we'd effectively have 2 completely different APIs for the same >>>> method. Also, I'm not sure that either of those examples are much >>>> better than: >>>> >>>> and_raise(AnException.new with_one_arg) >>>> and_raise(AnException.new with_one_arg, and_another_arg) >>>> >>>> I'm open to the idea though for one reason: the rspec-expectations >>>> raise_exception method can accept 1 or two args, so I can imagine >>>> something like: >>>> >>>> describe Foo do >>>> it "raises when x happens" do >>>> foo = Foo.new(Bar.new) >>>> expect { Foo.do_something_bad }.to raise_exception(FooException, >>>> "with this message") >>>> end >>>> >>>> it "does x when its bar raises" do >>>> bar = double >>>> foo = Foo.new(bar) >>>> bar.should_receive(:msg).and_raise(BarException, "with this message") >>>> end >>>> end >>>> >>>> Your suggestion makes these two APIs align better if the exception >>>> initializer accepts one argument and raise_exception gets a String. >>>> But raise_exception can also take a regex, and exception initializers >>>> can take more than one arg. Consider: InsufficientFunds.new(50, :USD). >>>> The way things are today, you might see these two near each other >>>> (hopefully not in the same example): >>>> >>>> expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/) >>>> source_account.should_receive(:withdraw).and_raise(InsufficientFunds.new >>>> 50, :USD) >>>> >>>> With what you propose it would be this: >>>> >>>> expect { transfer.execute }.to raise_exception(InsufficientFunds, /50 USD/) >>>> source_account.should_receive(:withdraw).and_raise(InsufficientFunds, >>>> 50, :USD) >>>> >>>> I think the way it is now tells a better story about what's really >>>> going on (i.e. that you're supplying an initialized object to >>>> and_raise) than the proposed change. But that's one opinion. >>>> >>>> Any others out there? >>> >>> Hi David, >>> >>> My main thinking was to make it consistent with the Kernel.raise. >>> >>> Like, in my production code, I have: >>> >>> raise Osaka::SystemCommandFailed, output_message >>> >>> so, it would make sense to the mock to work the same with: >>> >>> and_raise Osaka::SystemCommandFailed, "Fake output message" >>> >>> I figured it would be a relative minor change as it would add one extra parameter which could default to an empty string. >>> (as reference, see Kernel raise: http://www.ruby-doc.org/core-1.9.3/Kernel.html) >>> >>> I had not considered the consistency with and_raise_exception, but I just noticed that this was one of the cases where my default excepted behavior from RSpec was different from what the API wanted. Therefore, I had to dive in the RSpec doc to see how I could pass the message?. >>> >>> Bas >> >> Unfortunately, the Kernel#raise API also accepts a 3rd argument, which >> is an Array of caller information (the backtrace): >> http://www.ruby-doc.org/core-1.9.3/Kernel.html#method-i-raise. >> >> What that doc doesn't tell you is that the first arg can actually be >> an initialized exception: >> >> raise InsufficientFunds.new(49, :USD) >> >> I can't remember where I heard this but there was some advice from a >> respected software developer that said something like "APIs should be >> loose with what they accept and strict with what they return." Based >> on that advice, we should support your suggestion. It's not like if >> you use one API or the other you're going to get a different result. >> Beginning to lean in favor. >> >> More opinions? > > Then again ... > > raise InsufficientFunds, 50, :USD # raises ArgumentError > and_raise InsufficientFunds, 50, :USD # currently raises > ArgumentError, would not if we implement this suggestion > > So it depends on what we want to align with. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From apremdas at gmail.com Mon Aug 27 09:55:16 2012 From: apremdas at gmail.com (Andrew Premdas) Date: Mon, 27 Aug 2012 10:55:16 +0100 Subject: [rspec-users] error message for expect{}.should Message-ID: Hi all, Having not done any speccing for a few weeks I just spent ages puzzling over why the following code wasn't working it "should require a client" do expect{ }.should raise_error ArgumentError end and giving me a expected ArgumentError, got # From pafahim at gmail.com Fri Aug 31 14:14:24 2012 From: pafahim at gmail.com (Fahim Patel) Date: Fri, 31 Aug 2012 19:44:24 +0530 Subject: [rspec-users] Question on Cucumber and siienium Message-ID: Hi all,,,, I work on Rspec and now i see some more framework which is cucumber and silenium I have one question.. Which one is best for high level testing between cucumber and silinium? can we use both cucumber and silinium together ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Aug 31 14:42:47 2012 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 31 Aug 2012 10:42:47 -0400 Subject: [rspec-users] Question on Cucumber and siienium In-Reply-To: References: Message-ID: On Fri, Aug 31, 2012 at 10:14 AM, Fahim Patel wrote: > > > Hi all,,,, > > I work on Rspec and now i see some more framework which is cucumber and > silenium > I have one question.. > > Which one is best for high level testing between cucumber and silinium? > > can we use both cucumber and silinium together ? Selenium automates web browsers. Cucumber automates tests. Together, they let you automate tests in web browsers. If that's what you want to do, they work very well together, but I'd also look at Capybara, which provides a simpler interface to Selenium (via some other tools like selenium-web-driver). HTH, David