rspec

Why won't my rails spec run?

那年仲夏 提交于 2019-12-24 00:59:56
问题 When I try to run my spec, I get an uninitialized constant error. My spec looks like this: describe Facility do it { should have_many(:units) } it { should have_many(:facilities_users) } it { should have_many(:administrators) } it { should have_many(:facility_employees) } end The error is: facility_spec.rb:1:in `<top (required)>': uninitialized constant Facility (NameError) I certainly have a Facility model, so I'm not sure why this would happen. 回答1: You should try running rake spec instead

How can you universally override the get and post methods in RSpec?

限于喜欢 提交于 2019-12-24 00:55:26
问题 I'd like to override the get and post methods in RSpec. I want to do this in order to deal with subdomains in my tests. As far as I can tell, the only way to deal with subdomains is to alter the @request object before each call. I could do this before each and every test but that's going to lead to some really messy code. In an effort to keep things DRY I've tried using a config.before(:each) method in spec_helper.rb however this doesn't seem to be run in the same scope as the test and doesn

RSpec and Factory for testing next, prev records

China☆狼群 提交于 2019-12-24 00:51:46
问题 I have a User model which has methods for a next and previous user: def next_user User.where("id > ?", id).order("id ASC").first end def prev_user User.where("id < ?", id).order("id DESC").first end I'm trying to setup a test using RSpec and Factory girl to test this, and am not sure of the approach - i'm only getting started with TDD. I'm trying this: describe "previous_next" do let(:user) { FactoryGirl.create(:user) } let(:next_user) { FactoryGirl.create(:user) } it "should know the next

undefined local variable or method `root_path' (Rspec Spork Guard)

五迷三道 提交于 2019-12-24 00:47:22
问题 I have a newbie question :-) I'm "creating" an app, and I use M. Hartl's Tutorial to do so. But I have some problems since I decided to change my routes.rb. I know the question has already been posted, but the answer doesn't work for me, so I supposed I should ask a new one... Here are the codes : config/routes.rb root to: 'static_pages#home' match '/help', to: 'static_pages#help' match '/contact', to: 'static_pages#contact' match '/about', to: 'static_pages#about' spec/requests/static_pages

Rspec undefined local variable or method root_path

∥☆過路亽.° 提交于 2019-12-24 00:45:23
问题 I'm starting to use Rspec, but when I run bundle exec rspec I get an error /spec/requests/pages_spec.rb:20:in `block (2 levels) in <top (required)>': undefined local variable or method `root_path' for #<Class:0x00000102e46850> (NameError) I do not have Spork or Guard running so the question below shouldn't apply undefined local variable or method `root_path' (Rspec Spork Guard) I have added config.include Rails.application.routes.url_helpers in my spec_helper.rb file, but that did not help.

Using fixture_file_upload method Rails 4 Rspec

时光毁灭记忆、已成空白 提交于 2019-12-24 00:18:49
问题 I am testing the creation of my Image object with FactoryGirl and Rspec. Orignally i have been doing I am using photo { File.new(File.join(Rails.root, 'spec/fixtures', photo_name)) } but all of a sudden i am getting Paperclip::AdapterRegistry::NoHandlerError: No handler found for "#<File:0x00000003bf15c8> So after reading various posts I have changed to fixture_file_upload method but am having trouble creating the object. images.rb include ActionDispatch::TestProcess FactoryGirl.define do

Models created with FactoryGirl aren't available in controller

谁都会走 提交于 2019-12-23 22:25:46
问题 Original question I'm trying to write some feature tests with RSpec and Capybara and wonder, why my gon object is always empty allthough it was set in my controller: app/controllers/timetrackings_controller.rb : class TimetrackingsController < ApplicationController include ApplicationHelper before_action :authenticate_user! before_action :set_timetracking, only: [:update, :destroy] # GET /timetrackings def index projects = Project.all_cached.select('id, name, category, number, customer_id')

Deprecation warning for capybara-webkit requiring Qt version 5

自闭症网瘾萝莉.ら 提交于 2019-12-23 22:13:33
问题 When I run rspec, I get the following message: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.6. I was not aware I was using Qt, so know nothing of the implications of upgrading it. How do I upgrade it and what precautions should I take before doing so? 回答1: equaleffect's comment above led me to ImNaN answer, i.e. Comment out the capybara and capybara-webkit gems from your gemfile. Then: bundle gem uninstall capybara-webkit gem

Rspec tests failing with user being redirected when he should be given access to a Deal he owns

耗尽温柔 提交于 2019-12-23 20:08:52
问题 In my app, I give access to a customer to HIS own deals thanks to Cancan. It works when I try it "manually" with the browser but I fail at implementing the rspec tests . A customer can't access other customer's deals but only his own (the administrator give him access through Active Admin interface). It's like I am not managing to make rspec understand that the customer(through FactoryGirl) I create for tests should be allowed/associated with the deals I create for the tests (again through

How to test for input title/tooltip with rspec

社会主义新天地 提交于 2019-12-23 20:01:27
问题 How do you test for an input's title/tooltip with rspec? I wasn't testing for tooltips until I noticed a few stopped working and it wasn't caught by the other tests. (Had to add something so the question would be accepted) 回答1: How about: find('#element-locator')['title'].should == 'Expected title' 回答2: You can also look at the HTML attributes: expect(page).to have_selector("<selector>[data-content='<content>']") 来源: https://stackoverflow.com/questions/16698902/how-to-test-for-input-title