Cathal Curtis
2012-Feb-13 22:46 UTC
[rspec-users] Should I use cucumber or Controller RSpecs or both?
Hi All, I''d like to get some other''s opinions on testing controllers. Say I have a model and I want to prevent deletion of instances of it. The controllers''s destroy action simply redirects to an error page - nothing else. Lets assume the relevant views have no links or buttons to delete the instance. I want to ensure that on receipt of a DELETE request for an instance of that model, that the application does in fact disallow the deletion and redirects to an error page. Should I create a cucumber test, with a step that would call something like: "delete url_for(...)"? Or should I leave it to a Controller RSpec? I have implemented both, the RSpec is working fine but I''m having trouble getting cucumber to follow the redirect and therefore my "Then I should be on error page" fails. I''d like to know if such a cucumber test is unnecessary. Should I even have such a cucumber test if the user cannot generate the condition/action/event through normal use of the application? If the controller RSpec proves that the controller responds with a redirect response to the correct page, is that all I need? Thanks in advance, Cathal. -- Posted via http://www.ruby-forum.com/.
Cynthia Kiser
2012-Feb-14 03:56 UTC
[rspec-users] Should I use cucumber or Controller RSpecs or both?
Quoting Cathal Curtis <lists at ruby-forum.com>:> I want to ensure that on receipt of a DELETE request for an instance of > that model, that the application does in fact disallow the deletion and > redirects to an error page. > > Should I create a cucumber test, with a step that would call something > like: "delete url_for(...)"? > Or should I leave it to a Controller RSpec?...> I''d like to know if such a cucumber test is unnecessary. > Should I even have such a cucumber test if the user cannot generate the > condition/action/event through normal use of the application?In my opinion, if the user can''t generate the event through normal interaction (clicking links, etc.) then it probably shouldn''t be in a cucumber test.> If the controller RSpec proves that the controller responds with a > redirect response to the correct page, is that all I need?Yes. The two tests are trying to test the same thing and so are mostly redundant. But I think the RSpec test is the more appropriate test. It''s a bonus that that one is already working. -- Cynthia N. Kiser cnk at ugcs.caltech.edu
Justin Ko
2012-Feb-14 03:57 UTC
[rspec-users] Should I use cucumber or Controller RSpecs or both?
On Feb 13, 2012, at 3:46 PM, Cathal Curtis wrote:> Hi All, > > I''d like to get some other''s opinions on testing controllers. > > Say I have a model and I want to prevent deletion of instances of it. > The controllers''s destroy action simply redirects to an error page - > nothing else. > Lets assume the relevant views have no links or buttons to delete the > instance. > I want to ensure that on receipt of a DELETE request for an instance of > that model, that the application does in fact disallow the deletion and > redirects to an error page. > > Should I create a cucumber test, with a step that would call something > like: "delete url_for(...)"? > Or should I leave it to a Controller RSpec? > > I have implemented both, the RSpec is working fine but I''m having > trouble getting cucumber to follow the redirect and therefore my "Then I > should be on error page" fails. > > I''d like to know if such a cucumber test is unnecessary. > Should I even have such a cucumber test if the user cannot generate the > condition/action/event through normal use of the application? > If the controller RSpec proves that the controller responds with a > redirect response to the correct page, is that all I need? > > Thanks in advance, Cathal. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersSome good discussion on this topic: http://solnic.eu/2012/02/02/yes-you-should-write-controller-tests.html
Andrew Premdas
2012-Feb-14 09:52 UTC
[rspec-users] Should I use cucumber or Controller RSpecs or both?
On 13 February 2012 22:46, Cathal Curtis <lists at ruby-forum.com> wrote:> Hi All, > > I''d like to get some other''s opinions on testing controllers. > > Say I have a model and I want to prevent deletion of instances of it. > The controllers''s destroy action simply redirects to an error page - > nothing else. > Lets assume the relevant views have no links or buttons to delete the > instance. > I want to ensure that on receipt of a DELETE request for an instance of > that model, that the application does in fact disallow the deletion and > redirects to an error page. > > Should I create a cucumber test, with a step that would call something > like: "delete url_for(...)"? > Or should I leave it to a Controller RSpec? > > I have implemented both, the RSpec is working fine but I''m having > trouble getting cucumber to follow the redirect and therefore my "Then I > should be on error page" fails. > > I''d like to know if such a cucumber test is unnecessary. > Should I even have such a cucumber test if the user cannot generate the > condition/action/event through normal use of the application? > If the controller RSpec proves that the controller responds with a > redirect response to the correct page, is that all I need? > > Thanks in advance, Cathal. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >Why do you want to ensure that the instance cannot be deleted. If its a business concern then you should write a cuke for it. If you just want to specify as a dev that it can''t be deleted then perhaps you could write a routing spec that says there is no route for delete, though are you going to write specs that say you can''t foo_it or bar_it? There are lots of security concerns that a business can have about users doing things that have no interaction in the UI. These are generally very easy to implement in cucumber e.g - after all you just need to visit a url to generate the request. The only issue is that in Rails you may not get the error page you expect because you are running in test mode. You can address that by using an @allow-rescue tag on the feature. HTH Andrew -- ------------------------ Andrew Premdas blog.andrew.premdas.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120214/5abdbb4b/attachment.html>
Cathal Curtis
2012-Feb-15 09:23 UTC
[rspec-users] Should I use cucumber or Controller RSpecs or both?
Cathal Curtis wrote in post #1046554: I found what I think is the answer to my question by chance while doing some further searching on the web: http://groups.google.com/group/ruby-capybara/browse_thread/thread/7b6c92e4c96c9135 Jonas Nicklas describes it as using the wrong tool for the job. Capybara is restricted to what a normal user can do. And he says it should be tested in a controller test/spec... -- Posted via http://www.ruby-forum.com/.