rspec-rails

Testing Rails 3.1 mountable engine with Rspec

試著忘記壹切 提交于 2019-11-27 05:06:07
问题 I started making a Rails 3.1 engine, and I'm having a hard time testing it using rspec. First of all, if I run rails g integration_test whatever it creates a regular integration test in tests/integration instead of spec/requests (the rspec-rails gem is installed and required as a development dependency in the gemspec file) Also, when I run a spec test I get an error saying the table corresponding to the model I'm testing has not been created. I tried rake engine_name:install:migrations and

Rails 3 Tutorial Chapter 11 “Validation failed: Email has already been taken” error

一个人想着一个人 提交于 2019-11-27 01:57:51
问题 My trouble arose in Chapter 11 of the Ruby on Rails Tutorial here. I was seeing this rspec error: Failure/Error: :user => Factory(:user, :email => Factory.next(:email))) ActiveRecord::RecordInvalid: Validation failed: Email has already been taken first in user_spec.rb then in micropost_spec.rb . It was pretty puzzling. I thought the factory statements were generating a user in a fresh testing db each time autotest ran rspec. I checked out source files from the master branch with git and tried

expected true to respond to true?

六眼飞鱼酱① 提交于 2019-11-27 01:44:34
问题 I upgraded my rspec-rails to 3.0.1 and now I'm seeing this error on all of my tests Failure/Error: Sidekiq::Status::complete?(json.jid).should be_true expected true to respond to `true?` I can't find the solution nor what I'm missing. 回答1: From rspec 3.0, be_true is renamed to be_truthy and be_false to be_falsey The behavior has not changed. So (nil).should be_falsey (false).should be_falsey will pass, and (anything other than nil or false).should be_truthy will also pass From the changelog 3

Capybara tests with :js=>true… Routing Error: No route matches [GET] “/assets”

筅森魡賤 提交于 2019-11-27 00:35:05
问题 I'm getting a similar error in a number of tests when I add ":js => true" to them. eg: An error occurred in an after hook ActionController::RoutingError: No route matches [GET] "/assets" occurred at /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' I haven't been testing JavaScript-enabled stuff in my app before and have only just set up to do so by upgrading to Capybara 2 and installing Database Cleaner.

Cookies do not persist in Rspec on rails 3.1

女生的网名这么多〃 提交于 2019-11-26 21:36:47
问题 This is a problem with the cookies collection in a controller spec in the following environment: rails 3.1.0.rc4 rspec 2.6.0 rspec-rails 2.6.1 I have a simple controller spec that creates a Factory user, calls a sign in method which sets a cookie, and then tests to see if the signed in user may access a page. The problem is that all cookies seem to disappear between the authentication cookie being set and the "show" action being called on my controller. My code works fine when run in a

Rspec/Capybara loading in progress, circular require considered harmful

安稳与你 提交于 2019-11-26 20:31:14
问题 Unsure if this is a Capybara issue, but I just did a fresh install of Rails (4.1.1) and Rspec Rails (3.0.1) and I would like to use Capybara (2.3.0), but having never used it I'm running into issues. I created a "spec" in spec/features and the spec itself runs and passes as expected, but I get the following "warnings" when rspec is run. Any ideas? Do I just need to disable warnings at the ruby level or something? /Users/typeoneerror/.rvm/gems/ruby-2.1.2@doki/gems/mail-2.5.4/lib/mail/network

Controller spec unknown keyword: id

主宰稳场 提交于 2019-11-26 20:05:34
问题 I have simple action show def show @field = Field.find_by(params[:id]) end and i want write spec for it require 'spec_helper' RSpec.describe FieldsController, type: :controller do let(:field) { create(:field) } it 'should show field' do get :show, id: field expect(response.status).to eq(200) end end but I have got an error Failure/Error: get :show, id: field ArgumentError: unknown keyword: id How to fix it? 回答1: HTTP request methods will accept only the following keyword arguments params,

test a file upload using rspec - rails

拟墨画扇 提交于 2019-11-26 19:20:17
I want to test a file upload in rails, but am not sure how to do this. Here is the controller code: def uploadLicense #Create the license object @license = License.create(params[:license]) #Get Session ID sessid = session[:session_id] puts "\n\nSession_id:\n#{sessid}\n" #Generate a random string chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a newpass = "" 1.upto(5) { |i| newpass << chars[rand(chars.size-1)] } #Get the original file name upload=params[:upload] name = upload['datafile'].original_filename @license.format = File.extname(name) #calculate license ID and location @license

How is spec/rails_helper.rb different from spec/spec_helper.rb? Do I need it?

浪子不回头ぞ 提交于 2019-11-26 15:17:41
问题 I am doing the Rails Tutorial for the second time. When I enter this rails generate integration_test static_pages I get spec/rails_helper.rb and spec/spec_helper.rb instead of just spec/spec_helper.rb Now when I run my tests, they are longer (more "verbose") and slower than when I did this last time. I am wondering what the difference between the two files is, and if I did something wrong. Also, is there a way to get rid of the rails_helper.rb file without messing everything up? 回答1: rspec