我在我的Line模型中有这个
validates :home_team, :uniqueness => { :scope => [:visiting_team, :event_datetime],
:message => "** DOUBLE EVENT **" }
Run Code Online (Sandbox Code Playgroud)
我的规格中有这个
describe Line do
it { should validate_uniqueness_of(:home_team).scoped_to(:visiting_team, :event_datetime) }
Run Code Online (Sandbox Code Playgroud)
我收到这个错误......
失败:
1) Line
Failure/Error:
it { should validate_uniqueness_of(:home_team).scoped_to(:visiting_team, :event_datetime) }
Did not expect errors to include "has already been taken" when home_team is set to "arbitrary_string", got error:
# ./spec/models/line_spec.rb:7:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
任何想法为什么失败?
我刚刚将我的Capybara Gem从版本1升级到2.1.0(最新版).基于Capybara自述文件,我将以下几行添加到Spork.prefork块中的spec_helper.rb
require 'capybara/rspec'
require 'capybara/rails'
Run Code Online (Sandbox Code Playgroud)
但是,我收到了一个错误
/home/user_1/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.1.0/lib/capybara/rails.rb:6:in `block (2 levels) in <top (required)>': uninitialized constant Rails (NameError)
Run Code Online (Sandbox Code Playgroud)
我是否因为水豚的工作正常而错过了什么?
我有一个ActiveRecord模型,PricePackage.这有一个before_create回调.此回调使用第三方API进行远程连接.我正在使用工厂女孩,并希望将这个api存根,以便在测试期间建立新工厂时不会进行远程调用.
我正在使用Rspec进行模拟和存根.我遇到的问题是我的工厂中没有Rspec方法.rb
模型:
class PricePackage < ActiveRecord::Base
has_many :users
before_create :register_with_3rdparty
attr_accessible :price, :price_in_dollars, :price_in_cents, :title
def register_with_3rdparty
return true if self.price.nil?
begin
3rdPartyClass::Plan.create(
:amount => self.price_in_cents,
:interval => 'month',
:name => "#{::Rails.env} Item #{self.title}",
:currency => 'usd',
:id => self.title)
rescue Exception => ex
puts "stripe exception #{self.title} #{ex}, using existing price"
plan = 3rdPartyClass::Plan.retrieve(self.title)
self.price_in_cents = plan.amount
return true
end
end
Run Code Online (Sandbox Code Playgroud)
厂:
#PricePackage
Factory.define :price_package do |f|
f.title "test_package"
f.price_in_cents "500"
f.max_domains "20"
f.max_users "4"
f.max_apps "10"
f.after_build …Run Code Online (Sandbox Code Playgroud) activerecord mocking rspec-rails ruby-on-rails-3 factory-bot
我一直试图找出这个错误信息的含义,但无法弄明白.
这是完整的信息
DEPRECATION WARNING: Passing a template handler in the template name
is deprecated. You can simply remove the handler name or pass render
:handlers => [:jbuilder] instead. (called from realtime at
/Users/Arel/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/benchmark.rb:295)
Run Code Online (Sandbox Code Playgroud)
这是代码:
it "is logged in" do
post "/api/v1/login", user_login: {email: 'test@test.com', password: '12345678' }
response.status.should be(201)
end
Run Code Online (Sandbox Code Playgroud)
什么是template handler,为什么它认为我在传递它template name?什么模板?
编辑:
Sessions_controller.控制器由登录路径调用.
class Api::V1::SessionsController < Devise::SessionsController
before_filter :authenticate_user!, except: [:create, :destroy]
before_filter :ensure_params_exist
skip_before_filter :verify_authenticity_token
def create
resource = User.find_for_database_authentication(email: params[:user_login][:email])
return …Run Code Online (Sandbox Code Playgroud) 环境
Rails 4.2.0
ruby-2.2.1 [ x86_64 ]
devise 3.4.1
rspec-core 3.2.2
rspec-rails 3.2.1
Run Code Online (Sandbox Code Playgroud)
在我的/spec/rails_helper.rb中,我已经为使用和标记的spec文件包含了Devise助手type: :controllertype: :request
投机/ rails_helper.rb
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.strategy …Run Code Online (Sandbox Code Playgroud) 我在我的Rails应用程序中使用SendGrid的SMTP API来发送电子邮件.但是,我遇到了使用RSpec测试电子邮件标题("X-SMTPAPI")的麻烦.
这是电子邮件的样子(从ActionMailer :: Base.deliveries中检索):
#<Mail::Message:2189335760, Multipart: false, Headers:
<Date: Tue, 20 Dec 2011 16:14:25 +0800>,
<From: "Acme Inc" <contact@acmeinc.com>>,
<To: doesntmatter@nowhere.com>,
<Message-ID: <4ef043e1b9490_4e4800eb1b095f1@Macbook.local.mail>>,
<Subject: Your Acme order>, <Mime-Version: 1.0>,
<Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>,
<X-SMTPAPI: {"sub":{"|last_name|":[Foo],"|first_name|":[Bar]},"to":["foo@bar.com"]}>>
Run Code Online (Sandbox Code Playgroud)
这是我的规范代码(失败):
ActionMailer::Base.deliveries.last.to.should include("foo@bar.com")
Run Code Online (Sandbox Code Playgroud)
我也尝试了各种方法来检索标题("X-SMTPAPI")并且也没有工作:
mail = ActionMailer::Base.deliveries.last
mail.headers("X-SMTPAPI") #NoMethodError: undefined method `each_pair' for "X-SMTPAPI":String
Run Code Online (Sandbox Code Playgroud)
救命?
事实证明,我可以这样做来检索电子邮件标题的值:
mail.header['X-SMTPAPI'].value
Run Code Online (Sandbox Code Playgroud)
但是,返回的值是JSON格式.然后,我需要做的就是解码它:
sendgrid_header = ActiveSupport::JSON.decode(mail.header['X-SMTPAPI'].value)
Run Code Online (Sandbox Code Playgroud)
返回一个哈希,我可以这样做:
sendgrid_header["to"]
Run Code Online (Sandbox Code Playgroud)
检索电子邮件地址数组.
我为我的Rails 3.1应用程序添加了一些确认对话框,在此之前,他们进行了相应的测试.按照Railscast#257的模型,我在测试中添加了':js => true',添加了database_cleaner并相应地修改了spec_helper.rb文件.
当我运行测试时,Firefox启动,Capybara-Selenium在字段中填入相应的用户名和密码,但登录失败(即"无效的用户名/密码".)其他没有':js =的测试> true'并且还登录,仍然通过.
我想在将来为我的应用程序添加更多javascript,并且我正在避免破解Capybara以使其工作的解决方案(例如,在所有对话框上单击"确定".)
我可能会缺少什么想法?失败,有关如何调试此问题的任何建议?
谢谢.
我的GEMFILE中有以下内容:
group :development do
gem 'rspec-rails'
gem 'annotate-models'
end
group :test do
gem 'rspec'
gem 'webrat'
gem 'spork'
gem 'factory_girl_rails'
end
Run Code Online (Sandbox Code Playgroud)
'rspec'和'rspec-rails'之间有什么区别?
rspec中的事务夹具阻止调用after_commit,但即使我禁用它们也是如此
RSpec.configure do |config|
config.use_transactional_fixtures = false
end
Run Code Online (Sandbox Code Playgroud)
在after_commit callback不运行.
这是一个带有最新版本的rspec/rails的rails应用程序: git://github.com/sheabarton/after_commit_demo.git
我在Rails 4/Ruby 2上运行了一个应用程序.前端是用Ember开发的.
运行时rake spec,我得到以下异常.它似乎只发生在Rspec功能规范中(不是在开发模式下).此外,它通常只发生在我只运行一个功能规范时; 如果我运行整个测试套件,我通常不会收到错误.
由于对Rails的这种提交而发生错误:https: //github.com/rails/rails/commit/b33700f5580b4cd85379a1dc60fa341ac4d8deb2
但是,当然,我不知道这是真正的问题还是在调用堆栈中更深层次.我知道,如果我在Rails代码中做了一个小改动而不抛出那个错误,那么一切似乎都能正常工作并且我的测试通过了.但某些地方似乎正在尝试加载LocationsController,即使它已经加载了.
非常感谢任何帮助,因为这个让我真的很难过.
1) Locations Creating locations
Failure/Error: Unable to find matching line from backtrace
RuntimeError:
Circular dependency detected while autoloading constant LocationsController
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/dependencies.rb:460:in `load_missing_constant'
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/dependencies.rb:183:in `const_missing'
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/inflector/methods.rb:226:in `const_get'
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/inflector/methods.rb:226:in `block in constantize'
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/inflector/methods.rb:224:in `each'
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/inflector/methods.rb:224:in `inject'
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/inflector/methods.rb:224:in `constantize'
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/dependencies.rb:534:in `get'
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/activesupport/lib/active_support/dependencies.rb:565:in `constantize'
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/routing/route_set.rb:76:in `controller_reference'
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/routing/route_set.rb:66:in `controller'
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/routing/route_set.rb:44:in `call'
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/journey/router.rb:71:in `block in call'
# /usr/local/rvm/gems/ruby-2.0.0-p195@nepco/bundler/gems/rails-783c6711a4b4/actionpack/lib/action_dispatch/journey/router.rb:59:in `each' …Run Code Online (Sandbox Code Playgroud) ruby-on-rails capybara rspec-rails ruby-on-rails-4 ember-rails
rspec-rails ×10
rspec ×5
capybara ×3
factory-bot ×2
activerecord ×1
commit ×1
devise ×1
ember-rails ×1
mocking ×1
rspec2 ×1
selenium ×1
sendgrid ×1