Hello Everyone, I am new to Ruby on Rails. I just finished Michael Hartl''s *Ruby on Rails Tutorial* <http://ruby.railstutorial.org/ruby-on-rails-tutorial-book> and I just started on *Agile Web Development with Rails, Fourth Edition* by Sam Ruby <http://pragprog.com/book/rails4/agile-web-development-with-rails>. In trying to build confidence and proficiency, I started building small apps and decided, as I had learned from Michael Hartl, to use capybara<https://github.com/jnicklas/capybara>and rspec <https://github.com/rspec/rspec>. But when I tried it nothing was working. It turns out, this was the reason: If you are using Rails, put your Capybara specs in spec/features.> And in order to use the tests I had created in spec/requests, I have to dothis: If you are not using Rails, tag all the example groups in which you want to> use Capybara with :type => :feature.Can anyone explain the reasoning behind this? I''m sure there is a good reason for this that my newbie self does not comprehend yet. Thank you in advance. p -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/yvcOOFxzJyEJ. For more options, visit https://groups.google.com/groups/opt_out.
Here''s a post by Jose Valim on the reasoning behind the change: http://blog.plataformatec.com.br/2012/06/improving-the-integration-between-capybara-and-rspec/ As a quick summary, Capybara is an acceptance test framework and as such, tests should be written from a browser or user''s perspective. With the rspec-rails gem, tests found in spec/requests directory have access to methods that expose lower-level details like requests and responses(methods like get, put, post.) So if Capybara tests are also found in that same spec/requests directory, you are able to use both the Capybara DSL and the free methods that are meant for integration tests which causes a conflict and leads to some developers using a mix of both. This leads to ugly test suites. The solution they came up with is to create a separate directory meant for use with Capybara DSL, which is spec/features and another directory (spec/api) meant for use with the Rails provided integration test tools. Michael Hartl will be releasing a newer version of his tutorial sometime in the future which will provide more up-to-date material. You might also want to look at RSpec''s ''expect'' syntax for its assertions. They plan on deprecating the ''should'' syntax possibly as early as RSpec 3.0. On Sunday, March 31, 2013 1:57:30 PM UTC+8, Peter wrote:> > Hello Everyone, > > I am new to Ruby on Rails. I just finished Michael Hartl''s *Ruby on Rails > Tutorial* <http://ruby.railstutorial.org/ruby-on-rails-tutorial-book> and > I just started on *Agile Web Development with Rails, Fourth Edition* by > Sam Ruby<http://pragprog.com/book/rails4/agile-web-development-with-rails>. > In trying to build confidence and proficiency, I started building small > apps and decided, as I had learned from Michael Hartl, to use capybara<https://github.com/jnicklas/capybara>and > rspec <https://github.com/rspec/rspec>. But when I tried it nothing was > working. It turns out, this was the reason: > > If you are using Rails, put your Capybara specs in spec/features. > > > >> And in order to use the tests I had created in spec/requests, I have to > do this: > > If you are not using Rails, tag all the example groups in which you want >> to use Capybara with :type => :feature. > > > Can anyone explain the reasoning behind this? I''m sure there is a good > reason for this that my newbie self does not comprehend yet. Thank you in > advance. > > p >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/kktojwdJDlUJ. For more options, visit https://groups.google.com/groups/opt_out.
Julian Leviston
2013-Mar-31 09:56 UTC
Re: Re: Why Did Capybara Move Specs into spec/features?
From my point of view (as a professional Rails dev), this makes much better and more complete sense. Devs are *always* confused about this, and have lots of trouble around it. One often ends up wondering "Do I use visit/page or do I use request(get/post)/response?" Julian On 31/03/2013, at 8:16 PM, Gjaldon <gjaldon85-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Here''s a post by Jose Valim on the reasoning behind the change: > http://blog.plataformatec.com.br/2012/06/improving-the-integration-between-capybara-and-rspec/ > > As a quick summary, Capybara is an acceptance test framework and as such, tests should be written from a browser or user''s perspective. With the rspec-rails gem, tests found in spec/requests directory have access to methods that expose lower-level details like requests and responses(methods like get, put, post.) So if Capybara tests are also found in that same spec/requests directory, you are able to use both the Capybara DSL and the free methods that are meant for integration tests which causes a conflict and leads to some developers using a mix of both. This leads to ugly test suites. > > The solution they came up with is to create a separate directory meant for use with Capybara DSL, which is spec/features and another directory (spec/api) meant for use with the Rails provided integration test tools. > > Michael Hartl will be releasing a newer version of his tutorial sometime in the future which will provide more up-to-date material. You might also want to look at RSpec''s ''expect'' syntax for its assertions. They plan on deprecating the ''should'' syntax possibly as early as RSpec 3.0. > > On Sunday, March 31, 2013 1:57:30 PM UTC+8, Peter wrote: > Hello Everyone, > > I am new to Ruby on Rails. I just finished Michael Hartl''s Ruby on Rails Tutorial and I just started on Agile Web Development with Rails, Fourth Edition by Sam Ruby. In trying to build confidence and proficiency, I started building small apps and decided, as I had learned from Michael Hartl, to use capybara and rspec. But when I tried it nothing was working. It turns out, this was the reason: > > If you are using Rails, put your Capybara specs in spec/features. > > And in order to use the tests I had created in spec/requests, I have to do this: > > If you are not using Rails, tag all the example groups in which you want to use Capybara with :type => :feature. > > Can anyone explain the reasoning behind this? I''m sure there is a good reason for this that my newbie self does not comprehend yet. Thank you in advance. > > p > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/kktojwdJDlUJ. > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Thanks for the advice on the upcoming RSpec expect syntax. On Sunday, March 31, 2013 2:16:50 AM UTC-7, Gjaldon wrote:> > Here''s a post by Jose Valim on the reasoning behind the change: > > http://blog.plataformatec.com.br/2012/06/improving-the-integration-between-capybara-and-rspec/ > > As a quick summary, Capybara is an acceptance test framework and as such, > tests should be written from a browser or user''s perspective. With the > rspec-rails gem, tests found in spec/requests directory have access to > methods that expose lower-level details like requests and responses(methods > like get, put, post.) So if Capybara tests are also found in that same > spec/requests directory, you are able to use both the Capybara DSL and the > free methods that are meant for integration tests which causes a conflict > and leads to some developers using a mix of both. This leads to ugly test > suites. > > The solution they came up with is to create a separate directory meant for > use with Capybara DSL, which is spec/features and another directory > (spec/api) meant for use with the Rails provided integration test tools. > > Michael Hartl will be releasing a newer version of his tutorial sometime > in the future which will provide more up-to-date material. You might also > want to look at RSpec''s ''expect'' syntax for its assertions. They plan on > deprecating the ''should'' syntax possibly as early as RSpec 3.0. > > On Sunday, March 31, 2013 1:57:30 PM UTC+8, Peter wrote: >> >> Hello Everyone, >> >> I am new to Ruby on Rails. I just finished Michael Hartl''s *Ruby on >> Rails Tutorial*<http://ruby.railstutorial.org/ruby-on-rails-tutorial-book> and >> I just started on *Agile Web Development with Rails, Fourth Edition* by >> Sam Ruby<http://pragprog.com/book/rails4/agile-web-development-with-rails>. >> In trying to build confidence and proficiency, I started building small >> apps and decided, as I had learned from Michael Hartl, to use capybara<https://github.com/jnicklas/capybara>and >> rspec <https://github.com/rspec/rspec>. But when I tried it nothing was >> working. It turns out, this was the reason: >> >> If you are using Rails, put your Capybara specs in spec/features. >> >> >> >>> And in order to use the tests I had created in spec/requests, I have to >> do this: >> >> If you are not using Rails, tag all the example groups in which you want >>> to use Capybara with :type => :feature. >> >> >> Can anyone explain the reasoning behind this? I''m sure there is a good >> reason for this that my newbie self does not comprehend yet. Thank you in >> advance. >> >> p >> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/kybOhYfoTbUJ. For more options, visit https://groups.google.com/groups/opt_out.