我正在为Ruby On Rails引擎编写Rspec测试。我的引擎为ActiveRecord模型提供了一个类方法is_a_limesurvey_participant(opts = {}),它使用类变量和关联对它们进行扩展。要测试我的TestModel扩展,我需要在不同且连续的RSpec上下文中多次初始化它,并提供不同的选项。为此,我需要取消定义我的TestModel,否则它将“记住”旧的设置。在受启发进行测试之前,我调用了以下实用方法
def reset_test_model
Object.send(:remove_const,'TestModel')
load Fi
我在一个规范中有以下代码:
it 'should save some favorite locations' do
user=FactoryGirl.create(:user) # not adding anything
而且它似乎没有向数据库中写入任何内容。FactoryGirl打算用这个在模型规范中写点东西吗?如果我从rails控制台运行,它确实会添加到数据库中。为什么rspec中的测试没有运行这个?这就是它的工作方式吗?
thx
我想测试一个我知道正在工作的销毁操作,但我想对它进行测试。 这是一个销毁操作。路线:DELETE /journals/:id(.:format) journals#destroy 在admin/journals.rb als.rb注册块中,使用controller块覆盖destroy方法。 ActiveAdmin.register Journal do
controller do
def destroy
# do stuff and redirect.
end
end
end 我的测试 require 'rails_helper'
R
在运行Rails 4.2、Ruby 2.2.0和Rspec 3.2时,我在运行Rspec时收到以下错误:
rake aborted!
PG::ConnectionBad: FATAL: permission denied for database "postgres"
DETAIL: User does not have CONNECT privilege.
-e:1:in `<main>'
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task
所以作为一个初学者,我正在学习Michael Hart的ruby on rails第二版教程!
当我使用集成测试模块运行命令行时
rspec test/integration/static_pages_test.rb
它没有显示Hartl得到了什么。相反,它显示的是:
/Users/Name/rails_testprojects/protego/test/integration/static_pages_test.rb:1:in `require': no such file to load -- test_helper (LoadError)
from /Users/Name
我正在为使用开源回购,并在执行bundle exec rspec时遇到以下失败
681个例子,3个失败的例子:
rspec ./spec/bin/compile_spec.rb:49 # compile script should work with the liberty WEB-INF case
rspec ./spec/bin/compile_spec.rb:65 # compile script should also work with the zipped up server case
rspec ./spec/bin/compile_spec.rb:82 # compile sc
我最近开始了Rails的开发。我遇到了春天的问题。
我使用Spring和Rspec来加速我的测试。虽然测试运行良好,但它似乎并没有像通常那样给我带来巨大的速度提升。我怀疑它没有正常工作。
我使用的是ruby 2.2.0和Rails 4.2
在安装过程中,我遵循了以下步骤:
向创业板文件中添加创业板'spring‘
捆绑安装
我使用bundle exec spring binstub --所有的--对可执行文件进行了编程。
使用bin/spring状态显示spring正在运行:
Spring is running:
16641 spring server | aut
我在做这个在线软件工程课程。我正在进行最后一次家庭作业,以调试一些遗留代码。我通过了所有的测试和rspec测试后,提交了家庭作业。为了玩这个应用程序,我也手动运行了几次(这个应用程序是一个博客站点-- bug是新的/编辑类别抛出了一个错误)。自动评分器给了我这个输出,基本上说所有的主要测试都失败了:
should support creating new categories [50 points] (FAILED)
should support editing existing categories [50 points] (FAILED)
should support editing ex
我有一个非常简单的测试场景,配置了RSpec、Capybara和Selenium:
require './spec_helper'
RSpec.describe 'test' do
title = 'My title'
context 'When I navigate to my page' do
before(:all) do
visit 'http://foo.com/'
end
it "the page title is #{title}" d
我刚刚开始测试第一Ruby &我在运行rakes开始解决问题时遇到了困难。
我认为是我的版本的RSpec或我的版本的Ruby导致了这个错误。
这是个错误
AT MacBook-Pro:01_temperature AT$ rake
(in /Users/AT/Desktop/learn_ruby)
/Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- temperature (LoadError)
from /Libra
我不明白为什么下面的Rspec测试没有通过-
require "rspec"
require_relative "file-to-be-tested"
describe Customer do
it "is valid with firstname" do
customer = Customer.new("handy")
expect(customer).to be_valid
end
end
对于相应的类别定义-
class Customer
attr_reader :
有没有人知道如何在rspec中使用gem来测试gem的控制器?我尝试过和,但没有成功。
我在gem中有一个控制器,如下所示:
module mygem
class PostsController < ::ApplicationController
def index
@posts = Posts.find(:all)
@other_var = 10
end
end
end
我希望在我的应用程序中有一个像spec/controller/post_controller_spec.rb这样的测试
describe PostsController do
我从视图规范中得到了一些奇怪的结果
Failure/Error: assert_select "div.fileinput-new.thumbnail"
ArgumentError:
wrong number of arguments (3 for 1)
好的,这似乎是不言自明的(虽然我不确定引用的3个参数是什么)。
然而,如果我再次运行套件,我可能会得到0错误。接下来是5个错误,与上面的类型相同,但引用了不同的DOM元素。
这些规格中没有什么特别之处。
describe do
build :object / create :object
@object = a