我的spec_helper.rb
require 'simplecov'
SimpleCov.start 'rails'
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails
我在rspec-core代码库()中问过这个问题,但之后我觉得这不是提问的合适地方。
假设我有这样一个组:
it { should be_a Array }
it { should include :something }
it { should include :another }
如果第一个示例失败,我可以阻止rspec运行示例2和3吗?是的,我知道我可以加入他们来解决这个问题,但仍然是这样。
对不起,我的英语
UPD。我想对此补充一些解释。我之所以想要这个,是因为我厌倦了如果主题被bugged (或者类似的东西),从不同的示例中得到3个相同的错误消息。即使你没有过度使用像我这样的应该在线
我想为以下形式的代码编写一个单元测试: class Foo
def bar(obj)
return nil unless obj&.foo
obj.bar
end
end 下面是示例测试: RSpec.describe Foo do
subject { Foo.new.bar(obj) }
context 'when obj is nil' do
let(:obj) { nil }
it 'does not call :foo' do
expect(obj).to_not receive(
最后两个测试工作individually...but当两者都设置为运行(非挂起)时,我会遇到问题。
问:我可以创建一个将两者合并为一个的测试吗?这看起来怎么样?(是的,我是rspec新手)
require_relative '../spec_helper'
# the universe is vast and infinite....and...it is empty
describe "tic tac toe game" do
context "the game class" do
before (:each) do
我是RSpec的新手,我想创建一个运行规范的自定义顺序,我希望最重要的规范首先运行,然后运行不太重要的规范,以此类推,直到最不重要的规范。Rspec已经有了默认的全局排序:defined,但我想覆盖它并创建我自己的自定义排序。我读过一篇关于这方面的文档(“ "),但不明白如何实现它。如果你们能发布一些带有解释的示例代码,将不胜感激。
这是我的spec_helper.rb文件:
RSpec.configure do |config|
#config.register_ordering :global do |examples|
# model, other = examples.
今天,我遇到了一个非常奇怪的问题我的规格。当我在没有指定任何特定dir/文件的情况下运行spec命令时,我的测试运行得很好,都是绿色的。但是,如果我指定一个dir或文件,rspec会抛出很少(随机的)错误,这取决于我是否在spring中使用rspec。更重要的是,昨天,就在我的工作结束之前,一切都很顺利。从那以后,我没有碰过任何东西,现在由于某种原因,它已经坏了。情况如下:
rspec spec/requests/api/v1/users_spec.rb
结果:
uninitialized constant FactoryGirl
spring stop; spring rspec s
每当我想要创建一个用户时,我都想删除FactoryGirl.build(:user),所以我添加了以下行:
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
给spec_helper.rb。但是这会产生以下错误:
`method_missing': `build` is not available on an example group (e.g. a `describe` or `context` block). It is only available from within
我更喜欢以随机顺序运行我的RSpec (2.14)规范,所以我添加了
config.order = 'random'
到我的spec_helper
但是,对于一个并且只有一个文件,我需要按照它们的编写顺序运行它们。
我已经修改了我的文件,如下
describe ApiAuthentication do
RSpec.configure do |config|
config.order = 'defined'
end
it'....'
end
end
但它们仍然按随机顺序执行。
有没有办法只为一个文件指定定义的顺序?
谢谢
使用rspec和selenium webdriver for chrome,我编写了如下格式的代码:
describe x do
[some code]
context y do
[some code]
it a do
[more code]
end
end
context z do
[some other code]
it b do
[even more code]
end
end
end
直观地看,程序流应该直接进入程序,进入上下文y,然后执行'it a do‘语句。然而,在它完成上下文y中
在将项目从Rails 6.0升级到6.1之后,RSpec在任何控制器或请求规范上都失败了,这些控制器或请求规范的结果是包含任何形式的_url或_path助手的视图文件。
最简单的例子可以写成;
it 'gets blah' do
get '/blah'
end
如果/blah只是有一些文本,没有什么会爆炸,然而,如果我们添加<%= root_path %>到该视图(根设置),那么我将得到这个错误;
Failure/Error: <%= root_path %>
ActionView::Template::Error:
我想以固定的顺序运行用rspec/capybara编写的功能规范,如下所示:
signup_spec.rb
login_spec.rb
project_creation_spec.rb
project_migration_spec.rb
的--order特性表明
Use the --order option to tell RSpec how to order the files, groups, and
examples
我如何使用.rspec文件来提及通过我的要求?
我有一个shell脚本,其中的测试用例按如下顺序运行:
rspec spec/features/signup_spec.rb
我正在尝试在Rspec中运行这段watir代码,同时我也在尝试并行运行测试用例。但它一个接一个地运行。有没有什么办法可以实现并行运行? require 'rspec'
require 'watir'
a=[]
2.times do
a<<Thread.new do
describe 'My behaviour' do
it 'should do something' do
b = Watir::Browser.new
b.goto 'www.google
我有一个非常简单的测试场景,配置了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
我将lib文件夹下的模块规格放到了spec/lib中,但我运行的rspec和spec spec/都无法在spec/lib中测试规格。
是否需要为此进行配置?我使用的是rails 3.2.0,下面是我的spec_helper.rb
require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
Spork.prefork do
# Loading mor