Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up rspec-rails to generate feature specs for capybara

I'm using rspec-rails 2.12.0 and capybara 2.0.1 for testing. In capybara 2.x you need to put your specs in spec/features instead of spec/requests. Is there a way so if I were to generate a scaffold ala 'rails g scaffold Model' that rspec would generate the feature specs for me in the correct directory?

like image 310
jhummel Avatar asked Nov 30 '12 18:11

jhummel


People also ask

What is RSpec capybara?

Capybara is a web-based automation framework that creates certain functional tests in order to simulate how a user may interact with an application. It is a library used on top of a web-based driver that writes the code in Ruby. This Ruby library has an advantage as it interacts with applications​ from a Rack level.

What is a feature spec in RSpec and where do we use them in our application?

Feature specs, a kind of acceptance test, are high-level tests that walk through your entire application ensuring that each of the components work together. They're written from the perspective of a user clicking around the application and filling in forms.

What does capybara do in Rails?

Capybara is an acceptance test framework for web applications. It's a common choice for end-to-end, acceptance, or integration testing in Rails applications. It allows developers to simulate a user on a web page and make assertions based on the content and environment of the page.


1 Answers

"controller" and "request" specs are tied to the inner app mechanism and thus can be auto generated by scaffold generator mimicking the controller structure.

"Feature" specs are completely different conceptually from these specs as they describe end user interactions with the application, they cannot be generated in advance as there is no way to effectively guess what feature you want to test. Feature specs also spread across multiple controllers, you don't want them to be mapped to your controller scaffold. The only thing that could be done is generate an almost empty feature/xyz file for you to fill in, which is pretty useless as chances are you will have to delete/rename it.

like image 125
a.s.t.r.o Avatar answered Sep 28 '22 05:09

a.s.t.r.o