rspec2

autotest and rspec giving different answers

爷,独闯天下 提交于 2019-12-11 02:42:56
问题 I have an application that I'm testing with rspec2 (2.6.4), capybara and selenium. When I run any request spec directly with rspec, the test passes. When I run the request specs with autotest they all fail with a message saying 'Cannot find a User with ID= * *. When autotest reloads the first request test automatically, it passes Autotest then reloads all tests and when it reaches the request tests they all fail again Users are being created by factory-girl and logged in using devise as

Rails 3.2.1: Calling undefined method in view causes test to hang for 30+ seconds

ぐ巨炮叔叔 提交于 2019-12-10 23:29:38
问题 I'm upgrading my app from 3.0.9 to 3.2.1 (ruby 1.9.3-p0, rvm, bundler) and one thing that I haven't been able to track down yet is this problem. I have a controller spec (in spec/controllers) that renders views for each example. The template that it renders can have any undefined method (like calling "- blahblah" in the haml) and it causes the test to hang for over 30 seconds. Here is the error: undefined local variable or method `blahblahblah' for #<#<Class:0x007fa84f76cc90>:0x007fa849c578c8

rspec - why does be_valid not work

房东的猫 提交于 2019-12-10 10:14:01
问题 I'm trying to do this: 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 But I get the following error: /spec/models/group_model_spec.rb:22: undefined local variable or method `be_valid' for #<Class:0x105d13ed0> (NameError) from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:132:in `module_eval' from /Library/Ruby/Gems/1.8/gems

Adding Controller Macros in Rspec

折月煮酒 提交于 2019-12-10 09:43:53
问题 Im trying to define some controller macros for Rspec. Im using rails 3 and have my macros defined in spec/support/macros/controller_macros.rb, that file looks like this: module ControllerMacros def self.login_admin #code end end in my spec helper I have: config.include(ControllerMacros, :type => :controller) So in my controller spec i just call login_admin in my admin tests but when ever i use the method i get undefined local variable or method `login_admin' for #<Class:0xb6de4854> (NameError

Rspec: How to suppress warnings and notices when running tests?

自闭症网瘾萝莉.ら 提交于 2019-12-10 01:56:51
问题 I was using Mysql database before and decided to switch to Postgresql and now, when I run my tests using rspec, I getting a lot of warnings and notices. WARNING: there is already a transaction in progress NOTICE: there is no transaction in progress should has link "Suspender" WARNING: there is already a transaction in progress NOTICE: there is no transaction in progress should has css "title" with text "Suspensão de anúncio" WARNING: there is already a transaction in progress NOTICE: there is

`require': cannot load such file — spec_helper (LoadError)

孤街醉人 提交于 2019-12-09 16:22:15
问题 I am creating bundler gem --test=rspec MyGem. in which I'm getting the repository structure. When I try to run the rspec code I get the following error: `require': cannot load such file -- spec_helper (LoadError) I then try to apply require relative but I still get an error: sheetal@ubuntu:~/sheetal/spec$ rspec sheetal_spec.rb \/home/sheetal/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- spec_helper (LoadError) from /home

Change Rubymine Rspec Color

邮差的信 提交于 2019-12-09 13:13:34
问题 Im using Rspec for Testing, but CAN'T find how to change the grey color in to Red and Green. Im testing so much that -especially when an error occurs- im having a hard time reading the passed and failures. Any help would be nice :) 回答1: I got it running by doing the following two things: In your run/debug configurations , enter -c in the Runner options field In your spec_helper.rb , add the following code: RSpec.configure do |config| config.tty = true end Additional info: http://rubyforge.org

CanCan load_and_authorize_resource triggers Forbidden Attributes

北战南征 提交于 2019-12-09 08:28:15
问题 I have a standard RESTful controller that uses strong parameters. class UsersController < ApplicationController respond_to :html, :js def index @users = User.all end def show @user = User.find(params[:id]) end def new @user = User.new end def edit @user = User.find(params[:id]) end def create @user = User.new(safe_params) if @user.save redirect_to @user, notice: t('users.controller.create.success') else render :new end end def update @user = User.find(params[:id]) if @user.update_attributes

Adding an error message to a custom validator

岁酱吖の 提交于 2019-12-08 15:58:30
问题 I have a custom validator and I am trying to output an error message when it fails but have been unable to do so. Could someone please tell me if I am doing this in the correct place. class User < ActiveRecord::Base self.table_name = "user" attr_accessible :name, :ip, :printer_port, :scanner_port validates :name, :presence => true, :length => { :maximum => 75 }, :uniqueness => true validates :ip, :length => { :maximum => 75 }, :allow_nil => true validates :printer_port, :presence => true, :if

rspec test, how to get the id in my case?

那年仲夏 提交于 2019-12-08 04:54:55
问题 I have a rsepc test for my controller, in my test, I have the following code snippet: ... params= {SOME PARAMETERS} post :create, params the above code test the create method in my controller, the create method create a instance object and save it into database. Now the problem is how can I get the id of the created instance object in database? It seems (I am not sure) I need to query the test database for this object, how to query? (PS: I know there is Factory can be used to create object