- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Rails 4.2.4 和 ruby 2.2.3。
这是我的spec_helper.rb 文件(由生成器生成):
RSpec.configure do |config|
require 'rails/all'
require 'json_spec'
require 'devise'
require 'rspec/rails'
config.infer_spec_type_from_file_location!
config.include JsonSpec::Helpers
config.include Devise::TestHelpers, type: :request
config.include Devise::TestHelpers, type: :controller # https://github.com/plataformatec/devise#test-helpers
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
end
这是我的rails_helper.rb:
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort('The Rails environment is running in production mode!') if Rails.env.production?
# ADDED BY AS #
require 'support/database_cleaner'
require 'yarjuf'
# END OF ADDED BY AS #
require 'spec_helper'
require 'rspec/rails'
# ADDED BY AS #
if ENV['COVERAGE']
require 'simplecov'
require 'simplecov-csv'
SimpleCov.formatter = SimpleCov::Formatter::CSVFormatter
SimpleCov.coverage_dir(ENV['COVERAGE_REPORTS'])
SimpleCov.start 'rails'
end
# END OF ADDED BY AS #
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
end
在Gemfile
上:
source 'https://rubygems.org'
ruby '2.2.3'
# ruby '2.1.0', :engine => 'rbx', :engine_version => '2.2.6' #rubinius
# ruby '1.9.3', engine: 'jruby', engine_version: '1.7.10'
source 'https://be79af0d:c5a6f6bd@gems.contribsys.com/' do
gem 'sidekiq-pro', '>= 3'
end
gem 'mime-types', '>= 2.6', require: 'mime/types/columnar'
gem 'activerecord-import'
gem 'aasm', '~> 4.5.0'
gem 'activerecord-colored_log_subscriber'
gem 'aws-sdk-v1' # Needed by paperclip @ v4.2.1, consider the removal after paperclip gem updates will support awk-sdk v2.
gem 'aws-sdk', '~> 2'
gem 'active_model_serializers'
gem 'ancestry', '~> 2.1.0' # Gestione delle gerarchie ad albero
gem 'auxilium', path: 'engines/auxilium'
gem 'barby', '~> 0.6.1' # Codice a barre
gem 'bootstrap-kaminari-views', '~> 0.0.5'
gem 'cancancan', '~> 1.13'
gem 'crummy', '~> 1.8.0'
gem 'dalli'
gem 'devise', '~> 3.5.0'
gem 'devise_security_extension'
gem 'devise-async', '~> 0.10.1'
gem 'email_validator', '>= 1.5.0'
gem 'flipclockjs-rails', '~> 0.7.4', git: 'https://github.com/knightq/flipclockjs-rails.git'
gem 'font_assets'
gem 'google_visualr', '~> 2.5.1' # Grafici
gem 'hamlit-rails'
gem 'hirefire-resource', '~> 0.3.8'
gem 'htmlentities', '~> 4.3.4', require: false
gem 'ice_cube', '~> 0.12.1' # Ricorrenze
gem 'jhtmlarea', '~> 0.1.0' # formattazione testo
gem 'kaminari', '~> 0.16.2'
gem 'mailboxer', '~> 0.13.0' # Messaggistica interna
gem 'memcachier'
gem 'mini_magick', '~> 4.3.4', require: false
gem 'newrelic_rpm'
gem 'paperclip', '~> 4.3'
gem 'paginate_alphabetically', '~> 0.3.3', git: 'https://github.com/edendevelopment/paginate_alphabetically.git', branch: 'bundler'
gem 'paper_trail', '~> 4.0.0' # Record versioning
gem 'pdfkit', '~> 0.8.2'
gem 'pg', '~> 0.18.4' # PostgreSql
gem 'heroku-api', require: false
gem 'prawn', '~> 1.0.0'
gem 'prawn-print'
gem 'prawn-svg', '~> 0.22'
gem 'prawn-templates', '~> 0.0.3'
gem 'rack-attack'
gem 'rails', '~> 4.2.4'
gem 'rails-jquery-autocomplete'
gem 'rainbow', '~> 2.0.0', require: false
gem 'ransack', '~> 1.7.0' # Ricerche
gem 'render_anywhere', '~> 0.0.12' # Gemma per il rendering di view in workers
gem 'responders', '~> 2.0'
gem 'rollbar', '~> 2.6' # Gestione eccezioni
gem 'rqrcode', '~> 0.7.0' # Codice QR
gem 'savon', '~> 2.0'
gem 'scout_apm'
gem 'sinatra', '>= 1.3.0', require: nil
# gem 'sidekiq', '>= 3.3.2'
gem 'sidekiq-limit_fetch', '>= 3.0.1'
gem 'sidekiq-status', '~> 0.5.1'
gem 'sidekiq-statistic', '~> 1.2'
gem 'sorted', '~> 2.0.3'
gem 'sorted-actionview', '~> 0.0.1'
gem 'sorted-activerecord', '~> 0.1.2'
gem 'switch_user', '~> 1.2.0'
gem 'jc-validates_timeliness', '~> 3.0'
gem 'when_easter', '~> 0.3.1' # Calcolo pasqua
gem 'wicked', '~> 1.2.1' # Wizards
gem 'wkhtmltopdf-binary', '~> 0.9.9.1'
gem 'rubyzip', require: false
gem 'ruby-progressbar', require: false
gem 'templatar'
gem 'tunemygc'
gem 'rqrcode-rails3'
gem 'strip_attributes'
gem 'analytics-ruby', '~> 2.0.0', require: 'segment/analytics'
gem 'activerecord-session_store', '~> 0.1.2'
gem 'jquery-ui-themes', '~> 1.11.4', git: 'https://github.com/knightq/jquery-ui-themes-rails.git', branch: 'jquery-ui-1.11.x'
# Rubinius-test dependencies
# gem 'racc', platform: :rbx
# gem 'rubysl', platform: :rbx
# jruby-test dependencies
# gem 'activerecord-jdbcpostgresql-adapter'
# gem 'rmagick4j'
# TODO: Test rubinius and jruby with puma
group :production, :staging do
# gem 'unicorn', '~> 4.7.0'
gem 'kgio'
gem 'puma', '~> 2.15.3'
gem 'rack-cache'
gem 'rails_12factor' # see http://stackoverflow.com/questions/9027403/rails-2-3-style-plugins-and-deprecation-warnings-running-task-in-heroku
end
gem 'bootstrap-sass', '~> 2.3.2.2'
gem 'chosen-rails', '~> 1.4.3'
gem 'coffee-rails', '~> 4.1.0'
gem 'momentjs-rails'
gem 'fullcalendar-rails', '~> 2.5.0'
gem 'jquery_context_menu-rails', '~> 0.0.4'
gem 'jquery-fileupload-rails', '~> 0.4.1'
gem 'jquery-rails', '~> 4.0.5'
gem 'jquery-ui-rails'
gem 'jqgrid-jquery-rails'
gem 'sass-rails', '~> 5.0.4'
gem 'sprockets'
gem 'select2-rails', '~> 3.5.9.3'
gem 'uglifier', '~> 2.7.2'
gem 'jquery-infinite-pages', '~> 0.2.0'
group :development do
# gem 'better_errors'
# gem 'binding_of_caller'
gem 'derailed'
gem 'bullet'
gem 'web-console', '~> 2.0'
gem 'hirb', '~> 0.7.1'
gem 'hub', require: false
gem 'i18n_yaml_sorter'
gem 'meta_request'
gem 'quiet_assets'
gem 'peek'
gem 'peek-rblineprof'
gem 'peek-git'
gem 'peek-gc'
gem 'peek-performance_bar'
gem 'peek-pg'
gem 'pygments.rb', require: false
# gem 'rack-mini-profiler'
gem 'rubocop'
gem 'spring'
gem 'stackprof'
gem 'thin'
gem 'traceroute' # find the dead routes and actions, see: https://github.com/amatsuda/traceroute
end
group :staging do
gem 'httplog'
end
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :development, :test do
gem 'capybara', '~> 2.5.0'
gem 'database_cleaner'
gem 'factory_girl_rails', '~> 4.0'
gem 'jasmine-rails'
gem 'pry-rails'
gem 'pry-nav'
gem 'rspec-rails', '~> 3.4.0'
gem 'seed-fu', '~> 2.3'
end
group :test do
gem 'yarjuf'
gem 'json_spec', require: false
gem 'simplecov', require: false
gem 'simplecov-csv', require: false
end
到目前为止,我在 /spec/models/my_model_spec.rb
上只有一个规范类:
require 'rails_helper'
describe MyModel do
end
服务器启动并正确运行,但是当我尝试启动bundle exec rspec spec
o甚至简单地rspec spec
时,我得到:
/Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:146:in `to_app': missing run or map statement (RuntimeError)
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:160:in `block in generate_map'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:160:in `each'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:160:in `generate_map'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:145:in `to_app'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/capybara-2.5.0/lib/capybara/rails.rb:13:in `<top (required)>'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-rails-3.4.0/lib/rspec/rails/vendor/capybara.rb:7:in `<top (required)>'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-rails-3.4.0/lib/rspec/rails.rb:13:in `<top (required)>'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
from /Users/andreasalicetti/Development/epersonam/spec/spec_helper.rb:23:in `block in <top (required)>'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core.rb:97:in `configure'
from /Users/andreasalicetti/Development/epersonam/spec/spec_helper.rb:19:in `<top (required)>'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1295:in `require'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1295:in `block in requires='
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1295:in `each'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1295:in `requires='
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/configuration_options.rb:109:in `block in process_options_into'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/configuration_options.rb:108:in `each'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/configuration_options.rb:108:in `process_options_into'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/configuration_options.rb:21:in `configure'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:101:in `setup'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:88:in `run'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:73:in `run'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:41:in `invoke'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.1/exe/rspec:4:in `<top (required)>'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/bin/rspec:23:in `load'
from /Users/andreasalicetti/.rbenv/versions/2.2.3/bin/rspec:23:in `<main>'
最佳答案
请尝试删除以下一行或两行:
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/autorun'
没有它们,我的 RSpec 运行良好。
关于ruby-on-rails - 无法运行 rspec(未定义方法 `belongs_to' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23807218/
我想了解 Ruby 方法 methods() 是如何工作的。 我尝试使用“ruby 方法”在 Google 上搜索,但这不是我需要的。 我也看过 ruby-doc.org,但我没有找到这种方法。
Test 方法 对指定的字符串执行一个正则表达式搜索,并返回一个 Boolean 值指示是否找到匹配的模式。 object.Test(string) 参数 object 必选项。总是一个
Replace 方法 替换在正则表达式查找中找到的文本。 object.Replace(string1, string2) 参数 object 必选项。总是一个 RegExp 对象的名称。
Raise 方法 生成运行时错误 object.Raise(number, source, description, helpfile, helpcontext) 参数 object 应为
Execute 方法 对指定的字符串执行正则表达式搜索。 object.Execute(string) 参数 object 必选项。总是一个 RegExp 对象的名称。 string
Clear 方法 清除 Err 对象的所有属性设置。 object.Clear object 应为 Err 对象的名称。 说明 在错误处理后,使用 Clear 显式地清除 Err 对象。此
CopyFile 方法 将一个或多个文件从某位置复制到另一位置。 object.CopyFile source, destination[, overwrite] 参数 object 必选
Copy 方法 将指定的文件或文件夹从某位置复制到另一位置。 object.Copy destination[, overwrite] 参数 object 必选项。应为 File 或 F
Close 方法 关闭打开的 TextStream 文件。 object.Close object 应为 TextStream 对象的名称。 说明 下面例子举例说明如何使用 Close 方
BuildPath 方法 向现有路径后添加名称。 object.BuildPath(path, name) 参数 object 必选项。应为 FileSystemObject 对象的名称
GetFolder 方法 返回与指定的路径中某文件夹相应的 Folder 对象。 object.GetFolder(folderspec) 参数 object 必选项。应为 FileSy
GetFileName 方法 返回指定路径(不是指定驱动器路径部分)的最后一个文件或文件夹。 object.GetFileName(pathspec) 参数 object 必选项。应为
GetFile 方法 返回与指定路径中某文件相应的 File 对象。 object.GetFile(filespec) 参数 object 必选项。应为 FileSystemObject
GetExtensionName 方法 返回字符串,该字符串包含路径最后一个组成部分的扩展名。 object.GetExtensionName(path) 参数 object 必选项。应
GetDriveName 方法 返回包含指定路径中驱动器名的字符串。 object.GetDriveName(path) 参数 object 必选项。应为 FileSystemObjec
GetDrive 方法 返回与指定的路径中驱动器相对应的 Drive 对象。 object.GetDrive drivespec 参数 object 必选项。应为 FileSystemO
GetBaseName 方法 返回字符串,其中包含文件的基本名 (不带扩展名), 或者提供的路径说明中的文件夹。 object.GetBaseName(path) 参数 object 必
GetAbsolutePathName 方法 从提供的指定路径中返回完整且含义明确的路径。 object.GetAbsolutePathName(pathspec) 参数 object
FolderExists 方法 如果指定的文件夹存在,则返回 True;否则返回 False。 object.FolderExists(folderspec) 参数 object 必选项
FileExists 方法 如果指定的文件存在返回 True;否则返回 False。 object.FileExists(filespec) 参数 object 必选项。应为 FileS
我是一名优秀的程序员,十分优秀!