如何将第一个 Cucumber 测试添加到 Rails 应用程序
坦白说:我从未为 Rails 编写过任何测试。
我已经安装了gems cucumber、rspec、capybara、factory girls。运行轨道 3.1。
我不确定在哪里创建新的测试文件或命名它。
感谢您的耐心等待。
Confession: I have never written a single test for Rails.
I have installed the gems cucumber, rspec, capybara, factory girl. Running Rails 3.1.
I am not sure, um, where to create a new test file or what to name it.
Thanks for your patience.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Micheal Hartl 有一个关于 Rails 的很好的教程,主要是测试驱动的:
http://ruby.railstutorial.org/
您可能知道其中大部分内容,但它会为您指明正确的方向。
这是在 Cucumber 上投射的 Rails:
http://railscasts.com/episodes/155-beginning-with-cucumber
这是 RSpec Rails 演员表:
http://railscasts.com/episodes/71-testing-controllers-with-rspec
以下是一堆 Cucumber 示例:
https://github.com/cucumber/cucumber/tree/master/examples/i18n
希望有帮助!
Micheal Hartl has a good tutorial on Rails that is mostly test driven:
http://ruby.railstutorial.org/
You probably know most of this but it will point you in the right direction.
Here's a Rails Cast on Cucumber:
http://railscasts.com/episodes/155-beginning-with-cucumber
Here's an RSpec Rails Cast:
http://railscasts.com/episodes/71-testing-controllers-with-rspec
Here are a bunch of Cucumber examples:
https://github.com/cucumber/cucumber/tree/master/examples/i18n
Hope that helps!
安装 rspec 和 cucumber 后
您必须运行以下命令
rails generated rspec:install
对于 rspec第一个命令,
将配置rails生成命令,它将创建spec目录,其中将包含模型,控制器,视图的测试,在各自的目录中,您可以编写
rspec 测试
例如。如果您有用户模型,那么用户的规格将进入
spec/models/user_spec.rb ,
运行
这些测试使用
rspec spec/models/user_spec.rb
,将输出测试是否通过
Cucumber 描述应用程序的行为
的行为
,rspec 描述对象rails 生成 cucumber:install
,这将在您的 Cucumber 中创建 features 目录应用root
里面你可以用 .feature 扩展名编写黄瓜测试,
例如。如果您的应用程序具有创建用户之类的功能,则此功能将放在
features/creating_user.feature 文件
中,并且此功能的步骤定义将放在
features/step_definitions/create_user_steps.rb
中,它只是简短的指导方针,您可以参考以下
链接黄瓜
http:// /loudcoding.com/posts/quick-tutorial-starting-with-cucumber-and-capybara-bdd-on-rails-project/
after installing the rspec and cucumber
you must run following commands
rails generate rspec:install for rspec
first command
will configure rails generate command and it will create the spec directory which will contain tests for your models, controllers, views in respective directory you can write the
rspec test
eg. If you are having user model then specs for user will go in
spec/models/user_spec.rb
that's it
to run these tests use
rspec spec/models/user_spec.rb
which will output the whether the tests are passed or not
cucumber describes the behavior of application
and rspec describes behavior of object
rails generate cucumber:install for cucumber
which will create features directory in your application root
inside that you can write cucumber test with .feature extension
eg. If your application have feature like creating user, this feature will go in
features/creating_user.feature file
and the step definition for this feature will go in
features/step_definitions/create_user_steps.rb
well its just short guide line you can refer the following links
for cucumber
http://loudcoding.com/posts/quick-tutorial-starting-with-cucumber-and-capybara-bdd-on-rails-project/
想想人们使用您的应用程序的最常见方式是什么。为“快乐路径”编写测试,忽略任何边缘情况。
接下来,为最有可能损坏的部分编写测试。
Think what is the most common way for people to use your app. Write a test for the 'happy path', ignoring any edge cases.
Next, write tests for the parts most likely break.