Hello,
I read a lot about rails and BDD and I think I've found my own path. I
want to share my method and to know what you think about that.
This is my workflow :
1. Creation of feature specs (example 1);
1. Only the happy path
2. Test only things than the user can view;
3. Don't test the number of records of the database, if an email is
sent or other things like that;
4. Keep it very simple;
2. Watch the feature specs fails;
3. Create views and routes;
4. Watch the feature specs fail again;
5. Create the controllers specs (example 2);
1. Write the specs in complete isolation;
2. Use Factory Girl's build_stubbed;
3. Write a context for all conditons in ifs;
6. Create the code for the controllers specs;
7. Create the specs for all model's methods I stubbed;
8. Write the code to pass the model's specs;
9. Refactor;
10. Continue to the next feature;
I try to respect the single responsability principle (SRP) and Keep It
Simple, Stupid (KISS).
With the SRP, the controller should manage the majority of objects and
it should not be a lot of depth. The models are used only for an
interface with the database and do validation. All other things should
have their own classes.
I write specs for mailers, helpers and all other classes.
I found this mail :
http://www.mail-archive.com/rspec-users@rubyforge.org/msg03883.html. And
I think it's similar.
I don't like Cucumber and I prefer Capybara.
I read this :
http://alindeman.github.com/2012/11/11/rspec-rails-and-capybara-2.0-what-you-need-to-know.html
but I just must moved my request in a feature folder. I don't want to
create request tests. I think it test the same thing than my feature
specs and it will be slow to create two integration tests.
*Example 1 : A Request Spec
*
describe 'Create' do
it 'add a new project' do
sign_in
visit new_project_path
within('#new_project') do
fill_in("Title", with: "My Project")
fill_in("Url", with: "http://www.google.com")
select("Ruby", from: "Type")
click_button "Create"
end
page.should have_content("Your project was created")
end
end
*Example 2 : A Controller Spec*
describe "#create" do
context "with valid data" do
it "redirect to project's path"Did
it "save the project"
it "set a flash message"
end
context "with invalid data" do
it "render new template"
end
end
What do you think about that? Did I write my specs as I should?
Thanks and bye!
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users