Tag: rspec

无法修改冻结数组(TypeError) – config / application.rb:42:in << <<':

我有一个rails 3应用程序,我正在尝试进行测试。 我执行以下命令rspec spec / controllers /并得到以下错误: /config/application.rb:42:in `<<': can't modify frozen array (TypeError) from c:/Users/#####/documents/#####/config/application.rb:42 它指向我在下面提供的config / application.rb文件。 require File.expand_path(‘../boot’, __FILE__) require ‘rails/all’ # If you have a Gemfile, require the gems listed there, including any gems # you’ve limited to :test, :development, or :production. Bundler.require(:default, Rails.env) if defined?(Bundler) module PadOnRails class Application < […]

Rails RSpec路由:测试操作:除了不路由

相当简单的问题(我想过),但我遇到了一些问题: 在Rails 3.1.0.rc6 / RSpec 2.6.0中,我正在尝试测试我的’产品’资源的路由,如下所示: resources :products, :except => [:edit, :update] 有效操作的路由有效,但我想确保编辑和更新路由不可调用。 这是我正在尝试的: it “does not route to #edit” do lambda { get(“/products/1/edit”) }.should raise_error end 失败/错误:lambda {get(“/ products / 1 / edit”)}。应该是raise_error预期exception但没有引发任何内容#。/ spec /routing / products_routing_spec.rb:11:在`block(3 levels)in’ ……然而,当我跑的时候 it “does not route to #edit” do get(“/products/1/edit”).should_not route_to(“products#edit”, :id => “1”) end 我明白了 失败/错误:get(“/ […]

我的控制器的rspec测试返回nil(+工厂女孩)

我正在学习Rails上的rspec和工厂女孩的测试,我无法让它们工作。 我的用户控制器如下所示: class UsersController < ApplicationController def index @users = User.all.order(:first_name) end end 和测试: require ‘spec_helper’ describe UsersController do before(:each) do @user1 = FactoryGirl.create(:user, first_name: “B”, last_name: “B”, uid: “b”) @user2 = FactoryGirl.create(:user, first_name: “A”, last_name: “A”, uid: “a”) end describe “GET index” do it “sets a list of users sorted by first name” do […]

Capybara,Devise,CanCan和RSpec集成测试:有效签到302重定向到example.com

更新:请参阅文章的结尾,了解规范现在如何工作,我的规格/请求中的规格而不是规格/控制器。 仍然想知道如何获得一个有效的登录用户与我的控制器进行集成测试。 我第一次使用Devise和CanCan,并且很难进行最基本的集成测试,我正在validation登录的用户是……好……登录。我已经阅读了无数post和处理Devise和RSpec集成测试的答案(即通过https://github.com/plataformatec/devise/wiki/How-To%3a-Test-with-Capybara,http:// schneems直接访问会话来加速它们.com / post / 15948562424 / speed-up-capybara-tests-with-devise ,以及Capybara,RSpec和Devise:通过绕过慢速登录和直接设置会话,可以更快地进行集成测试吗?但我一直无法做到得到一个标准的工作按预期工作,我很困惑: 开发环境工作正常(可以登录并重定向到正确的页面,导航登录链接更改为注销等)。 test.log表示没有问题,直到302重定向到http://www.example.com而不是我的root_path。 对于具有不同解决方案的类似问题的大量用户,我显然不是唯一一个遇到此问题的人,因为会话的各个方面等在不同场景中不可用。 剥离测试: subject { page } describe ‘should be able to log in’ do before do visit ‘/users/sign_in’ user = FactoryGirl.create(:admin) #user.add_role :admin fill_in ‘Username’, with: user.username fill_in ‘Password’, with: user.password click_on ‘Sign in’ end it { should have_link ‘Logout’ } end […]

使用RSpec和Capybara检查图像和图标的存在

有没有一种很好的方法来检查使用rspec和水豚的图像和favicons的存在? 我可以查看favicon和图像的DOM,但我希望能够检查这些图像是否也加载。 这对rspec和水豚有可能吗?

如何在RSpec中测试send_data? 或者……在这种情况下我应该测试什么?

使用RSpec测试以下代码的最佳方法是什么? 我应该测试什么? show动作打开一个文件并对其进行流式处理。 此外,如果操作依赖于某处存在的文件,我可以测试吗? def show image_option = params[:image_option] respond_to do |format| format.js format.pdf {open_bmap_file(“#{@bmap.bmap_pdf_file}”, ‘application/pdf’, “#{@bmap.bmap_name}.pdf”, “pdf”, “pdf”)} format.png {open_bmap_file(“#{@bmap.bmap_png_file}”, ‘image/png’, “#{@bmap.bmap_name}.png”, “png”, image_option)} end end private def open_bmap_file(filename, application_type, send_filename, format, image_option = nil) filename = “app/assets/images/image_not_available_small.png” unless File.exist? filename path = Bmap.bmaps_pngs_path case image_option when “image” filename = “#{@bmap.bmap_name}.png” when “large_thumbnail” filename […]

在RSpec中是否存在与Cucumber的“情景”相同或者我使用RSpec的错误方式?

我对Cucumber的情景的简洁性和实用性印象深刻,它们是测试不同情况的一种很好的方式。 例如黄瓜情景 Feature: Manage Users In order to manage user details As a security enthusiast I want to edit user profiles only when authorized Scenario Outline: Show or hide edit profile link Given the following user records | username | password | admin | | bob | secret | false | | admin | secret […]

测试(使用RSpec)Rails环境之外的控制器

我正在创建一个gem,它将为将使用它的Rails应用程序生成一个控制器。 在尝试测试控制器时,这是一个试错过程。 在测试模型时,它非常简单,但在测试控制器时,不包括ActionController :: TestUnit(如此处所述)。 我试过要求它,以及Rails中所有类似的声音,但它没有奏效。 我需要在spec_helper中要求测试工作吗? 谢谢!

从字符串编译ERB代码时出错

我正在为我的视图助手(Rails 4.0)编写一些测试,并尝试在执行它的字符串中编译ERB代码。 但是,为了简单起见,我在rails form helper中使用了一个常见的方法,并收到相同的错误: Failure/Error: ERB.new(template).result SyntaxError: (erb):1: syntax error, unexpected ‘)’ …out.concat(( field_set_tag do ).to_s); _erbout.concat “\n\t\… … ^ (erb):4: syntax error, unexpected end-of-input, expecting ‘)’ ; _erbout.force_encoding(__ENCODING__) ^ 这是我正在执行的代码: template = <<-TEMPLATE Lorem Ipsum TEMPLATE ERB.new(template).result 我发现了一些使用<%而不是<%=但这会导致Lorem Ipsum成为唯一的输出。 我也尝试过使用HAML而不是ERB,但结果却类似。 如何使用字符串中的field_set_for帮助程序将模板输出 Lorem Ipsum ?

Capybara方法未定义

我不能让水豚工作。 我正在使用capybara 2.0.0 我收到这个错误 Failure/Error: visit “/users/sign_in” NoMethodError: undefined method `visit’ for # 在这个规范上 规格/请求/ forgot_password_spec.rb describe “forgot password” do it “redirects user to users firms subdomain” do visit “/users/sign_in” end end 我没有得到任何错误,它找不到水豚,它包含在spec_helper.rb中 spec_helper.rb require ‘rubygems’ require ‘spork’ require ‘database_cleaner’ Spork.prefork do ENV[“RAILS_ENV”] ||= ‘test’ require File.expand_path(“../../config/environment”, __FILE__) require ‘rspec/rails’ require ‘capybara/rspec’ require ‘rspec/autorun’ require […]