rspec希望您的控制器规格在/spec/ controller中。我的控制器中包含了一些模块。据我所知,测试它们的唯一方法是创建一个虚拟控制器,将模块包含在其中,然后从那里进行测试。问题是模块规范在/spec/lib/module中,所以没有包含ControllerExampleGroup,这意味着我不能调用助手方法get "action“等。
我可以手动导入这些文件,这样我就可以完成大部分工作,但随后会出现以下错误:
Failure/Error: Unable to find matching
line from backtrace undefined method
`pat
我正在尝试为类的任何实例(通过any_instance)生成一个类方法。我的测试运行成功,但在测试结束时,当rspec试图重置any_instance存根时,它抛出了一个错误(无法从回溯中找到匹配的行)。下面是明显的罪魁祸首代码行(删除它就会删除错误):
Confetti::Config.any_instance.stub(:write_info)
完整错误如下所示。看起来存根应该(但没有)创建__rspec_original_dup方法,并且当重置发生时,它找不到预期的方法。
Failure/Error: Unable to find matching line from backtrac
我有一个类似的错误张贴在这里,但都不会解决我的问题。
我的文件'spec/request/news_controller_spec.rb‘如下所示:
require 'spec_helper'
describe "NewsController" do
include Devise::TestHelpers
describe "GET /news" do
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:u
我在做这个在线软件工程课程。我正在进行最后一次家庭作业,以调试一些遗留代码。我通过了所有的测试和rspec测试后,提交了家庭作业。为了玩这个应用程序,我也手动运行了几次(这个应用程序是一个博客站点-- bug是新的/编辑类别抛出了一个错误)。自动评分器给了我这个输出,基本上说所有的主要测试都失败了:
should support creating new categories [50 points] (FAILED)
should support editing existing categories [50 points] (FAILED)
should support editing ex
我最近将我的应用程序从Rails3升级到了Rails4,现在正在尝试运行单元测试。但是我在使用validate_uniqueness_of().scoped_to().的两个地方遇到了一个奇怪的错误
以下是其中一种情况下的完整错误:
1) Distribution should require case sensitive unique value for collaborator_id scoped to variant_id
Failure/Error: it { should validate_uniqueness_of(:collaborator_id).scoped_to(:v
我是在3个月前开始rspec的,我正在使用它在sinatra项目(使用ruby 2.1.1) .
我的规范中没有错误(它们在其他计算机上成功运行),但是当我自己运行它们的时候,我得到了每个例子的这个.
Failure/Error: Unable to find matching line from backtrace
ArgumentError:
wrong number of arguments (0 for 1)
# /home/vagrant/.rvm/gems/ruby-2.1.1/gems/rspec-mocks-2.14.6/lib/rspec/mocks.rb:10:
这是@tourdedave编写的示例代码
require 'allure-rspec'
require 'selenium-webdriver'
require 'uuid'
RSpec.configure do |config|
config.include AllureRSpec::Adaptor
config.before(:each) do
@driver = Selenium::WebDriver.for :firefox
end
config.after(:each) do |example|
i
rspec版本: 3.5 rails版本: 5.2
控制器:
def show
# Remove all source.
end
测试控制器:
describe 'GET #show' do
it 'returns not found' do
get :show, params: {id: post}
expect(response).to have_http_status(:not_found)
end
end
此测试用例将测试404状态,但得到500内部服务器错误:
expected the response to have st
我使用的是ruby "2.0.0“和'rails','~> 4.0.0‘和’rspec‘,"2.14.2”(引用于Gemfile )。我有两个完全不同的应用程序,我在这两个程序上都有相同的错误。
我用脚手架发电机做控制器。所以它也产生了我的控制器测试。尤其是,更新操作立即中断。测试代码
describe "PUT update" do
describe "with valid params" do
it "updates the requested product" do
produc
我有这样的请求规范
require 'rails_helper'
describe 'People API' do
describe 'GET /api/v1/people/lookup.json?phone_number=PHONE_NUMBER', :wip do
it 'returns a 200 status code' do
auth_get '/api/v1/people/lookup.json', phone_number: '91900199'
我正在尝试这样做:
describe "should fail on create if the name is shorter than 5 characters" do
group = Factory.build(:group, :name => "a")
group.should be_invalid
group.should have(1).error_on(:name)
end
但我得到以下错误:
/spec/models/group_model_spec.rb:22: undefined local variab
我在与RSpec做斗争,我只是无法让RSpec在我的Ruby中工作。即使在RSpec:官方主页的“立即开始”部分中提供的简单示例中也没有。
因此,我从正式示例中获取代码,并创建bowling.rb和bowling_spec.rb。当我尝试从控制台运行rspec时:
rspec bowling_spec.rb --format nested
我得到了这个输出:
require': no such file to load -- bowling (LoadError)
from C:/.../Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_
当我运行rspec时,我会收到以下错误消息
/Users/umezo/.rvm/gems/ruby-2.1.1@itsonme/gems/bundler-1.6.1/lib/bundler/runtime.rb:34:in `block in setup': You have already activated rspec-core 2.14.8, but your Gemfile requires rspec-core 2.13.1. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
我
当我做“rspec_junit_formatter”时有问题
包exec格式RspecJunitFormatter
我有这样的错误,怎么解决呢?
home/stasyan/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.4/lib/rspec/core/formatters/deprecation_formatter.rb:186:in `puts': Treating `metadata[:execution_result]` as a hash is deprecated. Use the attributes methods to access
我正在为使用开源回购,并在执行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应用程序中使用devise进行身份验证,但我无法使用RSpec测试任何模型。控制器规范可以正常工作,但我无法使模型规范工作。
我得到了这个错误:
Failures:
1) Group should create new group
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `env' for nil:NilClass
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/activ
在将--drb添加到.rspec文件后,我在运行spork时得到以下错误。我在mac上使用jruby-1.6.7
$ jruby -S rspec
NoMethodError: undefined method `read_all' for nil:NilClass
method_missing at /Users/larry/.rvm/rubies/jruby-1.6.7/lib/ruby/1.9/drb/drb.rb:1099
run at /Users/larry/.rvm/gems/jruby-1.6.7@entercamp/gems/rspec-
我运行:
$ bundle exec rspec spec/
并收到此消息:
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core.rb:78:in `require': no such file to load -- rspec/expectations (LoadError)
from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.0 .1/lib/rspec/core.rb:78
升级到最新的Rubymine6.3,在尝试使用规范配置运行所有规范时遇到了这个问题。查看日志看起来就像rubymine问题。知道怎么解决这个问题吗?
/Applications/RubyMine.app/rb/testing/patch/bdd/teamcity/spec/runner/formatter/teamcity/rspec3_formatter.rb:250:in `dump_summary': undefined local variable or method `count_notification' for #<Spec::Runner::Format
我试着开始我的rspec测试,然后
RAILS_ENV=test bundle exec rspec
我得到了:
/home/nitrous/poznan-workshops-2015/.bundle/gems/rspec-core-3.3.0/lib/rspec/core/example_group.rb:348:in `find_and_eval_shared': Could not find shared examples "template rend
ering action" (ArgumentError)
from /home/nit
这是我的代码:
#app/models/user.rb
class User < ActiveRecord::Base
def display_name
name.split(' ').try(:first)
end
end
#spec/models/user_spec.rb
require 'rails_helper'
RSpec.describe User, :type => :model do
let(:user) { FactoryGirl.create :user }
it "should retur
下面是我的规范文件:spec/api/v1/projects_spec.rb
require "spec_helper"
describe "/api/v1/projects", :type => :api do
context "projects viewable by this user" do
it "JSON" do
end
end
end
它包含了更多,但我删除了很多行,试图找到错误,但没有成功,错误是这样的:
Failure/Error: Unable to find matching li