Tag: rspec

rspec堆栈级别太深

当我单独运行我的模型规格和控制器规格时,它没问题。 当我一起运行它们时,我得到一个堆栈溢出,字面意思:) $ bundle exec rspec –fail-fast spec/models …….. Finished in 0.44274 seconds 8 examples, 0 failures $ bundle exec rspec –fail-fast spec/controllers .. Finished in 0.99339 seconds 2 examples, 0 failures $ bundle exec rspec –fail-fast spec F Failures: 1) HerpController derp derp example Failure/Error: Unable to find matching line from backtrace SystemStackError: stack […]

如何使用RSpec测试javascript重定向?

我正在使用xhr:post与控制器交互,我期待重定向。 在js.erb中我有window.location.href =地址。 手动测试,浏览器可以正确重定向。 我如何使用RSpec进行测试? response.should redirect_to失败

validates_inclusion_of,acts_as_tree和rspec的问题

我有问题让rspec正常运行以测试validates_inclusion_of我的迁移如下所示: class CreateCategories < ActiveRecord::Migration def self.up create_table :categories do |t| t.string :name t.integer :parent_id t.timestamps end end def self.down drop_table :categories end end 我的模型看起来像这样: class Category Category.all.map(&:id), :unless => Proc.new { |c| c.parent_id.blank? } end 我的工厂: Factory.define :category do |c| c.name “Category One” end Factory.define :category_2, :class => Category do |c| c.name “Category Two” […]

如何运行多个特定的RSpec测试?

我有一个巨大的测试套件(> 5000次测试)需要一个小时才能运行。 400失败了,我有一个失败的测试列表,如下所示: rspec ./spec/models/fullscreen_hidden_view_state_spec.rb:116 # FullscreenHiddenViewState showing a playlist on third element – slide has all the right links and properties rspec ./spec/features/fullscreen/play_spec.rb:59 # View case in fullscreen presention mode Courtesy section when viewing the cases discussion via the cases hidden share token the Add To button should be hidden rspec ./spec/features/cases/index_spec.rb:204 # finding […]

未定义的方法’has_selector?’ 用于rspec装饰器

我有以下rspec测试: # spec/decorators/user_decorator_spec.rb require File.expand_path ‘spec/spec_helper’ describe UserDecorator do let(:user) { UserDecorator.new build(:user, level: build(:level)) } subject { user } its(:avatar) { should have_selector ‘h6’ } end 我得到错误: Failure/Error: its(:avatar) { should have_selector ‘h6′ } NoMethodError: undefined method `has_selector?’ for # # ./spec/decorators/user_decorator_spec.rb:7:in `block (2 levels) in ‘ 我尝试了流行的建议: before { ApplicationController.new.set_current_view_context } 但后来它说undefined method […]

WebMock:Rspec – 使用JSON响应测试Facebookvalidation

我很难为我的程序编写规范,因为我需要在填写所有正确的格式信息后validationfacebook ID。 我的facebook ID是从JSON响应中检索的,所以我不知道如何在我的规范中描述它。 我对这个领域很陌生,而且我已经被困在这一点很长一段时间了。 如果有一些示例代码可以帮助我,我将不胜感激。 以下是我的半成品规格。 场景:如果用户名和fbid相同,则使用用户给定的Fbid通过使用“ http://graph.facebook.com ”(JSON响应)来validationFacebook页面。 我的githuburl: https : //github.com/amycheong/company_list 更新:我使用过WebMock但最终获得: 1) Companies new company create with valid information correct facebook id should validate fbid Failure/Error: Company.validate_fbid(‘pepsi’)[‘username’].should == “pepsi” WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: GET http://graph.facebook.com:443/pepsi with headers {‘Accept’=>’*/*’, ‘User-Agent’=>’Ruby’} You can stub this request with the following […]

测试时,错误的URI(不是URI?) Rspec的

我有这些奇怪的问题,我不知道如何解决它。 如果可以,请你帮助我。 这是测试结果: 1) Admin can edit a hotel Failure/Error: visit edit_admin_hotel_path(hotel) URI::InvalidURIError: bad URI(is not URI?): # ./spec/requests/admin_spec.rb:32:in `block (2 levels) in ‘ 2) Admin can edit a user Failure/Error: visit edit_admin_user_path(admin) URI::InvalidURIError: bad URI(is not URI?): # ./spec/requests/admin_spec.rb:54:in `block (2 levels) in ‘ rake routes我显示了很好的用户和酒店编辑路线: edit_admin_hotel GET /admin/hotels/:id/edit(.:format) admin/hotels#edit edit_admin_user GET /admin/users/:id/edit(.:format) admin/users#edit […]

Selenium无法找到’spec’文件夹

因此,我正在尝试建立我的本地系统,以帮助完成仅使用rails的雇主的现有项目。 他们希望我主要关注rspec测试,因为项目几乎是function性的,我需要充实他们错过的东西。 但是,我无法获得’rake spec’来构建我的测试文件夹。 实际上,测试文件夹包含一些使用Selenium的基本用户登录测试(我没有写它们)。 以下是错误的跟踪: /opt/local/lib/ruby/gems/1.8/gems/selenium-client-1.2.18/lib/selenium/rspec/spec_helper.rb:2:in ‘require’: no such file to load — spec (LoadError) from /opt/local/lib/ruby/gems/1.8/gems/selenium-client-1.2.18/lib/selenium/rspec/spec_helper.rb:2 from /Users/cliffhess/ampms/spec/integration/user_registration_name_not_blank_spec.rb:5:in ‘require’ from /Users/cliffhess/ampms/spec/integration/user_registration_name_not_blank_spec.rb:5 from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in ‘load’ from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in ‘load_spec_files’ from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in ‘map’ from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in ‘load_spec_files’ from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in ‘run’ from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in ‘run_in_process’ from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in ‘run’ from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in ‘autorun’ from /opt/local/lib/ruby/gems/1.8/bin/rspec:19 rake aborted! 事实上,我很确定我理解这个问题(也许?)。 selenium-clients的spec_helper.rb中的第2行说require ‘spec’ ,如果我没弄错的话,就是说selenium-client应该包含一个名为spec的文件夹,其中包含所有的rspec内容。 […]

使用RSpec测试导轨金属/机架?

假设我有一个名为Preview的Metal类。 如何使用RSpec进行测试? 当我尝试: require ‘spec_helper’ describe Preview do it “should return the posted content” do post “/preview”, :content => “*title*” response.body.should == “*title*” end end 我明白了: undefined method `post’ for # 似乎RSpec没有加载:post方法,如果测试没有显式为Controller。 我试过指定:type => :controller无济于事。

rspec不报告错误行数

对于我的几乎所有规格,当rspec报告错误时,它会告诉我路径末尾的行号,例如 rspec ./spec/controllers/eclubs_controller_spec.rb:21 但是在我的一个规范中,它会报告错误位置 rspec ./spec/controllers/eclubs/members_controller_spec.rb[1:1:2:3:1] 在块的嵌套方面可能有意义,但坦率地说是相当神秘的。 有效的规范的顶部看起来像这样 require ‘rails_helper’ describe EclubsController do 并且不起作用的那个看起来像这样 require ‘rails_helper’ describe Eclubs::MembersController do 我在两个文件中看到的唯一区别是一个控制器是命名空间,但我有其他命名空间控制器正确报告错误行。 是什么造成的?