From lee_longmore at yahoo.co.uk Sun Mar 3 09:40:26 2013 From: lee_longmore at yahoo.co.uk (Lee Longmore) Date: Sun, 3 Mar 2013 09:40:26 +0000 (GMT) Subject: [rspec-users] Lee Longmore Message-ID: <1362303626.80014.YahooMailNeo@web133206.mail.ir2.yahoo.com> ydt mvz.vsd/http://www.maaelimpresiones.com/vwubayz/gxhlhmjm8hou8o.sfv?5vt79tkz29wawzjvixyrbt6phwrtsicupi cxsg.vsd/rsnajkb uzfktrn.vsd/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrew.pennebaker at gmail.com Fri Mar 8 14:38:42 2013 From: andrew.pennebaker at gmail.com (Andrew Pennebaker) Date: Fri, 8 Mar 2013 09:38:42 -0500 Subject: [rspec-users] rspec output not displaying properly in Windows Message-ID: rspec's coloration displays incorrectly in Windows. Example: C:\>rspec ... ?[36m # ./lib/github_teams/authentication.rb:82:in `github_api'?[0m ?[36m # ./lib/github_teams/authentication.rb:87:in `github'?[0m ?[36m # ./lib/github_teams/team.rb:10:in `initialize'?[0m ?[36m # ./spec/lib/github_teams/team_spec.rb:5:in `new'?[0m ?[36m # ./spec/lib/github_teams/team_spec.rb:5:in `block (2 levels) in '?[0m ?[36m # ./spec/lib/github_teams/team_spec.rb:15:in `block (3 levels) in '?[0m 17) GithubTeams::Team#initialize sets the organization to the default from the oauth file if not specified ?[31mFailure/Error:?[0m ?[31mt = Team.new("test")?[0m ?[31mTypeError?[0m: ?[31mbind argument must be an instance of GithubTeams::GithubEmployeeSync ?[0m ?[36m # ./lib/github_teams/authentication.rb:82:in `new'?[0m ?[36m # ./lib/github_teams/authentication.rb:82:in `github_api'?[0m ?[36m # ./lib/github_teams/authentication.rb:87:in `github'?[0m ?[36m # ./lib/github_teams/team.rb:10:in `initialize'?[0m ?[36m # ./spec/lib/github_teams/team_spec.rb:10:in `new'?[0m ?[36m # ./spec/lib/github_teams/team_spec.rb:10:in `block (3 levels) in '?[0m Finished in 0.01562 seconds The terminal characters appear to be written for Linux tty's. This wacky behavior is the same in Git Bash. Coloration *is* available in Windows; can we make the coloration more cross-platform compatible? Or could we at least turn off coloration in Windows environments? -- Cheers, Andrew Pennebaker www.yellosoft.us -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Sat Mar 9 23:20:15 2013 From: lists at ruby-forum.com (Fearless Fool) Date: Sun, 10 Mar 2013 00:20:15 +0100 Subject: [rspec-users] expecting one of two conditions Message-ID: <102feb41df0c214cdd508de89b94fe0e@ruby-forum.com> I'm expecting my_test to raise one error or another, but since I'm pulling data from a db, I don't know which error it will be. Is there a better way to write this? expect { my_test }.to raise_error { |error| error.should satisfy {|e| e.instance_of?(OneError) || e.instance_of?(OtherError) } } ? I'm not complaining, mind you -- I'm really impressed that RSpec lets me test for such specific pathology! I'm just wondering if there's another matcher that won't be quite so verbose. - ff -- Posted via http://www.ruby-forum.com/. From adam.sroka at gmail.com Sun Mar 10 00:24:40 2013 From: adam.sroka at gmail.com (Adam Sroka) Date: Sat, 9 Mar 2013 16:24:40 -0800 Subject: [rspec-users] expecting one of two conditions In-Reply-To: <102feb41df0c214cdd508de89b94fe0e@ruby-forum.com> References: <102feb41df0c214cdd508de89b94fe0e@ruby-forum.com> Message-ID: It depends on what you really mean: 1) If you care that it is either OneError or OtherError, then these are two separate scenarios and should be written as such. 2) If you don't care which one it is, then you probably just be less specific. Is there a common message they respond to that you could check for? 3) If you care which error you are getting, but you don't want to have to check for each one, then you might consider wrapping the error with something easier to inspect. There are probably a number of other good answers too, depending on which smell is bugging you the most. On Sat, Mar 9, 2013 at 3:20 PM, Fearless Fool wrote: > I'm expecting my_test to raise one error or another, but since I'm > pulling data from a db, I don't know which error it will be. Is there a > better way to write this? > > expect { my_test }.to raise_error { |error| > error.should satisfy {|e| > e.instance_of?(OneError) || e.instance_of?(OtherError) > } > } > > ? > > I'm not complaining, mind you -- I'm really impressed that RSpec lets me > test for such specific pathology! I'm just wondering if there's another > matcher that won't be quite so verbose. > > - ff > > -- > Posted via http://www.ruby-forum.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 rdpoor at gmail.com Sun Mar 10 02:04:23 2013 From: rdpoor at gmail.com (Robert Poor) Date: Sat, 9 Mar 2013 18:04:23 -0800 Subject: [rspec-users] expecting one of two conditions In-Reply-To: References: <102feb41df0c214cdd508de89b94fe0e@ruby-forum.com> Message-ID: On Sat, Mar 9, 2013 at 4:24 PM, Adam Sroka wrote: > It depends on what you really mean: > > 1) If you care that it is either OneError or OtherError, then these are > two separate scenarios and should be written as such. > > 2) If you don't care which one it is, then you probably just be less > specific. Is there a common message they respond to that you could check > for? > > 3) If you care which error you are getting, but you don't want to have to > check for each one, then you might consider wrapping the error with > something easier to inspect. > > There are probably a number of other good answers too, depending on which > smell is bugging you the most. > I don't care which error I'm getting, so suggestion 2) works. The errors I expect are within a specific module (UpdateOrInsert::), so I could simply check for that. Not sure how do to that short of parsing the class name string (e.g. error_class.name.split("::")), but I'm not sure that is less smelly than the code I already have. I'll contemplate 3), which could make life easer. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From samer.masry at gmail.com Sun Mar 10 02:08:35 2013 From: samer.masry at gmail.com (Samer Masry) Date: Sat, 9 Mar 2013 18:08:35 -0800 Subject: [rspec-users] expecting one of two conditions In-Reply-To: References: <102feb41df0c214cdd508de89b94fe0e@ruby-forum.com> Message-ID: It would be better to split that into two tests that test when each error is raised. On Mar 9, 2013, at 4:24 PM, Adam Sroka wrote: > It depends on what you really mean: > > 1) If you care that it is either OneError or OtherError, then these are two separate scenarios and should be written as such. > > 2) If you don't care which one it is, then you probably just be less specific. Is there a common message they respond to that you could check for? > > 3) If you care which error you are getting, but you don't want to have to check for each one, then you might consider wrapping the error with something easier to inspect. > > There are probably a number of other good answers too, depending on which smell is bugging you the most. > > > On Sat, Mar 9, 2013 at 3:20 PM, Fearless Fool wrote: > I'm expecting my_test to raise one error or another, but since I'm > pulling data from a db, I don't know which error it will be. Is there a > better way to write this? > > expect { my_test }.to raise_error { |error| > error.should satisfy {|e| > e.instance_of?(OneError) || e.instance_of?(OtherError) > } > } > > ? > > I'm not complaining, mind you -- I'm really impressed that RSpec lets me > test for such specific pathology! I'm just wondering if there's another > matcher that won't be quite so verbose. > > - ff > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From rdpoor at gmail.com Sun Mar 10 03:30:16 2013 From: rdpoor at gmail.com (Robert Poor) Date: Sat, 9 Mar 2013 19:30:16 -0800 Subject: [rspec-users] expecting one of two conditions In-Reply-To: References: <102feb41df0c214cdd508de89b94fe0e@ruby-forum.com> Message-ID: On Sat, Mar 9, 2013 at 6:08 PM, Samer Masry wrote: > It would be better to split that into two tests that test when each error > is raised. > Except that the specific error that I receive depends on the ordering of the data in the database, which isn't something I control. Hmm -- as I stare at that previous sentence, I detect a broader design smell rather than a specific code smell. I'll go think about this... -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Sun Mar 10 14:59:45 2013 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 10 Mar 2013 14:59:45 +0000 Subject: [rspec-users] expecting one of two conditions In-Reply-To: References: <102feb41df0c214cdd508de89b94fe0e@ruby-forum.com> Message-ID: <05356755-47FB-4B57-97D8-350EDD0263E3@mattwynne.net> On 10 Mar 2013, at 02:04, Robert Poor wrote: > On Sat, Mar 9, 2013 at 4:24 PM, Adam Sroka wrote: > It depends on what you really mean: > > 1) If you care that it is either OneError or OtherError, then these are two separate scenarios and should be written as such. > > 2) If you don't care which one it is, then you probably just be less specific. Is there a common message they respond to that you could check for? > > 3) If you care which error you are getting, but you don't want to have to check for each one, then you might consider wrapping the error with something easier to inspect. > > There are probably a number of other good answers too, depending on which smell is bugging you the most. > > I don't care which error I'm getting, so suggestion 2) works. The errors I expect are within a specific module (UpdateOrInsert::), so I could simply check for that. Not sure how do to that short of parsing the class name string (e.g. error_class.name.split("::")), but I'm not sure that is less smelly than the code I already have. > > I'll contemplate 3), which could make life easer. Thanks! Could you give both errors a common base class, then assert on that? cheers, Matt -- http://mattwynne.net || https://twitter.com/mattwynne || http://the-cucumber-book.com || http://bddkickstart.com || http://www.relishapp.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rdpoor at gmail.com Sun Mar 10 15:23:08 2013 From: rdpoor at gmail.com (Robert Poor) Date: Sun, 10 Mar 2013 08:23:08 -0700 Subject: [rspec-users] expecting one of two conditions In-Reply-To: <05356755-47FB-4B57-97D8-350EDD0263E3@mattwynne.net> References: <102feb41df0c214cdd508de89b94fe0e@ruby-forum.com> <05356755-47FB-4B57-97D8-350EDD0263E3@mattwynne.net> Message-ID: On Sun, Mar 10, 2013 at 7:59 AM, Matt Wynne wrote: > Could you give both errors a common base class, then assert on that? > That's the winning solution. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From deft.of.center at gmail.com Mon Mar 11 20:31:02 2013 From: deft.of.center at gmail.com (Dan Williams) Date: Mon, 11 Mar 2013 16:31:02 -0400 Subject: [rspec-users] Help solve distributed cucumber feature pain in 2 minutes or less Message-ID: Hey everybody, I have been beating my head on the wall when dealing with creating cucumber features in a distributed work environment. ?So, we decided to make a collaborative editor that solves this problem. Do have two minutes to help guide us? https://docs.google.com/forms/d/1tQbUHzDyUARHbbVvsy143p-OdE09VTJ5cyxDpNR8bK4/viewform Thanks for your input! -Dan -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Mon Mar 11 20:46:27 2013 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 11 Mar 2013 15:46:27 -0500 Subject: [rspec-users] Help solve distributed cucumber feature pain in 2 minutes or less In-Reply-To: References: Message-ID: You'll probably get more and better feedback from https://groups.google.com/forum/?fromgroups#!forum/cukes On Mon, Mar 11, 2013 at 3:31 PM, Dan Williams wrote: > Hey everybody, > > I have been beating my head on the wall when dealing with creating cucumber > features in a distributed work environment. So, we decided to make a > collaborative editor that solves this problem. Do have two minutes to help > guide us? > > https://docs.google.com/forms/d/1tQbUHzDyUARHbbVvsy143p-OdE09VTJ5cyxDpNR8bK4/viewform > > Thanks for your input! > > -Dan > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dmbrooking at gmail.com Sat Mar 16 12:56:52 2013 From: dmbrooking at gmail.com (Dan Brooking) Date: Sat, 16 Mar 2013 08:56:52 -0400 Subject: [rspec-users] stubbed methods are not returning what I've stubbed them to return Message-ID: I'm working on a small Sintra app and am having trouble getting my stub to return what I want it to. I've been searching and found quite a few with this question but no real answers. I also posted this to the sinatrarb google group in case it's an issue there. I have a helper method that returns a random string. I'm hoping it's something very simple I'm doing wrong def random_string(length) (0..length).map{ rand(36).to_s(36) }.join end I have my test written as follows: describe "#random_string" do it "returns a random string" do #Sinatra::Application.any_instance.stub(:random_string).and_return("abcdef") Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef') str = random_string(6) str.should == "abcdef" end end I have tried both lines shown in the code, and both times, the code runs. Yet my tests are still failing. It doesn't look like the stub is taking. My failure looks like: #random_string returns a random string Failure/Error: str.should == "abcdef" expected: "abcdef" got: "xcz0g7a" (using ==) Any ideas? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Mar 16 13:58:57 2013 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 16 Mar 2013 08:58:57 -0500 Subject: [rspec-users] stubbed methods are not returning what I've stubbed them to return In-Reply-To: References: Message-ID: On Sat, Mar 16, 2013 at 7:56 AM, Dan Brooking wrote: > I'm working on a small Sintra app and am having trouble getting my stub to > return what I want it to. I've been searching and found quite a few with > this question but no real answers. I also posted this to the sinatrarb > google group in case it's an issue there. > > I have a helper method that returns a random string. I'm hoping it's > something very simple I'm doing wrong > > def random_string(length) > (0..length).map{ rand(36).to_s(36) }.join > end > > > I have my test written as follows: > > describe "#random_string" do > it "returns a random string" do > #Sinatra::Application.any_instance.stub(:random_string).and_return("abcdef") > Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef') > str = random_string(6) Here ^^ random_string is being called in the context of the example, not the Sinatra::Application class or any of its instances. I don't know how Sinatra includes helper modules, but assuming that includes them in the Sinatra::Application object, then this should work: Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef') Sinatra::Application.random_string(6).should eq 'abcdef' HTH, David > str.should == "abcdef" > end > end > > > I have tried both lines shown in the code, and both times, the code runs. > Yet my tests are still failing. It doesn't look like the stub is taking. My > failure looks like: > > #random_string returns a random string > Failure/Error: str.should == "abcdef" > expected: "abcdef" > got: "xcz0g7a" (using ==) > > Any ideas? > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dmbrooking at gmail.com Sat Mar 16 14:05:09 2013 From: dmbrooking at gmail.com (Dan Brooking) Date: Sat, 16 Mar 2013 10:05:09 -0400 Subject: [rspec-users] stubbed methods are not returning what I've stubbed them to return In-Reply-To: References: Message-ID: OK, so I think based on this, I'm doing it right and it's a Sinatra issue. I did as you suggested and made a call to Sinatra::Application.random_string and now my error is "private method `random_string' called for Sinatra::Application:Class". So, like I said, looks to me like a Sintra specific issue where I need to reference it in a certain way. It's such a small method, I don't really need to test this but it's used in other modules so I wanted to isolate this to ensure I've got the stubbing down right. Thanks! On Sat, Mar 16, 2013 at 9:58 AM, David Chelimsky wrote: > On Sat, Mar 16, 2013 at 7:56 AM, Dan Brooking > wrote: > > I'm working on a small Sintra app and am having trouble getting my stub > to > > return what I want it to. I've been searching and found quite a few with > > this question but no real answers. I also posted this to the sinatrarb > > google group in case it's an issue there. > > > > I have a helper method that returns a random string. I'm hoping it's > > something very simple I'm doing wrong > > > > def random_string(length) > > (0..length).map{ rand(36).to_s(36) }.join > > end > > > > > > I have my test written as follows: > > > > describe "#random_string" do > > it "returns a random string" do > > > #Sinatra::Application.any_instance.stub(:random_string).and_return("abcdef") > > > Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef') > > str = random_string(6) > > Here ^^ random_string is being called in the context of the example, > not the Sinatra::Application class or any of its instances. I don't > know how Sinatra includes helper modules, but assuming that includes > them in the Sinatra::Application object, then this should work: > > > Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef') > Sinatra::Application.random_string(6).should eq 'abcdef' > > HTH, > David > > > str.should == "abcdef" > > end > > end > > > > > > I have tried both lines shown in the code, and both times, the code runs. > > Yet my tests are still failing. It doesn't look like the stub is > taking. My > > failure looks like: > > > > #random_string returns a random string > > Failure/Error: str.should == "abcdef" > > expected: "abcdef" > > got: "xcz0g7a" (using ==) > > > > Any ideas? > > > > _______________________________________________ > > 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 dmbrooking at gmail.com Sat Mar 16 14:11:26 2013 From: dmbrooking at gmail.com (Dan Brooking) Date: Sat, 16 Mar 2013 10:11:26 -0400 Subject: [rspec-users] stubbed methods are not returning what I've stubbed them to return In-Reply-To: References: Message-ID: I got it... I called it using instance_eval. def app Sinatra::Application end describe "#random_string" do it "returns a random string" do app.should_receive(:random_string).with(6).and_return('abcdef') str = app.instance_eval("random_string(6)") str.should == "abcdef" end end On Sat, Mar 16, 2013 at 10:05 AM, Dan Brooking wrote: > OK, so I think based on this, I'm doing it right and it's a Sinatra issue. > I did as you suggested and made a call to > Sinatra::Application.random_string and now my error is "private method > `random_string' called for Sinatra::Application:Class". > > So, like I said, looks to me like a Sintra specific issue where I need to > reference it in a certain way. It's such a small method, I don't really > need to test this but it's used in other modules so I wanted to isolate > this to ensure I've got the stubbing down right. > > Thanks! > > > On Sat, Mar 16, 2013 at 9:58 AM, David Chelimsky wrote: > >> On Sat, Mar 16, 2013 at 7:56 AM, Dan Brooking >> wrote: >> > I'm working on a small Sintra app and am having trouble getting my stub >> to >> > return what I want it to. I've been searching and found quite a few >> with >> > this question but no real answers. I also posted this to the sinatrarb >> > google group in case it's an issue there. >> > >> > I have a helper method that returns a random string. I'm hoping it's >> > something very simple I'm doing wrong >> > >> > def random_string(length) >> > (0..length).map{ rand(36).to_s(36) }.join >> > end >> > >> > >> > I have my test written as follows: >> > >> > describe "#random_string" do >> > it "returns a random string" do >> > >> #Sinatra::Application.any_instance.stub(:random_string).and_return("abcdef") >> > >> Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef') >> > str = random_string(6) >> >> Here ^^ random_string is being called in the context of the example, >> not the Sinatra::Application class or any of its instances. I don't >> know how Sinatra includes helper modules, but assuming that includes >> them in the Sinatra::Application object, then this should work: >> >> >> Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef') >> Sinatra::Application.random_string(6).should eq 'abcdef' >> >> HTH, >> David >> >> > str.should == "abcdef" >> > end >> > end >> > >> > >> > I have tried both lines shown in the code, and both times, the code >> runs. >> > Yet my tests are still failing. It doesn't look like the stub is >> taking. My >> > failure looks like: >> > >> > #random_string returns a random string >> > Failure/Error: str.should == "abcdef" >> > expected: "abcdef" >> > got: "xcz0g7a" (using ==) >> > >> > Any ideas? >> > >> > _______________________________________________ >> > 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 dchelimsky at gmail.com Sat Mar 16 14:28:03 2013 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 16 Mar 2013 09:28:03 -0500 Subject: [rspec-users] stubbed methods are not returning what I've stubbed them to return In-Reply-To: References: Message-ID: On Sat, Mar 16, 2013 at 9:11 AM, Dan Brooking wrote: > I got it... > > I called it using instance_eval. > > def app > Sinatra::Application > end > > describe "#random_string" do > it "returns a random string" do > app.should_receive(:random_string).with(6).and_return('abcdef') > str = app.instance_eval("random_string(6)") > str.should == "abcdef" > end > end It might pass, but this example tells you nothing about how the random_string method should work. What is it that you're actually wanting to specify here? > > > On Sat, Mar 16, 2013 at 10:05 AM, Dan Brooking wrote: >> >> OK, so I think based on this, I'm doing it right and it's a Sinatra issue. >> I did as you suggested and made a call to Sinatra::Application.random_string >> and now my error is "private method `random_string' called for >> Sinatra::Application:Class". >> >> So, like I said, looks to me like a Sintra specific issue where I need to >> reference it in a certain way. It's such a small method, I don't really >> need to test this but it's used in other modules so I wanted to isolate this >> to ensure I've got the stubbing down right. >> >> Thanks! >> >> >> On Sat, Mar 16, 2013 at 9:58 AM, David Chelimsky >> wrote: >>> >>> On Sat, Mar 16, 2013 at 7:56 AM, Dan Brooking >>> wrote: >>> > I'm working on a small Sintra app and am having trouble getting my stub >>> > to >>> > return what I want it to. I've been searching and found quite a few >>> > with >>> > this question but no real answers. I also posted this to the sinatrarb >>> > google group in case it's an issue there. >>> > >>> > I have a helper method that returns a random string. I'm hoping it's >>> > something very simple I'm doing wrong >>> > >>> > def random_string(length) >>> > (0..length).map{ rand(36).to_s(36) }.join >>> > end >>> > >>> > >>> > I have my test written as follows: >>> > >>> > describe "#random_string" do >>> > it "returns a random string" do >>> > >>> > #Sinatra::Application.any_instance.stub(:random_string).and_return("abcdef") >>> > >>> > Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef') >>> > str = random_string(6) >>> >>> Here ^^ random_string is being called in the context of the example, >>> not the Sinatra::Application class or any of its instances. I don't >>> know how Sinatra includes helper modules, but assuming that includes >>> them in the Sinatra::Application object, then this should work: >>> >>> >>> Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef') >>> Sinatra::Application.random_string(6).should eq 'abcdef' >>> >>> HTH, >>> David >>> >>> > str.should == "abcdef" >>> > end >>> > end >>> > >>> > >>> > I have tried both lines shown in the code, and both times, the code >>> > runs. >>> > Yet my tests are still failing. It doesn't look like the stub is >>> > taking. My >>> > failure looks like: >>> > >>> > #random_string returns a random string >>> > Failure/Error: str.should == "abcdef" >>> > expected: "abcdef" >>> > got: "xcz0g7a" (using ==) >>> > >>> > Any ideas? >>> > >>> > _______________________________________________ >>> > rspec-users mailing list >>> > rspec-users at rubyforge.org >>> > http://rubyforge.org/mailman/listinfo/rspec-users >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dmbrooking at gmail.com Sat Mar 16 14:42:29 2013 From: dmbrooking at gmail.com (Dan Brooking) Date: Sat, 16 Mar 2013 10:42:29 -0400 Subject: [rspec-users] stubbed methods are not returning what I've stubbed them to return In-Reply-To: References: Message-ID: Yes I realize that :) I actually need to stub this method out in some of my other methods... Since I'm still figuring out how stubbing works, I wanted to strip it down to it's most basic. So in essence, I guess I am testing my stub with this code. So now I know that if I throw this stub in my other tests, I should be good to go. On Sat, Mar 16, 2013 at 10:28 AM, David Chelimsky wrote: > On Sat, Mar 16, 2013 at 9:11 AM, Dan Brooking > wrote: > > I got it... > > > > I called it using instance_eval. > > > > def app > > Sinatra::Application > > end > > > > describe "#random_string" do > > it "returns a random string" do > > app.should_receive(:random_string).with(6).and_return('abcdef') > > str = app.instance_eval("random_string(6)") > > str.should == "abcdef" > > end > > end > > It might pass, but this example tells you nothing about how the > random_string method should work. What is it that you're actually > wanting to specify here? > > > > > > > On Sat, Mar 16, 2013 at 10:05 AM, Dan Brooking > wrote: > >> > >> OK, so I think based on this, I'm doing it right and it's a Sinatra > issue. > >> I did as you suggested and made a call to > Sinatra::Application.random_string > >> and now my error is "private method `random_string' called for > >> Sinatra::Application:Class". > >> > >> So, like I said, looks to me like a Sintra specific issue where I need > to > >> reference it in a certain way. It's such a small method, I don't really > >> need to test this but it's used in other modules so I wanted to isolate > this > >> to ensure I've got the stubbing down right. > >> > >> Thanks! > >> > >> > >> On Sat, Mar 16, 2013 at 9:58 AM, David Chelimsky > >> wrote: > >>> > >>> On Sat, Mar 16, 2013 at 7:56 AM, Dan Brooking > >>> wrote: > >>> > I'm working on a small Sintra app and am having trouble getting my > stub > >>> > to > >>> > return what I want it to. I've been searching and found quite a few > >>> > with > >>> > this question but no real answers. I also posted this to the > sinatrarb > >>> > google group in case it's an issue there. > >>> > > >>> > I have a helper method that returns a random string. I'm hoping it's > >>> > something very simple I'm doing wrong > >>> > > >>> > def random_string(length) > >>> > (0..length).map{ rand(36).to_s(36) }.join > >>> > end > >>> > > >>> > > >>> > I have my test written as follows: > >>> > > >>> > describe "#random_string" do > >>> > it "returns a random string" do > >>> > > >>> > > #Sinatra::Application.any_instance.stub(:random_string).and_return("abcdef") > >>> > > >>> > > Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef') > >>> > str = random_string(6) > >>> > >>> Here ^^ random_string is being called in the context of the example, > >>> not the Sinatra::Application class or any of its instances. I don't > >>> know how Sinatra includes helper modules, but assuming that includes > >>> them in the Sinatra::Application object, then this should work: > >>> > >>> > >>> > Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef') > >>> Sinatra::Application.random_string(6).should eq 'abcdef' > >>> > >>> HTH, > >>> David > >>> > >>> > str.should == "abcdef" > >>> > end > >>> > end > >>> > > >>> > > >>> > I have tried both lines shown in the code, and both times, the code > >>> > runs. > >>> > Yet my tests are still failing. It doesn't look like the stub is > >>> > taking. My > >>> > failure looks like: > >>> > > >>> > #random_string returns a random string > >>> > Failure/Error: str.should == "abcdef" > >>> > expected: "abcdef" > >>> > got: "xcz0g7a" (using ==) > >>> > > >>> > Any ideas? > >>> > > >>> > _______________________________________________ > >>> > rspec-users mailing list > >>> > rspec-users at rubyforge.org > >>> > http://rubyforge.org/mailman/listinfo/rspec-users > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >> > >> > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ivan.neverov at gmail.com Tue Mar 19 14:20:48 2013 From: ivan.neverov at gmail.com (=?KOI8-R?B?6dfBziDuxdfF0s/X?=) Date: Tue, 19 Mar 2013 16:20:48 +0200 Subject: [rspec-users] Assign default tag Message-ID: Hi all Could somebody tell me, is it possible to assign some tag=>value to all examples in directory? Like I want to mark all tests in spec/unit as :type=>'shallow'. And have some tests in other directory also with type shallow (assigned in describe) And then filter them with -t type:shallow Thanks Ivan -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Mar 19 15:41:28 2013 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 19 Mar 2013 08:41:28 -0700 Subject: [rspec-users] Assign default tag In-Reply-To: References: Message-ID: On Tue, Mar 19, 2013 at 7:20 AM, ???? ??????? wrote: > Hi all > Could somebody tell me, is it possible to assign some tag=>value to all > examples in directory? > > Like I want to mark all tests in spec/unit as :type=>'shallow'. And have > some tests in other directory also with type shallow (assigned in describe) > And then filter them with -t type:shallow > > > Thanks > Ivan Unfortunately, there's nothing built in to support this. I'd recommend you submit a feature request to http://github.com/rspec/rspec-core/issues. Cheers, David From pedzsan at gmail.com Tue Mar 19 16:52:29 2013 From: pedzsan at gmail.com (Perry Smith) Date: Tue, 19 Mar 2013 11:52:29 -0500 Subject: [rspec-users] Assign default tag In-Reply-To: References: Message-ID: <8CBB9694-D1F5-431D-8C03-A75C88F5E188@gmail.com> On Mar 19, 2013, at 10:41 AM, David Chelimsky wrote: > On Tue, Mar 19, 2013 at 7:20 AM, ???? ??????? wrote: >> Hi all >> Could somebody tell me, is it possible to assign some tag=>value to all >> examples in directory? >> >> Like I want to mark all tests in spec/unit as :type=>'shallow'. And have >> some tests in other directory also with type shallow (assigned in describe) >> And then filter them with -t type:shallow >> >> >> Thanks >> Ivan > > Unfortunately, there's nothing built in to support this. I'd recommend > you submit a feature request to > http://github.com/rspec/rspec-core/issues. I do this: config.include RSpec::Rails::ViewExampleGroup, type: :presenter, example_group: { file_path: config.escaped_path(%w[spec presenters]) } and it appears to work for me. But David would know better than I. Am I fooling myself somehow? Or did I misunderstand the question? Thanks, Perry From dchelimsky at gmail.com Tue Mar 19 18:26:29 2013 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 19 Mar 2013 11:26:29 -0700 Subject: [rspec-users] Assign default tag In-Reply-To: <8CBB9694-D1F5-431D-8C03-A75C88F5E188@gmail.com> References: <8CBB9694-D1F5-431D-8C03-A75C88F5E188@gmail.com> Message-ID: On Tue, Mar 19, 2013 at 9:52 AM, Perry Smith wrote: > > On Mar 19, 2013, at 10:41 AM, David Chelimsky wrote: > >> On Tue, Mar 19, 2013 at 7:20 AM, ???? ??????? wrote: >>> Hi all >>> Could somebody tell me, is it possible to assign some tag=>value to all >>> examples in directory? >>> >>> Like I want to mark all tests in spec/unit as :type=>'shallow'. And have >>> some tests in other directory also with type shallow (assigned in describe) >>> And then filter them with -t type:shallow >>> >>> >>> Thanks >>> Ivan >> >> Unfortunately, there's nothing built in to support this. I'd recommend >> you submit a feature request to >> http://github.com/rspec/rspec-core/issues. > > I do this: > > config.include RSpec::Rails::ViewExampleGroup, type: :presenter, example_group: { > file_path: config.escaped_path(%w[spec presenters]) > } > > and it appears to work for me. But David would know better than I. > > Am I fooling myself somehow? Or did I misunderstand the question? Actually that does point to a solution. The trick is the OP wants to add a tag to the groups in that directory so that those examples can be filtered, which means it has to be added _before_ filtering happens. I hadn't thought there was a good way to do this, but your example reminded me there is, sort of. The caveat is that this is a bit magical and relies on a somewhat buried API that may or may not be supported in the long term. That said, for now you _can_ do this: module ShallowExampleGroup def self.included(host) host.metadata[:type] = 'shallow' end end RSpec.configure do |config| config.include ShallowExampleGroup, example_group: { file_path: config.escaped_path(%w[spec unit]) } end HTH, David From xnull at opensuse.org Wed Mar 20 14:48:24 2013 From: xnull at opensuse.org (Yury Tsarev) Date: Wed, 20 Mar 2013 15:48:24 +0100 Subject: [rspec-users] Passing variables to custom formatters Message-ID: Guys, I observing old mail http://rubyforge.org/pipermail/rspec-users/2010-March/016638.html and from it I understood that options hash is more side effect then proper way for passing variable from spec to formatter. So is there any official and supported way for doing that ? Thanks a lot in advance, Yury From lists at ruby-forum.com Wed Mar 20 17:00:12 2013 From: lists at ruby-forum.com (Ezequiel Delpero) Date: Wed, 20 Mar 2013 18:00:12 +0100 Subject: [rspec-users] Rspec + Devise + BaseController Message-ID: <625dd258c4c5e6589b9ae951ad8361e0@ruby-forum.com> Hello there, I'm creating a base controller for the admin section of a project. All controllers whitin the admin section will inherit from it. ##################################################### #app/controllers/admins/base_controller.rb class Admins::BaseController < ApplicationController layout "admin_cms" before_filter :authenticate_admin! end ##################################################### #spec/controllers/admins/base_controller_spec.rb require 'spec_helper' describe Admins::BaseController do controller do def index end end describe "before_filter#authenticate_admin!" do before(:each) do @admin = FactoryGirl.create(:admin) @request.env["devise.mapping"] = Devise.mappings[:admin] end context "when admin is not logged in" do it "redirect admin to sign_in path" do get :index response.should redirect_to new_admin_session_path end end end end ##################################################### I've already inclueded Devise::TestHelpers on my spec_helper.rb and I'm getting this error when running this spec: ##################################################### Admins::BaseController before_filter#authenticate_admin! when admin is not logged in redirect admin to sign_in path (FAILED - 1) Failures: 1) Admins::BaseController before_filter#authenticate_admin! when admin is not logged in redirect admin to sign_in path Failure/Error: get :index ActionView::MissingTemplate: Missing template anonymous/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "#" # ./spec/controllers/admins/base_controller_spec.rb:17:in `block (4 levels) in ' Finished in 0.17124 seconds 1 example, 1 failure Failed examples: rspec ./spec/controllers/admins/base_controller_spec.rb:16 # Admins::BaseController before_filter#authenticate_admin! when admin is not logged in redirect admin to sign_in path ##################################################### I changed my spec to this: ##################################################### require 'spec_helper' describe Admins::BaseController do controller do def index render nothing: true end end describe "before_filter#authenticate_admin!" do context "when admin is not logged in" do it "redirect admin to sign_in path" do get :index response.should redirect_to new_admin_session_path end end end end ##################################################### and now I'm getting this error: ##################################################### Failures: 1) Admins::BaseController before_filter#authenticate_admin! when admin is not logged in redirect admin to sign_in path Failure/Error: response.should redirect_to new_admin_session_path Expected response to be a <:redirect>, but was <200> So, for some reason it's not entering in the authenticate_admin! before filter. I'm kind of lost. Thanks again. ##################################################### I'm using Rails 3.2.13, Ruby 2.0.0, Rspec-rails 2.13.0 and Devise 2.2.3. I really appreacite if someone could help me out with this. Thanks in advance. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Mar 20 18:21:12 2013 From: lists at ruby-forum.com (Ezequiel Delpero) Date: Wed, 20 Mar 2013 19:21:12 +0100 Subject: [rspec-users] Rspec + Devise + BaseController In-Reply-To: <625dd258c4c5e6589b9ae951ad8361e0@ruby-forum.com> References: <625dd258c4c5e6589b9ae951ad8361e0@ruby-forum.com> Message-ID: Finally I could solve the problem. The problem was on the definition of the anonymous controller on the spec: instead of: controller do def index end end I used: controller(Admins::Base) do def index end end You need to specify always the anonymous controller you're testing unless is ApplicationController the one you're trying to test. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Mar 20 19:50:49 2013 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 20 Mar 2013 12:50:49 -0700 Subject: [rspec-users] Rspec + Devise + BaseController In-Reply-To: References: <625dd258c4c5e6589b9ae951ad8361e0@ruby-forum.com> Message-ID: On Wed, Mar 20, 2013 at 11:21 AM, Ezequiel Delpero wrote: > Finally I could solve the problem. The problem was on the definition of > the anonymous controller on the spec: > > instead of: > > controller do > def index > end > end > > I used: > > controller(Admins::Base) do > def index > end > end > > You need to specify always the anonymous controller you're testing > unless is ApplicationController the one you're trying to test. FYI - docs: http://rubydoc.info/gems/rspec-rails/RSpec/Rails/ControllerExampleGroup/ClassMethods#controller-instance_method From lists at ruby-forum.com Wed Mar 27 20:06:41 2013 From: lists at ruby-forum.com (Ezequiel Delpero) Date: Wed, 27 Mar 2013 21:06:41 +0100 Subject: [rspec-users] Rspec + include Rails.application.routes.url_helpers Message-ID: <5431836095e828afdd0efc9d89fe7a4e@ruby-forum.com> Hello there, I'm having some issues trying to test a custom helper. And I been trying to figure this out without luck. Please, see attachs for more information. Thanks in advance. Attachments: http://www.ruby-forum.com/attachment/8268/errors.txt http://www.ruby-forum.com/attachment/8269/spec_helper.rb http://www.ruby-forum.com/attachment/8270/products_helper.rb http://www.ruby-forum.com/attachment/8271/products_helper_spec.rb -- Posted via http://www.ruby-forum.com/. From ods94065 at gmail.com Thu Mar 28 08:15:34 2013 From: ods94065 at gmail.com (Owen Smith) Date: Thu, 28 Mar 2013 01:15:34 -0700 Subject: [rspec-users] Dude, where's my full description? (bug report & suggested fix in rspec-core 2.13.1) Message-ID: Greetings, I'm writing to report an issue I stumbled upon while trying to adjust to the new (for me) world of implicit-subject expectation writing. Consider this rather silly test case: describe "something" do context "in context" do subject { "an object" } it { should == "an object" } end end When I run rspec with `--format documentation`, I see the nifty documentation generated by the matcher itself: something in context should == "an object" However, this is what I see when I run with `--format json` (modulo pretty printing): { "summary_line": "1 example, 0 failures", "summary": { "example_count": 1, "duration": 0.000344, "failure_count": 0, "pending_count":0 }, "examples": [ { "status": "passed", "description": "should == \"an object\"", "full_description": "something in context ", "line_number": 4, "file_path": "./spec/test_spec.rb" } ] } Note that the full_description is missing the matcher documentation. And with ci_reporter 1.8.4, this comes out as a sorry hash indeed, because _only_ the full descriptions are reported to CI. Here's the trimmed XML output. SPEC-something.xml: ... SPEC-something-in-context.xml: ... Now imagine you had 15-20 test cases whose names were all "something in context". Ugh. What I want to see, of course, is the generated matcher documentation being added to the end of the full description of the example, and showing up in my CI reports. ---- I couldn't find a report of this issue already, but please stop here and wave me off if you've already got a handle on this. Otherwise, here's my analysis and suggested fix. ---- At first I was digging through ci_reporter to see if there was something wrong on that end, but you can see that the built-in JSON reporter is running into the same problem: full_description is simply missing important stuff. The problem as I see it starts from the fact that the generated description from the matcher gets stored into metadata[:description] after the example is run, but metadata[:full_description] never gets updated. This results in the following metadata hash for our example: { :caller => ..., :description => "should == \"an object\"", :description_args = [], :example_group => ..., :example_group_block => #, :execution_result => ..., } No :full_description entry in sight. This means that, when someone calls `example.description` after the test is run, they get the generated matcher description, because the implementation of Example#description sees that `metadata[:description]` is set. But when someone calls `example.full_description` or `example.metadata[:full_description]`, both fall through to this implementation, from the ExampleMetadata module: def full_description build_description_from(self[:example_group][:full_description], *self[:description_args]) end Hmm... I see the parent's full description, the empty list of description_args... but where's the example's description itself? We're not taking into account that in this case the description didn't come from the args at all, it came from the generated matcher. That, I believe, is the root cause. I think the best behavior is to respect the description args above all, but _only if they're given_. Failing that, we should use the generated description if it's available, and then we do I dunno what (stick with the above, or go back to "example at ..."). Going with this behavior would fix my issue. So, my suggested fix is to have #full_description take metadata[:description] into account: def full_description + if self[:description] + build_description_from(self[:example_group][:full_description], self[:description]) + else build_description_from(self[:example_group][:full_description], *self[:description_args]) + end end It's not the cleanest patch, because it appears on the surface to be undermining the behavior I described above, prioritizing whatever it finds in self[:description], generated or otherwise, above self[:description_args]. However, I think it works, and I'm not sure how better to express it. If metadata[:description] is set, I think it could contain either the contents of metadata[:description_args] or the generated matcher description (any other possibilities?). And it looks to me from Example#assign_generated_description that if metadata[:description] is already filled out (from the description args), the previous contents will win. So really, I think what you're going to see is: if we fall through to the else, self[:description_args] is going to be empty. But I have yet to prove that. Questions notwithstanding, I've tried a monkey patch with this and it does indeed fix my issue. I can work it into a full test case and submission if you want, but as I'm new to the group I'll need some guidance. Thanks for reviewing, and for a fun little test framework! -- Owen -------------- next part -------------- An HTML attachment was scrubbed... URL: