我正在努力将我的项目的测试套件迁移到rspec。在试图访问我的设备时,我得到了以下错误:
零的未定义方法‘[]:NilClass
下面是一个示例规范文件:
require 'rails_helper'
feature "edit contacts" do
fixtures :contacts
before(:all) do
@thing = contacts(:two)
end
scenario "do a thing" do
visit new_contact_path
end
end
在调用b
我正在运行Rails 4,试图设置一些与Rspec和Capybara的集成测试。我想派警卫去做“宙斯测试”。每当我做出改变。问题是,无论何时调用Capybara DSL中的任何内容,或者每当我尝试使用路由帮助器时,都会出现如下错误:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_1:0x007f55682c6d60>
如果我将root_path替换为'/‘,它将得到:
undefined method `visit
我正在努力学习rspec。我似乎不能测试rails控制器方法。当我在测试中调用该方法时,rspec只返回一个未定义的方法错误。下面是我的测试示例
it 'should return 99 if large' do
GamesController.testme(1000).should == 99
end
下面是错误:
Failure/Error: GamesController.testme(1000).should == 99
NoMethodError:
undefined method `testme' for GamesController:Cla
我正在使用AWS Cloud9 (Rails v.5.0.0, Ruby v.2.6.3)创建一个rails应用程序,并成功地用gem install rspec安装了rspec,并将gem 'rspec-rails'添加到了did文件中的:development, :test块中,并执行了bundle install操作
Problem当我试图在终端中运行命令rails g rspec:install时,我得到以下信息:
Running via Spring preloader in process 7356
Could not find generator 'rsp
这里有点混乱,我正在rails应用程序上运行rspec测试,并有一个模型规范:
it { should validate_uniqueness_of(:email).case_insensitive }
这是对电子邮件对象的1次of3测试,它一直失败,但有以下错误:
1) User should validate that :email is case-insensitively unique
Failure/Error: it { should validate_uniqueness_of(:email).case_insensitive }
ArgumentError:
SMT
我正在尝试将一个旧项目(休眠一年)从Rails 3.1和Rspec 2.7升级到Rails 3.2和Rspec 2.12。
最初升级到Rails 3.2很顺利,应用程序也正常工作,但在Rspec下运行测试产生了许多关于以下方面的警告:
DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern
will be no longer included automatically. Please define instance methods
directly in RSpec::Rails::Test
我正在从factory_girl (2.0.2到3.4.2)和factory_girl_rails (1.1.0 -> 3.4.0)升级的过程中,我在rspec测试中遇到了工厂女孩的问题。
我想我已经成功地修改了我的工厂来处理新的语法,并删除了引入相同文件的多个副本的额外的require语句。我的服务器现在启动了,所以我知道factories.rb文件被正确解析了。
现在,当我运行我的rspec测试时,我得到了这个错误:
NoMethodError:未定义#的方法` `FactoryGirl‘
it 'can be created' do
course = Facto
在看了Corey的演讲和阅读了Avdi的之后,我正在设置我的新Rails3.2应用程序,以利用这些概念。
为了让一切正常工作,我从这个示例规范文件开始。
# spec_no_rails/projects/financials_spec.rb
require_relative '../spec_no_rails_helper'
class DummyProject
include Modules::Projects::Financials
end
describe Modules::Projects::Financials do
it 'should have
我希望确保我的EventNotifier对象捕获并记录Rails记录器的异常,因此我使用rspec模拟编写了以下rspec测试:
describe EventNotifier do
before(:all) do
RSpec::Mocks::setup(self)
end
it 'logs exception on error' do
error = RuntimeError.new('simulated for tests')
EventDispatcher.should_receive(:dispatch).with(
当我运行rspec时,会得到以下错误:
Failures:
1) User
Failure/Error: it { should validate_presence_of :email }
NoMethodError:
undefined method `validate_presence_of' for <RSpec::ExampleGroups::User:0x007f8177ff3408>
# ./spec/models/user_spec.rb:5:in `block (2 levels) in <top (requi
在Rails 3中测试作用域的最好方法是什么?在rails 2中,我会这样做:
Rspec:
it 'should have a top_level scope' do
Category.top_level.proxy_options.should == {:conditions => {:parent_id => nil}}
end
这在rails 3中失败了,并出现"undefined method `proxy_options‘for []:ActiveRecord::Relation“错误。
人们如何测试使用正确的选项指定了作用域?我看到你可以检
我试图在Rails API中为"show“操作编写一些测试。
require 'rails_helper'
RSpec.describe AirlinesController, type: :controller do
describe "GET #show" do
before(:each) do
@airline = FactoryGirl.create(:airline)
get :show, id: @airline.id
end
it "should return the airl
对于测试来说,这是相当环保的,但我遵循的是一个简单的udemy课程。我使用RSpec文档在rails中设置RSpec来尝试一些测试。但我遇到了一个问题,在我的一生中,我不知道.
require "rails_helper"
RSpec.describe User, type: :model do
subject { described_class.new("John") }
it "initializes a name" do
expect(subject.name).to eq("John")
end
我是ruby on rails的新手。当我在comment_spec.rb上运行rspec时,我得到了一个未定义的方法错误
1) after_save calls 'Post#update_rank' after save
Failure/Error: request.env["HTTP_REFERER"] = '/'
NameError:
undefined local variable or method `request' for #<RSpec::ExampleGroups::AfterSa
在我的rails3应用程序中,我安装了rspec。但是,当我在控制台中运行rspec命令时,它给出了以下错误。
C:\myapp>rspec spec
'rspec' is not recognized as an internal or external command,
operable program or batch file.
请帮帮忙。
提前谢谢。
我正在为rails中的Capyabara编写规范。在这里,我发现了在特性规范之间共享公共代码的文章。链接:
但是当我在rails规范中使用它的模块方法'sign_in‘时,它会出现“未初始化的常量sign_in'”错误。
describe "GET /" do
## include Features::SessionHelpers
before :each do
sign_in
end
....
如何正确导入rspec中的辅助模块?谢谢。
堆垛工,
在RSPEC中运行此规范时,我一直遇到一个错误。我正在使用:
rspec-核心(3.5.3) rspec-支持(~> 3.5.0) rspec-期望(3.5.0)
下面是我使用的规范:
require 'rails_helper'
RSpec.describe Service, type: :model do
it "has a valid factory" do
expect(service).to be_valid
end
end
这是一家工厂里的女孩:
FactoryGirl.define do
factory