How and what to test by using respectively Cucumber and Rspec?

本小妞迷上赌 提交于 2019-12-12 03:12:28

问题


I am using Ruby on Rails 3.2.2, cucumber-rails-1.3.0, rspec-rails-2.8.1 and capybara-1.1.2 with the Selenium driver. I would like to know how and what to test by using respectively Cucumber and Rspec? That is, what "behavior" should I treat with Cucumber and what with Rspec so to divide testing "concerns" in a proper way?

For example, in order to test a view, should I test the presence of a CSS id in a page content by using Cucumber or RSpec? or both?


回答1:


Use RSpec to test the various parts(Controllers, Models and Views) of your app by isolating them. (with Mock, Stub and the others tools that gives you RSpec)

Use Cucumber to test all parts of your app togheter, as you see the app in the browser... for example, if you need to test the sign in form of your app without cucumber you should:

1) Open a shell and run rails server.

2) Go to browser and type the url of login.

3) Fill in form fields.

4) Click Submit button.

You should automate this process, and similar process with Cucumber, for others test use Rspec.




回答2:


They both can test for node attributes, but I would use Capybara only for request specs. Ultimately it is personal preference. I use rspec and capybara together, but the language syntax of capybara makes more sense/is semantic as rspec when testing for request/expectations.




回答3:


Use UnitTest & capybara for testing because its more simple and fast. Checkout this URL for more details.

http://guides.rubyonrails.org/testing.html



来源:https://stackoverflow.com/questions/9906352/how-and-what-to-test-by-using-respectively-cucumber-and-rspec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!