From lists at ruby-forum.com Thu Feb 7 08:09:28 2013 From: lists at ruby-forum.com (Doug Livesey) Date: Thu, 07 Feb 2013 09:09:28 +0100 Subject: [rspec-users] undefined method `run_all' for []:Array In-Reply-To: References: Message-ID: <46c42477428776122642c22c9d5e2b51@ruby-forum.com> David Chelimsky wrote in post #971870: > On Sun, Jan 2, 2011 at 5:42 AM, Kristian Mandrup > wrote: >> I'm using the latest ruby 1.9.3-head and recently whenever I run rspec >> (2.2+) I get the following error: >> >> I have seen others have run into this issue, but to resolve it just >> rolled back to a previous version of rspec or it there a better way? > > Better is to wait to upgrade to the next version of rspec that fixes the > bug: > > https://github.com/rspec/rspec-core/issues/closed#issue/258 > > To be released as part of rspec-core-2.4 within the next day or so. > > Cheers, > David I guess this isn't fixed? I'm having the same error, and the version of rspec that installs is 2.0.1 Unless I'm missing something obvious? -- Posted via http://www.ruby-forum.com/. From gaurav.kapahi at gmail.com Thu Feb 7 11:42:00 2013 From: gaurav.kapahi at gmail.com (gaurav kapahi) Date: Thu, 7 Feb 2013 17:12:00 +0530 Subject: [rspec-users] hi Message-ID: Hi Can u send me the automated test script using rspec for sucessfully login in to gmail account -- gaurav kapahi -------------- next part -------------- An HTML attachment was scrubbed... URL: From alindeman at gmail.com Thu Feb 7 13:22:49 2013 From: alindeman at gmail.com (Andy Lindeman) Date: Thu, 7 Feb 2013 08:22:49 -0500 Subject: [rspec-users] undefined method `run_all' for []:Array In-Reply-To: <46c42477428776122642c22c9d5e2b51@ruby-forum.com> References: <46c42477428776122642c22c9d5e2b51@ruby-forum.com> Message-ID: Yes. It should be fixed. If you upgrade and still get the error, let us know! On Thursday, February 7, 2013, Doug Livesey wrote: > David Chelimsky wrote in post #971870: > > On Sun, Jan 2, 2011 at 5:42 AM, Kristian Mandrup > > > > wrote: > >> I'm using the latest ruby 1.9.3-head and recently whenever I run rspec > >> (2.2+) I get the following error: > >> > >> I have seen others have run into this issue, but to resolve it just > >> rolled back to a previous version of rspec or it there a better way? > > > > Better is to wait to upgrade to the next version of rspec that fixes the > > bug: > > > > https://github.com/rspec/rspec-core/issues/closed#issue/258 > > > > To be released as part of rspec-core-2.4 within the next day or so. > > > > Cheers, > > David > > I guess this isn't fixed? I'm having the same error, and the version of > rspec that installs is 2.0.1 > Unless I'm missing something obvious? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Sent from a mobile device. Please excuse the brevity and top reply. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ash.moran at patchspace.co.uk Thu Feb 7 18:26:33 2013 From: ash.moran at patchspace.co.uk (Ash Moran) Date: Thu, 7 Feb 2013 18:26:33 +0000 Subject: [rspec-users] Building higher-level DSLs Message-ID: Hi Someone on another mailing list I'm on recently posted asking for people's thoughts on test naming practices, and writing my reply made me think about some of the techniques I use to improve naming and remove duplication in my own spec files. The most worked-through example I have is the contract test for my solutions to the Tennis Kata[1]. (I'm not implying this is the best way to tackle the Tennis Kata.) Like with everything other spec suite, I started out using plain describe/context/it type language[2], which contains a lot of duplication: describe "scoring" do before(:each) { tennis.start_game } context "with no advantages" do context "A" do before(:each) { tennis.point_to_player_a } specify { expect(@score).to be == "15-0" } context "A" do before(:each) { tennis.point_to_player_a } specify { expect(@score).to be == "30-0" } end context "B" do before(:each) { tennis.point_to_player_b } specify { expect(@score).to be == "15-15" } And it so goes on for quite a bit longer in the same style. The first step is to factor out the duplication into context helpers, which leaves code like this: game_started do score_is_now "0-0" context "with no advantages" do point_to_player :a do score_is_now "15-0" point_to_player :a do score_is_now "30-0" end The problem now is that the meaning of the specification is now hidden in the implementation of the helpers, in this case it was in spec_helper[3]. This gives very poorly composed methods with mixed levels of abstraction. So the final step is to parameterise the spec DSL with blocks of code from the specs itself, allowing you to write: specification_dsl :tennis do for_context :game_not_started do nothing end for_context :game_started do tennis.start_game end for_context :point_to_player do |player| # Heh, just noticed writing this email that I could be doing # tennis.send(:"point_to_player_#{player}") here, hey ho player == :a ? tennis.point_to_player_a : tennis.point_to_player_b end for_context :deuce do 3.times do tennis.point_to_player_a tennis.point_to_player_b end end to_expect :score_is_now do |expected_score| expect(@scores.last).to be == expected_score end This has finally put the spec and its definition back together[4], with the DSL definition and its voodoo metaprogramming hidden away in spec_helper[5]. Unfortunately there's a problem with this implementation, which is that it fools RSpec into thinking expectation failures are all coming from spec_helper.rb, which makes for rather useless error messages. I haven't investigated this. Anyway, the point of explaining this example is to ask for people's opinions myself. A few obvious questions are: * What sort of DSL-building have you tried/seen? * Is this worth the effort over e.g. helper modules and custom matchers? (E.g. is the terseness worth the indirection?) * Is this possible in a simpler way with existing context tools in RSpec? * If not, is it worth trying to make this DSL definition reusable? * Are the situations where this is useful inherently best tackled another way? I'm interested in any opinions though, especially if you have a valid reason why this is a bad idea / approach. I've sat on it long enough I'm clearly not going to have any more insights on my own any time soon. Cheers Ash [1] http://codingdojo.org/cgi-bin/wiki.pl?KataTennis [2] https://github.com/ashmoran/tennis_kata/blob/ff46b7e502337988940ef9ed881c934a04c53766/spec/tennis_spec.rb [3] https://github.com/ashmoran/tennis_kata/blob/a159bac3c3d6180c6f1b83770e6cd678fa750b33/spec/spec_helper.rb [4] https://github.com/ashmoran/tennis_kata/blob/master/spec/tennis_contract.rb [5] https://github.com/ashmoran/tennis_kata/blob/master/spec/spec_helper.rb -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashmoran From samwgoldman at gmail.com Thu Feb 7 23:32:57 2013 From: samwgoldman at gmail.com (Sam Goldman) Date: Thu, 7 Feb 2013 13:32:57 -1000 Subject: [rspec-users] Building higher-level DSLs In-Reply-To: References: Message-ID: I'm not sure if this is what you are looking for, but I do have some experience with writing DSLs on top of RSpec. I made a project that lets you write tests for HTTP APIs in a bit more of a straightforward manner[1]. This isn't quite the level of DSL-ness that it seems you are going for?i.e., the specs using this library still very much look like RSpec. In the context of this project, I think that it was worth it. I very much enjoy writing specs in the style afforded by this DSL. I think the tradeoff is about test noise. Let me define noise as details that are only relevant at a lower level of abstraction from the spec's level of abstraction. Ideally, your DSL will only hide noise. If your DSL hides signal, then consumers of your dialect will need to understand the internals. That said, I think it's a bad idea to start with a DSL. Write your tests directly, then once you have a good number of tests, ask yourself if a non-leaky abstraction exists would let you convey your specs at a higher level. You might find that this leads to a new domain concept for your production code. Alternatively it might be better to augment your tests with a little DSL. Sorry if that's a little too philosophical :P Sam 1. https://github.com/smartlogic/http_spec On Thu, Feb 7, 2013 at 8:26 AM, Ash Moran wrote: > Hi > > Someone on another mailing list I'm on recently posted asking for people's > thoughts on test naming practices, and writing my reply made me think about > some of the techniques I use to improve naming and remove duplication in my > own spec files. > > The most worked-through example I have is the contract test for my > solutions to the Tennis Kata[1]. (I'm not implying this is the best way to > tackle the Tennis Kata.) Like with everything other spec suite, I started > out using plain describe/context/it type language[2], which contains a lot > of duplication: > > describe "scoring" do > before(:each) { tennis.start_game } > > context "with no advantages" do > context "A" do > before(:each) { tennis.point_to_player_a } > specify { expect(@score).to be == "15-0" } > > context "A" do > before(:each) { tennis.point_to_player_a } > specify { expect(@score).to be == "30-0" } > end > > context "B" do > before(:each) { tennis.point_to_player_b } > specify { expect(@score).to be == "15-15" } > > And it so goes on for quite a bit longer in the same style. The first step > is to factor out the duplication into context helpers, which leaves code > like this: > > game_started do > score_is_now "0-0" > > context "with no advantages" do > point_to_player :a do > score_is_now "15-0" > > point_to_player :a do > score_is_now "30-0" > end > > The problem now is that the meaning of the specification is now hidden in > the implementation of the helpers, in this case it was in spec_helper[3]. > This gives very poorly composed methods with mixed levels of abstraction. > So the final step is to parameterise the spec DSL with blocks of code from > the specs itself, allowing you to write: > > specification_dsl :tennis do > for_context :game_not_started do > nothing > end > > for_context :game_started do > tennis.start_game > end > > for_context :point_to_player do |player| > # Heh, just noticed writing this email that I could be doing > # tennis.send(:"point_to_player_#{player}") here, hey ho > player == :a ? tennis.point_to_player_a : tennis.point_to_player_b > end > > for_context :deuce do > 3.times do > tennis.point_to_player_a > tennis.point_to_player_b > end > end > > to_expect :score_is_now do |expected_score| > expect(@scores.last).to be == expected_score > end > > This has finally put the spec and its definition back together[4], with > the DSL definition and its voodoo metaprogramming hidden away in > spec_helper[5]. > > Unfortunately there's a problem with this implementation, which is that it > fools RSpec into thinking expectation failures are all coming from > spec_helper.rb, which makes for rather useless error messages. I haven't > investigated this. > > Anyway, the point of explaining this example is to ask for people's > opinions myself. A few obvious questions are: > > * What sort of DSL-building have you tried/seen? > * Is this worth the effort over e.g. helper modules and custom matchers? > (E.g. is the terseness worth the indirection?) > * Is this possible in a simpler way with existing context tools in RSpec? > * If not, is it worth trying to make this DSL definition reusable? > * Are the situations where this is useful inherently best tackled another > way? > > I'm interested in any opinions though, especially if you have a valid > reason why this is a bad idea / approach. I've sat on it long enough I'm > clearly not going to have any more insights on my own any time soon. > > Cheers > Ash > > [1] http://codingdojo.org/cgi-bin/wiki.pl?KataTennis > [2] > https://github.com/ashmoran/tennis_kata/blob/ff46b7e502337988940ef9ed881c934a04c53766/spec/tennis_spec.rb > [3] > https://github.com/ashmoran/tennis_kata/blob/a159bac3c3d6180c6f1b83770e6cd678fa750b33/spec/spec_helper.rb > [4] > https://github.com/ashmoran/tennis_kata/blob/master/spec/tennis_contract.rb > [5] > https://github.com/ashmoran/tennis_kata/blob/master/spec/spec_helper.rb > > -- > http://www.patchspace.co.uk/ > http://www.linkedin.com/in/ashmoran > > _______________________________________________ > 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 reality.tv.addict at gmail.com Fri Feb 8 15:29:46 2013 From: reality.tv.addict at gmail.com (Daniel) Date: Fri, 8 Feb 2013 10:29:46 -0500 Subject: [rspec-users] Sending raw JSON data with Rails 3.2.11 and RSpec Message-ID: I apologize if this message was sent more than once, I tried to post through the Google Groups page but it didn't seem to work. In order to ensure that my application is not vulnerable to this exploit, I am trying to create a controller test in RSpec to cover it. In order to do so, I need to be able to post raw JSON, but I haven't seemed to find a way to do that. In doing some research, I've determined that there at least used to be a way to do so using the RAW_POST_DATA header, but this doesn't seem to work anymore: it "should not be exploitable by using an integer token value" do > request.env["CONTENT_TYPE"] = "application/json" > request.env["RAW_POST_DATA"] = { token: 0 }.to_json > post :reset_password > end > When I look at the params hash, token is not set at all, and it just contains { "controller" => "user", "action" => "reset_password" }. I get the same results when trying to use XML, or even when trying to just use regular post data, in all cases, it seems to not set it period. I know that with the recent Rails vulnerabilities, the way parameters are hashed was changed, but is there still a way to post raw data through RSpec? Can I somehow directly use Rack::Test::Methods? Any help would be appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ash.moran at patchspace.co.uk Fri Feb 8 18:39:07 2013 From: ash.moran at patchspace.co.uk (Ash Moran) Date: Fri, 8 Feb 2013 18:39:07 +0000 Subject: [rspec-users] Building higher-level DSLs In-Reply-To: References: Message-ID: <6D6B0609-6942-4B6E-8B7E-F972B2D55C52@patchspace.co.uk> On 7 Feb 2013, at 23:32, Sam Goldman wrote: > I'm not sure if this is what you are looking for, but I do have some experience with writing DSLs on top of RSpec. > > I made a project that lets you write tests for HTTP APIs in a bit more of a straightforward manner[1]. This isn't quite the level of DSL-ness that it seems you are going for?i.e., the specs using this library still very much look like RSpec. > > In the context of this project, I think that it was worth it. I very much enjoy writing specs in the style afforded by this DSL. This looks like a nice little DSL, and you're doing exactly what I was thinking of with the request contexts: describe "My Awesome App" do include HTTPSpec::DSL::Resource get "/foobar" do # ? expectations ? I don't know how much work would be involved, but a few extra methods might make it cover HTTP completely, e.g. I could imagine it "should be successful" do do_request status.should eq(200) end turning into response_has_status 200 or some such. This is the dilemma I run into, how long to spend adding things like this. > I think the tradeoff is about test noise. Let me define noise as details that are only relevant at a lower level of abstraction from the spec's level of abstraction. Ideally, your DSL will only hide noise. If your DSL hides signal, then consumers of your dialect will need to understand the internals. Very well put. I like the signal metaphor, and I will be stealing it, hope you don't mind :) I suspect this fear of signal-hiding is the thinking process people are using when they don't use RSpec because it has "too much magic". (On a bigger scale, I suspect it's the reason some people use Python where Ruby is a viable option, as that seems to be a whole language founded on the concept of "no magic". I'm basing this on very limited knowledge though.) Leaky abstractions are a huge waste of time for consumers of so it puts a burden on the designer of a DSL to get it right. RSpec does this very well in my experience. Actually buggy software in general is a huge cause of waste, a leaky abstraction is just one type of bug. > That said, I think it's a bad idea to start with a DSL. I'm torn between agreeing with this and arguing for the opposite, which means there must be some rule I'm missing to decide between them. When I use Cucumber, I write the DSL first and then figure out how to automate it. This has advantages in that the tests are independent of the interface(s) but does front-load some work writing an adapter layer. I've always got in the back of my mind that this is how Christopher Alexander said we should build buildings, create the language first and then use it to build a building, even if only one, and he seemed to have a good understanding of design. Mind you, he had several thousand years of architecture to extract patterns from first. > Write your tests directly, then once you have a good number of tests, ask yourself if a non-leaky abstraction exists would let you convey your specs at a higher level. You might find that this leads to a new domain concept for your production code. When I use RSpec I do this, and use duplication to locate missing domain concepts in the tests, just like you say. Maybe this is because it's possible to get quicker feedback by committing to an interface immediately. But that doesn't explain why I'd do that in RSpec and yet I wouldn't dream of using 'When I click on the "foo" div' steps in Cucumber. OTOH I *do* use Aruba, which directly contradicts that, but then I've found command line interfaces to be more stable, and they're also much simpler, and Aruba removes the front-loading effort. HTTPSpec might fall into this category. > Alternatively it might be better to augment your tests with a little DSL. Agreed that you can always improve later when you know for certain what domain concepts you need available first-class. > Sorry if that's a little too philosophical :P Heh, not at all, it's got me thinking (out loud, as usual) and is all practical ideas I can test. I think what I'll do as an experiment is extract my RSpec meta-DSL, try to fix the error reporting line number bug, and do a few katas DSL-first (i.e. no plain `it` blocks and maybe no `context` blocks either - `describe` will probably stay). Then I'll be able to see what pain and/or benefits it has. Cheers Ash -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashmoran From lawrence.pit at gmail.com Fri Feb 8 21:01:43 2013 From: lawrence.pit at gmail.com (Lawrence Pit) Date: Sat, 09 Feb 2013 08:01:43 +1100 Subject: [rspec-users] Sending raw JSON data with Rails 3.2.11 and RSpec In-Reply-To: References: Message-ID: <3436B9E2-8A91-4872-A3CA-07D064E56D4D@gmail.com> Hi Daniel, describe "Example", :type => :request do # curl -k -i -X POST -d '{"api_token":0}' https://api.example.local/reset_password # See https://groups.google.com/d/topic/rubyonrails-security/ZOdH5GH5jCU/discussion it "should not be exploitable by using an integer token value" do post "/reset_password", '{"api_token":0}', 'CONTENT_TYPE' => 'application/json', 'ACCEPT' => 'application/json' response.status.should == 401 end end Cheers, Lawrence > I apologize if this message was sent more than once, I tried to post > through the Google Groups page but it didn't seem to work. > > In order to ensure that my application is not vulnerable to this > exploit, I > am trying to create a controller test in RSpec to cover it. In order > to do > so, I need to be able to post raw JSON, but I haven't seemed to find a > way > to do that. In doing some research, I've determined that there at > least > used to be a way to do so using the RAW_POST_DATA header, but this > doesn't > seem to work anymore: > > it "should not be exploitable by using an integer token value" do >> request.env["CONTENT_TYPE"] = "application/json" >> request.env["RAW_POST_DATA"] = { token: 0 }.to_json >> post :reset_password >> end >> > > When I look at the params hash, token is not set at all, and it just > contains { "controller" => "user", "action" => "reset_password" }. I > get > the same results when trying to use XML, or even when trying to just > use > regular post data, in all cases, it seems to not set it period. > > I know that with the recent Rails vulnerabilities, the way parameters > are > hashed was changed, but is there still a way to post raw data through > RSpec? Can I somehow directly use Rack::Test::Methods? > > Any help would be appreciated. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From reality.tv.addict at gmail.com Fri Feb 8 21:44:44 2013 From: reality.tv.addict at gmail.com (Daniel Vandersluis) Date: Fri, 8 Feb 2013 13:44:44 -0800 (PST) Subject: [rspec-users] Sending raw JSON data with Rails 3.2.11 and RSpec In-Reply-To: <3436B9E2-8A91-4872-A3CA-07D064E56D4D@gmail.com> References: <3436B9E2-8A91-4872-A3CA-07D064E56D4D@gmail.com> Message-ID: <838d86cb-ee7e-41f1-b728-044a680cf5aa@googlegroups.com> Hi Lawrence, thanks for the response. Unfortunately, when I try that, I get: NoMethodError: undefined method `symbolize_keys' for > "{\"api_token\":0}":String > /Users/daniel/.rvm/gems/ruby-1.9.3-327/gems/actionpack-3.2.11/lib/action_controller/test_case.rb:150:in > `assign_parameters' > /Users/daniel/.rvm/gems/ruby-1.9.3-327/gems/actionpack-3.2.11/lib/action_controller/test_case.rb:463:in > `process' > /Users/daniel/.rvm/gems/ruby-1.9.3-327/gems/actionpack-3.2.11/lib/action_controller/test_case.rb:49:in > `process' > /Users/daniel/rails/spec/controllers/user_controller_spec.rb:10: in `block > (2 levels) in ' > On Friday, February 8, 2013 4:01:43 PM UTC-5, lawrence.pit wrote: > > Hi Daniel, > > > describe "Example", :type => :request do > > # curl -k -i -X POST -d '{"api_token":0}' > https://api.example.local/reset_password > # See > > https://groups.google.com/d/topic/rubyonrails-security/ZOdH5GH5jCU/discussion > it "should not be exploitable by using an integer token value" do > post "/reset_password", '{"api_token":0}', 'CONTENT_TYPE' => > 'application/json', 'ACCEPT' => 'application/json' > response.status.should == 401 > end > > end > > > Cheers, > Lawrence > > > I apologize if this message was sent more than once, I tried to post > > through the Google Groups page but it didn't seem to work. > > > > In order to ensure that my application is not vulnerable to this > > exploit, I > > am trying to create a controller test in RSpec to cover it. In order > > to do > > so, I need to be able to post raw JSON, but I haven't seemed to find a > > way > > to do that. In doing some research, I've determined that there at > > least > > used to be a way to do so using the RAW_POST_DATA header, but this > > doesn't > > seem to work anymore: > > > > it "should not be exploitable by using an integer token value" do > >> request.env["CONTENT_TYPE"] = "application/json" > >> request.env["RAW_POST_DATA"] = { token: 0 }.to_json > >> post :reset_password > >> end > >> > > > > When I look at the params hash, token is not set at all, and it just > > contains { "controller" => "user", "action" => "reset_password" }. I > > get > > the same results when trying to use XML, or even when trying to just > > use > > regular post data, in all cases, it seems to not set it period. > > > > I know that with the recent Rails vulnerabilities, the way parameters > > are > > hashed was changed, but is there still a way to post raw data through > > RSpec? Can I somehow directly use Rack::Test::Methods? > > > > Any help would be appreciated. > > _______________________________________________ > > rspec-users mailing list > > rspec... at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec... at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From reality.tv.addict at gmail.com Fri Feb 8 21:50:06 2013 From: reality.tv.addict at gmail.com (Daniel Vandersluis) Date: Fri, 8 Feb 2013 13:50:06 -0800 (PST) Subject: [rspec-users] Sending raw JSON data with Rails 3.2.11 and RSpec In-Reply-To: <3436B9E2-8A91-4872-A3CA-07D064E56D4D@gmail.com> References: <3436B9E2-8A91-4872-A3CA-07D064E56D4D@gmail.com> Message-ID: <47562d38-538f-4217-b5b2-25de407653a1@googlegroups.com> Sorry, I just realized you did this as a request spec, not as a controller spec! That's what I was missing here, thanks! So is it not possible to do a controller spec with raw data? On Friday, February 8, 2013 4:01:43 PM UTC-5, lawrence.pit wrote: > > Hi Daniel, > > > describe "Example", :type => :request do > > # curl -k -i -X POST -d '{"api_token":0}' > https://api.example.local/reset_password > # See > > https://groups.google.com/d/topic/rubyonrails-security/ZOdH5GH5jCU/discussion > it "should not be exploitable by using an integer token value" do > post "/reset_password", '{"api_token":0}', 'CONTENT_TYPE' => > 'application/json', 'ACCEPT' => 'application/json' > response.status.should == 401 > end > > end > > > Cheers, > Lawrence > > > I apologize if this message was sent more than once, I tried to post > > through the Google Groups page but it didn't seem to work. > > > > In order to ensure that my application is not vulnerable to this > > exploit, I > > am trying to create a controller test in RSpec to cover it. In order > > to do > > so, I need to be able to post raw JSON, but I haven't seemed to find a > > way > > to do that. In doing some research, I've determined that there at > > least > > used to be a way to do so using the RAW_POST_DATA header, but this > > doesn't > > seem to work anymore: > > > > it "should not be exploitable by using an integer token value" do > >> request.env["CONTENT_TYPE"] = "application/json" > >> request.env["RAW_POST_DATA"] = { token: 0 }.to_json > >> post :reset_password > >> end > >> > > > > When I look at the params hash, token is not set at all, and it just > > contains { "controller" => "user", "action" => "reset_password" }. I > > get > > the same results when trying to use XML, or even when trying to just > > use > > regular post data, in all cases, it seems to not set it period. > > > > I know that with the recent Rails vulnerabilities, the way parameters > > are > > hashed was changed, but is there still a way to post raw data through > > RSpec? Can I somehow directly use Rack::Test::Methods? > > > > Any help would be appreciated. > > _______________________________________________ > > rspec-users mailing list > > rspec... at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec... at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lawrence.pit at gmail.com Sat Feb 9 06:51:05 2013 From: lawrence.pit at gmail.com (Lawrence Pit) Date: Sat, 09 Feb 2013 17:51:05 +1100 Subject: [rspec-users] Sending raw JSON data with Rails 3.2.11 and RSpec In-Reply-To: <47562d38-538f-4217-b5b2-25de407653a1@googlegroups.com> References: <3436B9E2-8A91-4872-A3CA-07D064E56D4D@gmail.com> <47562d38-538f-4217-b5b2-25de407653a1@googlegroups.com> Message-ID: <9B6923BE-9E33-49BD-9829-222B272A8CB6@gmail.com> > So is it not possible to do a controller spec with raw data? Not that I know of. In the controller the raw data is assumed to have been parsed already. You could also simply set the parameter value to an integer in your test and then call your controller action: params["token"] = 0 That should give you the same query manipulation if you have this in your controller action: User.find_by_token(params["token"]) Cheers, Lawrence From lists at ruby-forum.com Wed Feb 13 21:22:46 2013 From: lists at ruby-forum.com (Boob Marleyy) Date: Wed, 13 Feb 2013 22:22:46 +0100 Subject: [rspec-users] Speeding up RSpec Tests Message-ID: <73cb85ec787d453c24c5101256b1c0c2@ruby-forum.com> Hi there, In a blog post I've seen that it's really possible to speed up some of the rspec tests by small tweaks. As far as I understand, it is about BCrypt and the cost of encryption algorithms. More information: http://blog.syncopelabs.co.uk/2012/12/speed-up-rspec-test.html Can anyone suggests me more techniques like that one. Because I'm feeling that my tests are going slow while the size of my project increases. Regards, Bob -- Posted via http://www.ruby-forum.com/. From adam.sroka at gmail.com Wed Feb 13 22:51:08 2013 From: adam.sroka at gmail.com (Adam Sroka) Date: Wed, 13 Feb 2013 14:51:08 -0800 Subject: [rspec-users] Speeding up RSpec Tests In-Reply-To: <73cb85ec787d453c24c5101256b1c0c2@ruby-forum.com> References: <73cb85ec787d453c24c5101256b1c0c2@ruby-forum.com> Message-ID: Why would you need to generate models with passwords for every spec? Why would you need to generate a password for *any* spec that wasn't specifically about authentication? It seems like hacking BCrypt is a way to avoid the design problem rather than just taking it on. On Wed, Feb 13, 2013 at 1:22 PM, Boob Marleyy wrote: > Hi there, > > In a blog post I've seen that it's really possible to speed up some of > the rspec tests by small tweaks. > As far as I understand, it is about BCrypt and the cost of encryption > algorithms. > More information: > http://blog.syncopelabs.co.uk/2012/12/speed-up-rspec-test.html > > Can anyone suggests me more techniques like that one. Because I'm > feeling that my tests are going slow while the size of my project > increases. > > Regards, > Bob > > -- > 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 ash.moran at patchspace.co.uk Thu Feb 14 15:29:54 2013 From: ash.moran at patchspace.co.uk (Ash Moran) Date: Thu, 14 Feb 2013 15:29:54 +0000 Subject: [rspec-users] Speeding up RSpec Tests In-Reply-To: References: <73cb85ec787d453c24c5101256b1c0c2@ruby-forum.com> Message-ID: <5FA9A6DA-7820-4DCF-AB0C-EB6064CBE3C4@patchspace.co.uk> On 13 Feb 2013, at 22:51, Adam Sroka wrote: > Why would you need to generate models with passwords for every spec? Why would you need to generate a password for *any* spec that wasn't specifically about authentication? > > It seems like hacking BCrypt is a way to avoid the design problem rather than just taking it on. Agreed. I hit this problem a few years ago, and the suddenly increased spec run time revealed an unwanted coupling in the code. We refactored it to extract the BCrypt code entirely. A better strategy I use now is to be aware what runtime dependencies new code pulls in, isolate the slow behaviour behind a small integration test, then remove it from the default spec run. On one project I had a few specs that needed Berkeley DB access, which was painfully slow, and I hacked Guard to only run those files if they were saved directly. This works quite well. (Admittedly, Rails makes it a lot harder to be aware what dependencies you're pulling in.) And I pretty much disagree with that entire blog post. >> Before going further, I assume you are already using Spork in your Rails project. >> If not, you must start using it now, before reading the rest of the post. The fact a spec run with one example takes 20 seconds because it depends on Rails to boot is saying something important. Spork might make a spec run 2 or 3 times as fast, but isolating your own code so it doesn't need Rails will make a spec run several orders of magnitude faster. Also, in my own attempt to use Spork, I found the monkeypatching it needs to do can cause subtle, hard-to-track-down weirdness. That was a while ago though, maybe it's fine now. Either way, it doesn't solve the design problems the slow specs are screaming to have fixed. 164 examples in 12.17 seconds is painfully slow. This is my own experience, anyway. Ash -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashmoran From lists at ruby-forum.com Wed Feb 27 13:18:50 2013 From: lists at ruby-forum.com (ruby rails) Date: Wed, 27 Feb 2013 14:18:50 +0100 Subject: [rspec-users] Testing Controllers in Rspec Message-ID: <232eda0e108992098490131a8abe01af@ruby-forum.com> I am building an Rails application where the forgot password feature is implemented. I need to write the test cases for it using RSpec. I am very new to RSPEC and got the basic idea of how rspec works from the tutorial and screencasts. But I am not sure how it can be tested for controllers. In my controller method if i am retrieving a user from database, then how would I test it using rspec. Do I give dummy data for testing rspec.?? Please find the example below. In Usercontroller.rb def forgot_pass user = User.find_by_email(params[:email]) forget_pass = ForgetPassword.new forgetpass.userid = user.email forgetpass.status = true forgetpass.save! redirect_to login_url end In my password_reset_spec require 'spec_helper' describe "PasswordResets" do it "emails when user requesting password reset" do user=User.new forget_pwd = ForgetPassword.new #forget_pwd.userid.should == "pradeep" #forget_pwd.token.should == "123456" forget_pwd.userkey = "14dd" visit auth_index_path click_link "Forgot Password" fill_in "Email", :with=> 'pradeep83.achu at gmail.com' click_button "Submit" current_path.should eq(login_path) page.should have_content("A verification mail has been sent to your email id. Click on the confirmation link to change the password") last_email.to.should include('pradeep83.achu at gmail.com') end end In the test how do I test whether the user exists and assign the attributes. In my case, user = User.find_by_email(params[:email]) forgetpass.userid = user.email Please help as I am newbie in Rspec -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Feb 27 14:24:30 2013 From: lists at ruby-forum.com (guirec c.) Date: Wed, 27 Feb 2013 15:24:30 +0100 Subject: [rspec-users] Testing Controllers in Rspec In-Reply-To: <232eda0e108992098490131a8abe01af@ruby-forum.com> References: <232eda0e108992098490131a8abe01af@ruby-forum.com> Message-ID: <6d26009a05548e4d0e76377e4309993b@ruby-forum.com> I think your are confused with acceptance specs and controllers spec. In a controller spec you must to test only your controller in total isolation. You can use stubs and mocks to do it. In the acceptance spec you must to test all the behaviour at a very high level. I think to create a record in the database for a feature spec is correct. You can see an example of my specs here : https://github.com/GCorbel/comment-my-projects/blob/master/spec/acceptance/actualities_spec.rb and here : https://github.com/GCorbel/comment-my-projects/blob/master/spec/controllers/actualities_controller_spec.rb. As you can see, I use acceptance DSL (http://jeffkreeftmeijer.com/2011/acceptance-testing-using-capybaras-new-rspec-dsl/) and factory girl (https://github.com/thoughtbot/factory_girl_rails). I hope to help you. It's very hard to begin. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Feb 27 18:53:09 2013 From: lists at ruby-forum.com (ruby rails) Date: Wed, 27 Feb 2013 19:53:09 +0100 Subject: [rspec-users] Testing Controllers in Rspec In-Reply-To: <6d26009a05548e4d0e76377e4309993b@ruby-forum.com> References: <232eda0e108992098490131a8abe01af@ruby-forum.com> <6d26009a05548e4d0e76377e4309993b@ruby-forum.com> Message-ID: <756da77f661e4af28a163350b69a8976@ruby-forum.com> guirec c. wrote in post #1099350: > I think your are confused with acceptance specs and controllers spec. In > a controller spec you must to test only your controller in total > isolation. You can use stubs and mocks to do it. In the acceptance spec > you must to test all the behaviour at a very high level. > > I think to create a record in the database for a feature spec is > correct. You can see an example of my specs here : > https://github.com/GCorbel/comment-my-projects/blob/master/spec/acceptance/actualities_spec.rb > and here : > https://github.com/GCorbel/comment-my-projects/blob/master/spec/controllers/actualities_controller_spec.rb. > > As you can see, I use acceptance DSL > (http://jeffkreeftmeijer.com/2011/acceptance-testing-using-capybaras-new-rspec-dsl/) > and factory girl (https://github.com/thoughtbot/factory_girl_rails). > > I hope to help you. It's very hard to begin. >From the link above you provided for acceptance testing I understand that we write test cases for failing conditions first and then write the code until the tests are passed. But one question that arise in my mind is that in acceptance testing do we need to write tests for checking blank values, no or no of chars for password field (like validations)?? For eg, if I am writing test cases for Forgot password feature, then I write test cases as above what I have written. So as per the test cases I would write code in controllers/models/views and make the test pass. But do I also need to write test cases for scenarios like if Email field is left blank and clicked submit button, then it should fail?? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Feb 27 19:20:33 2013 From: lists at ruby-forum.com (guirec c.) Date: Wed, 27 Feb 2013 20:20:33 +0100 Subject: [rspec-users] Testing Controllers in Rspec In-Reply-To: <232eda0e108992098490131a8abe01af@ruby-forum.com> References: <232eda0e108992098490131a8abe01af@ruby-forum.com> Message-ID: Personaly, I only create only the scenario when everything is ok (the happy path). For controllers, models, etc... I test everything. Acceptances specs are slow. Test everything in acceptances specs will make your test suite very very very slow and I think it's useless. It's only my opinion. Some developpers test with complete scenarios. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Feb 28 05:40:42 2013 From: lists at ruby-forum.com (Mattias A.) Date: Thu, 28 Feb 2013 06:40:42 +0100 Subject: [rspec-users] Simular to Include Message-ID: Hi, I have array1 that contains several web address. Array2 contains the expected endings of array1 values. How can I control that arrays2 values is in array1? I have tried array1.should include array2, but it requires that array1 and array2 is identical. array1 = ["https://..../page.html, https://..../page1.html, https://..../page3.html] array2 = ["page.html", "page2.html", "page3.html", "page4.html"] A big thanks in advance! Regards Mattias -- Posted via http://www.ruby-forum.com/. From webervin at gmail.com Thu Feb 28 06:35:36 2013 From: webervin at gmail.com (Ervin Weber) Date: Thu, 28 Feb 2013 08:35:36 +0200 Subject: [rspec-users] Simular to Include In-Reply-To: References: Message-ID: Misunderstood examples. Array1.collect{|s| s.split ('/').last}.should == array2 seems closer to your intent. -------------- next part -------------- An HTML attachment was scrubbed... URL: From webervin at gmail.com Thu Feb 28 06:29:32 2013 From: webervin at gmail.com (Ervin Weber) Date: Thu, 28 Feb 2013 08:29:32 +0200 Subject: [rspec-users] Simular to Include In-Reply-To: References: Message-ID: (Array1 - array2).should be_blank maybe? On 28 Feb 2013 07:42, "Mattias A." wrote: > Hi, > > I have array1 that contains several web address. Array2 contains the > expected endings of array1 values. How can I control that arrays2 values > is in array1? > > I have tried array1.should include array2, but it requires that array1 > and array2 is identical. > > > array1 = ["https://..../page.html, https://..../page1.html, > https://..../page3.html] > > array2 = ["page.html", "page2.html", "page3.html", "page4.html"] > > A big thanks in advance! > > Regards > Mattias > > -- > 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 reza.primardiansyah at gmail.com Thu Feb 28 07:04:29 2013 From: reza.primardiansyah at gmail.com (reza.primardiansyah at gmail.com) Date: Thu, 28 Feb 2013 07:04:29 +0000 Subject: [rspec-users] Simular to Include In-Reply-To: References: Message-ID: <1782892400-1362035108-cardhu_decombobulator_blackberry.rim.net-337893689-@b25.c5.bise3.blackberry> It appears to duplicate implementation. Perhaps this can do: array2.each do |s2| array1.should be_any do |s1| s1.include s2 end end Or use zip instead Sent from my BlackBerry? smartphone from Sinyal Bagus XL, Nyambung Teruuusss...! -----Original Message----- From: Ervin Weber Sender: rspec-users-bounces at rubyforge.org Date: Thu, 28 Feb 2013 08:35:36 To: rspec-users Reply-To: rspec-users Subject: Re: [rspec-users] Simular to Include _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Thu Feb 28 13:44:33 2013 From: lists at ruby-forum.com (ruby rails) Date: Thu, 28 Feb 2013 14:44:33 +0100 Subject: [rspec-users] uninitialized constant Factory (NameError) Message-ID: <01e4879fb072cea9817a8898b7fb7410@ruby-forum.com> I have installed factory_girl_rails gem in Gemfile for both test as well as development. And in the password_rest_spec file I have given require 'spec_helper' describe "PasswordResets" do it "emails when user requesting password reset" do user = Factory(:user) #forget_pwd.userid.should == "ruby" #forget_pwd.token.should == "123456" #forget_pwd.userkey = "14dd" visit auth_index_path click_link "Forgot Password" fill_in "Email", :with=> user.email click_button "Submit" current_path.should eq(login_path) page.should have_content("Hello Rails") last_email.to.should include(user.email) end end I have created another file called factories.rb where I have created the data as below. Factory.define :user do |f| f.sequence(:email) {|n| "foo#{n}@example.com"} f.password "Secret" end But when I am running this spec, it is failing and showing the error as uninitialized constant Factory (NameError). I have followed exactly as in the railscasts. http://railscasts.com/episodes/275-how-i-test Please help -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Feb 28 15:16:13 2013 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 28 Feb 2013 10:16:13 -0500 Subject: [rspec-users] uninitialized constant Factory (NameError) In-Reply-To: <01e4879fb072cea9817a8898b7fb7410@ruby-forum.com> References: <01e4879fb072cea9817a8898b7fb7410@ruby-forum.com> Message-ID: See https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md It's FactoryGirl, not Factory (which used to be the correct constant, but is no longer). On Thu, Feb 28, 2013 at 8:44 AM, ruby rails wrote: > I have installed factory_girl_rails gem in Gemfile for both test as well > as development. And in the password_rest_spec file I have given > > require 'spec_helper' > describe "PasswordResets" do > it "emails when user requesting password reset" do > user = Factory(:user) > #forget_pwd.userid.should == "ruby" > #forget_pwd.token.should == "123456" > #forget_pwd.userkey = "14dd" > visit auth_index_path > click_link "Forgot Password" > fill_in "Email", :with=> user.email > click_button "Submit" > current_path.should eq(login_path) > page.should have_content("Hello Rails") > last_email.to.should include(user.email) > end > end > > I have created another file called factories.rb where I have created the > data as below. > > Factory.define :user do |f| > f.sequence(:email) {|n| "foo#{n}@example.com"} > f.password "Secret" > end > But when I am running this spec, it is failing and showing the error as > uninitialized constant Factory (NameError). > I have followed exactly as in the railscasts. > http://railscasts.com/episodes/275-how-i-test > > Please help > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Thu Feb 28 17:57:25 2013 From: lists at ruby-forum.com (ruby rails) Date: Thu, 28 Feb 2013 18:57:25 +0100 Subject: [rspec-users] Validation Failed: Userkey has already been taken, Email has already been taken Message-ID: Hi, I am using Factory girl with rspec and capybara for testing my rails appliction. I have the below code FactoryGirl.define do factory :user do |f| f.email "sss1 at gmail.com" f.userkey "12ssd345q62" end end When I run the test it is failing as "Validation Failed: Userkey has already been taken, Email has already been taken". What could be the reason for this. I am new to Rspec. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Feb 28 18:55:22 2013 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 28 Feb 2013 13:55:22 -0500 Subject: [rspec-users] Validation Failed: Userkey has already been taken, Email has already been taken In-Reply-To: References: Message-ID: On Thu, Feb 28, 2013 at 12:57 PM, ruby rails wrote: > Hi, > > I am using Factory girl with rspec and capybara for testing my rails > appliction. I have the below code > FactoryGirl.define do > factory :user do |f| > f.email "sss1 at gmail.com" > f.userkey "12ssd345q62" > end > end > > When I run the test it is failing as "Validation Failed: Userkey has > already been taken, Email has already been taken". > > What could be the reason for this. I am new to Rspec. If you have unique validations on email and userkey, you'll want the factory to generate diff values every time. Take a look at https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#sequences I appreciate that you're new to RSpec, and lists like this exist to provide help, but this is the 2nd time you've asked FactoryGirl questions that could be answered by reading the FactoryGirl docs. Please do so before the next question about FactoryGirl and, if it's about FactoryGirl, you probably want to hit up https://groups.google.com/forum/?fromgroups#!forum/factory_girl, and restrict your questions on this list to those actually about rspec. If you're not sure what the cause is, and can't figure out where else to send your question, we can point you in the right direction. Cheers, David