我正在尝试为我的rails应用程序构建测试功能。 我正在使用萝卜来编写功能测试。 在github页面中,据说将步骤定义放在模块“您现在可以在RSpec中包含此模块”之后。 但目前尚不清楚推荐的RSpec在哪里。 它是文件夹还是文件,它在哪里?
有人可以澄清一下吗?
谢谢。
I am trying to build testing capability for my rails application. I am using turnip to write feature test. In the github page, it is said that after putting the step definitions in a module "You can now include this module in RSpec". But it is not clear where the referred RSpec is. Is it a folder or a file and where it is?
Could anyone please clarify on this?
Thanks.
最满意答案
萝卜文档中提到的RSpec.configure块可以在spec/spec_helper.rb和/或spec/rails_helper.rb 。 您可能只有一个文件。 在那里,你可以包括你的步骤:
RSpec.configure do |config| config.include MonsterSteps # other settings... end两者之间的区别在于,前者仅加载最少量的代码以使库规范更快,而后者加载整个Rails堆栈。 您需要自己决定需要助手的位置。 如果您不确定,请将其放在spec/spec_helper.rb因为这将使其适用于所有规格。
如果您根本没有rspec文件夹,则需要将rspec-rails添加到Gemfile:
gem 'rspec-rails', group: [:development, :test]然后运行
bundle install最后生成基本的RSpec文件
rails generate rspec:installThe RSpec.configure block mentioned in the turnip documentation can be found in spec/spec_helper.rb and/or spec/rails_helper.rb. It is possible that you have only one of the files. There, you can include your steps:
RSpec.configure do |config| config.include MonsterSteps # other settings... endThe difference between the two is that the former loads only a minimal amount of code to make library specs faster, and the latter one loads the entire Rails stack. You need to decide on your own where you need the helpers. If you are not sure, put it in spec/spec_helper.rb as this will make it available to all specs.
If you don't have a rspec folder at all, you need to add rspec-rails to your Gemfile:
gem 'rspec-rails', group: [:development, :test]then run
bundle installand finally generate the basic RSpec files with
rails generate rspec:install更多推荐
发布评论