rspec

Why am I getting FactoryGirl wrong number of arguments error?

心已入冬 提交于 2019-12-24 07:17:58
问题 Having strange behavior from FactoryGirl in non-rails app. getting wrong number of arguments error...don't know why. gideon@thefonso ~/Sites/testing (master)$ rspec spec /Users/gideon/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb:6:in `define': wrong number of arguments (1 for 0) (ArgumentError) from /Users/gideon/Sites/testing/spec/factories.rb:1:in `<top (required)>' Here are the files involved... login_user_spec.rb require_relative '../spec_helper'

Difference between expect and is_expected.to in Rspec

爷,独闯天下 提交于 2019-12-24 06:38:51
问题 What is the difference between those keywords. In the following example, using expect passed the test, while is_expected.to failed it. it { expect validate_uniqueness_of(:access_token) } it { is_expected.to validate_uniqueness_of(:access_token) } Testing for class User , which is generated by Devise class User < ActiveRecord::Base devise :lockable, :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable validates :access_token, uniqueness: true before

Specs for controller inside a module (versionist)

我与影子孤独终老i 提交于 2019-12-24 05:49:06
问题 I'm creating an API in Rails and I use versionist to handle versions. I want to test API controllers, but I'm unable to create a valid request. My controller: class Api::V1::ItemsController < Api::V1::BaseController def index render json:'anything' end end My spec: describe Api::V1::ItemsController do describe "#create" do it "shows items" do get :index, format: :json end end end routes.rb: scope '/api' do api_version(:module => "Api::V1", :path => {:value => "v1"}, :default => true) do

How to test a nested form with RSpec and FactoryGirl?

萝らか妹 提交于 2019-12-24 05:38:09
问题 In my Rails project I have a User that can have many Projects which in turn can have many Invoices . Each Invoice can have many nested Items . class Invoice < ActiveRecord::Base attr_accessible :number, :date, :recipient, :project_id, :items_attributes belongs_to :project belongs_to :user has_many :items, :dependent => :destroy accepts_nested_attributes_for :items, :reject_if => :all_blank, :allow_destroy => true validates :project_id, :presence => true def build_item(user) items.build(:price

Rspec Capybara test with ajax call not updating record

社会主义新天地 提交于 2019-12-24 05:31:31
问题 I have a form where when a user submits an ajax form with a single name field, a record is created that belongs to a Template object. This all works fine manually, but for some reason when I test this via rspec its telling me that the association was not created. Why isn't the template object updated here? describe "edit page" do before(:each) do visit edit_admin_template_path(template) end context "form sections", js: true do it "allows admin to create one" do find("#btn-add-section").click

Spork is repeatedly re-running failing tests in autotest

人走茶凉 提交于 2019-12-24 05:11:48
问题 I have a new project that I am trying to get up and running with rspec, autotest and spork. I am using: rails 3.0.4 rspec 2.5.0 spork 0.9.0.rc3 autotest 4.4.6 Spork seems to be loading fine (I get a message that it is listening on a port), but when I run autotest with a failing test, it reruns that test over and over. It should just run the test, see that it is failing and stop. Any idea why this behavior is happening? Also, once I make the failing tests pass, autotest stops as it should. If

issue with stubs and rspec old syntax

こ雲淡風輕ζ 提交于 2019-12-24 04:54:08
问题 I am writing some code and using rspec but received a warning that the syntax is old and i can't quite figure out how i should be writing it instead? it "should calculate the value correctly" do mock_cards = [Card.new(:clubs, 5), Card.new(:diamonds, 10)] hand = Hand.new hand.stub(:cards) { cards } #stub out cards and have it return cards expect(hand.value).to eq (15) end The error message is as follows: Using stub from rspec-mocks' old :should syntax without explicitly enabling the syntax is

RSpec controller test error: controller does not implement method

扶醉桌前 提交于 2019-12-24 04:26:06
问题 I've written some custom code for Devise registration. Namely once a user hits the "sign up" button, Devise's generic code ensures that the user is saved correctly. But then, I want to go in and make sure that the user gets an associated Stripe customer account. Most of the code below is from Devise, except for a few lines that I added: class Users::RegistrationsController < Devise::RegistrationsController def create build_resource(sign_up_params) resource.save yield resource if block_given?

Testing Sidekiq workers using Rspec

守給你的承諾、 提交于 2019-12-24 03:54:06
问题 How do i test the following line of code invokes 'perform' in 5 mins using rspec? CustomSidekiqWorker.perform_in(5.minutes, parameter1) 回答1: If you've set Sidekiq to use inline processing while runnings tests like so: require 'sidekiq/testing' Sidekiq::Testing.inline! Then the following should work in your specs: expect(CustomSideWorker).to receive(:perform_in).with(5.minutes, parameter1) 来源: https://stackoverflow.com/questions/27899120/testing-sidekiq-workers-using-rspec

How to stub an object that still has to be loaded from the database in RSpec?

柔情痞子 提交于 2019-12-24 03:50:31
问题 I would like to check whether an object's association receives a certain method call. Problem is that I can stub the object's association, but when later on, the association is loaded from the database, the loaded object is not the same "fysical" object as my stubbed object. It has the same ID, but it is not the same "fysical" object, so the stub doesn't work anymore. What I currently have is (and this works!) it "should register the payment of the invoice if everything ok" do invoice =