ruby-on-rails - Rails Guard 正在寻找规范文件夹,但没有规范文件夹

标签 ruby-on-rails rspec cucumber guard

这是第一次,我正在尝试 BDD 和测试,我正在通过查看教程进行尝试,我的问题是我发现守卫正在寻找其守卫文件中定义的规范文件夹, 但没有spec文件夹,我有test文件夹。

当我运行时

守卫

它尝试加载规范文件夹,但没有规范文件夹。是否可以编辑保护文件以查找测试文件夹而不是规范文件夹?

我应该安装 rspec 吗?

rails g rspec 安装

找不到生成器 rspec。

我的 gem 文件

source 'https://rubygems.org'

gem 'rails',     path: '/home/phanindra/rails'
gem 'journey', git: 'https://github.com/rails/journey.git'
gem 'arel',      git: 'https://github.com/rails/arel'
gem 'activerecord-deprecated_finders', git: 'https://github.com/rails/activerecord-deprecated_finders'

gem 'sqlite3'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sprockets-rails', git: 'https://github.com/rails/sprockets-rails'
  gem 'sass-rails',   git: 'https://github.com/rails/sass-rails'
  gem 'coffee-rails', git: 'https://github.com/rails/coffee-rails'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  gem 'therubyracer', platforms: :ruby

  gem 'uglifier', '>= 1.0.3'
end
gem 'rb-inotify', '~> 0.8.8'
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

group :test, :development do
  gem 'cucumber-rails', :require => false
  gem 'database_cleaner'
  gem 'rspec'
  gem 'spork'
  gem 'guard'
  gem 'guard-rspec'
  gem 'launchy'
end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano', group: :development

# To use debugger
# gem 'debugger'

我的 guard 文件

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'rspec' do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml)$})                 { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }

  # Capybara features specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/features/#{m[1]}_spec.rb" }

  # Turnip features and steps
  watch(%r{^spec/acceptance/(.+)\.feature$})
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end

按照Could not find generator rspec:install.上的答案进行操作 我已将 rspec-rails 添加到我的 gem 文件中并进行了捆绑安装,然后 rspec 生成器工作并生成了spec 文件夹。

但它在测试文件夹中没有任何文件夹,如固定装置或验收或功能等!!

最佳答案

根据官方文档(https://github.com/rspec/rspec-rails#install),我认为你应该运行:

# not: rails g rspec install
rails generate rspec:install   

生成“spec”文件夹和“spec/spec_helper.rb”文件以及其他相关内容。

关于ruby-on-rails - Rails Guard 正在寻找规范文件夹,但没有规范文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14138628/

相关文章:

ruby-on-rails - Rails 上的 ruby |设置属性

ruby-on-rails - Rails 4 + Rspec + 设计 : undefined method 'env' in controller specs for sign_in a user

ruby-on-rails - 两个外键的作用域

ruby-on-rails - 具有一些智能的 Rails 迭代

ruby - 如何将自定义消息附加到 RSpec 异常消息

Selenium WebDriver 连接被拒绝 - 连接被拒绝 (Errno::ECONNREFUSED)

javascript - 定义两个级别的登录过程 Cucumber 测试场景

ruby-on-rails-3 - 在 cucumber / capybara / Selenium 中 stub Ajax请求?

ruby-on-rails - Rails 4 的价格验证

ruby-on-rails - 为什么我在 rspec 中得到事件记录关系而不是数组?