rspec-rails

Rspec : PG::ConnectionBad: PQsocket() can't get socket descriptor

ε祈祈猫儿з 提交于 2019-12-04 17:16:33
问题 I run my rspec and most of the test were failed. I got the same error for them, which is: Failure/Error: Unable to find matching line from backtrace ActiveRecord::StatementInvalid: PG::ConnectionBad: PQsocket() can't get socket descriptor: BEGIN I found a question that is similar to my problem, but there is no answer yet and I also tried the solution from this link, but it didn't make any differences for me. I opened my test console and run some simplest queries and it worked. 回答1: There may

Cucumber and Rspec

社会主义新天地 提交于 2019-12-04 08:12:04
Can anyone suggest me good source (Easy examples) for cucumber and rspec tutorials (rails 3)??? Edit: Actually I am looking for free online resources with good examples.. I think the RSpec Book is an excellent resource on Cucumber, RSpec and BDD. Agree - the RSpec Book provides a wealth of information. I found getting the flow was a big problem in the learning. The book gives you the quick intro, then dives into details and by the time you surface your head will be swimming. It takes a couple of goes of reading the book to get the finer points. Another great read is a blog post by Sarah Mei

Rails 3.1, RSpec: testing model validations

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 07:34:04
问题 I have started my journey with TDD in Rails and have run into a small issue regarding tests for model validations that I can't seem to find a solution to. Let's say I have a User model, class User < ActiveRecord::Base validates :username, :presence => true end and a simple test it "should require a username" do User.new(:username => "").should_not be_valid end This correctly tests the presence validation, but what if I want to be more specific? For example, testing full_messages on the errors

Rails 2.3 and rspec-rails compatability

ぐ巨炮叔叔 提交于 2019-12-04 07:28:31
What version of the rspec-rails gem is still compatible with Rails 2.3 branch (2.3.14 specifically)? I've tried 2.1.0 , but that one's also for Rails >= 3.0. Any other dependencies or version limitations that I should be aware of? Thanks. Version 1.3.4 is the latest supported version for Rails 2.x. http://rubygems.org/gems/rspec-rails/versions/1.3.4 来源: https://stackoverflow.com/questions/9274329/rails-2-3-and-rspec-rails-compatability

Rails FactoryGirl trait association with model after_create callback not setting vanity_url

▼魔方 西西 提交于 2019-12-04 04:52:38
问题 In my model, I have an after_create callback that triggers the method: class Job < ActiveRecord::Base after_create :update_vanity_url private def update_vanity_url self.vanity_url = '/jobs/' + company.slug + '/' + slug + '/' + id.to_s + '/' end end This sets up a custom url for my jobs, however, when I try to use this in my coupon factory it is not being saved. The coupon is created without a job assigned. Only when the coupon is used is it paired with one job. I referred to that as executed:

Mocking chain of methods in rspec

旧城冷巷雨未停 提交于 2019-12-04 03:43:05
There are a chain of methods which gets a user object. I am trying to mock the following to return a user in my Factory Girl @current_user = AuthorizeApiRequest.call(request.headers).result I can mock the object up until the call method but I'm stuck at mocking the result method allow(AuthorizeApiRequest).to receive(:call).and_return(:user) I found I need to use receive_message_chain So this worked for me. allow(AuthorizeApiRequest).to receive_message_chain(:call, :result).and_return(user) 来源: https://stackoverflow.com/questions/40571911/mocking-chain-of-methods-in-rspec

Access to request object in request specs

独自空忆成欢 提交于 2019-12-04 03:06:04
How can I set the request headers before doing the request on a request spec? I'm moving controller specs to request specs on my API using Rails. One thing I'm stuck on is that I have no access to a request object to allow the requests. On my controller specs, I have access to a method I created which signs a specific user: def sign_in(user) token = user.api_keys.first.token # note the request object being used in the next line request.env["HTTP_AUTHORIZATION"] = ActionController::HttpAuthentication::Token.encode_credentials(token) end This works fine on controller specs, I can safely do:

How to test strong params with Rspec?

一曲冷凌霜 提交于 2019-12-04 02:16:20
What is the actual strategy to test strong params filtering in Rails controller with Rspec? (Except shoulda matchers) How to write failing test and then make it green? Create 2 hashes with expected and all (with unsatisfied) parameters. Then pass all params to action and check that you object model receiving only expected params. It will not if you are not using strong parameter filters. Than add permissions to params and check test again. For example, this: # action def create User.create(params) end # spec it 'creates a user' do expect_any_instance_of(User).to receive(:create). with({name:

How to call a rake task in rspec

旧城冷巷雨未停 提交于 2019-12-04 01:59:19
I am trying to invoke a rake task in in my rspec. require "rake" rake = Rake::Application.new Rake.application = rake rake.init rake.load_rakefile rake['rake my:task'].invoke But i am getting error Failure/Error: rake['rake db:migrate'].invoke RuntimeError: Don't know how to build task 'rake db:migrate' Does anyone have a idea how we can invoke rake task in rspec code. Any help would be highly appreciated. Martin Fenner To pass in the arguments in square brackets to invoke : rake sim:manual_review_referral_program[3,4] becomes: rake['sim:manual_review_referral_program'].invoke(3,4) If your

Factory Girl / Capybara deleting records from database mid-test?

半城伤御伤魂 提交于 2019-12-03 23:39:30
Working with RSpec & Capybara, I'm getting an interesting test failure mode which goes away with a few subtle rearrangements of lines in the test case...stuff that shouldn't matter. I'm developing my own authentication system. It is currently working and I can login/out with the browser and the session works etc etc. However, trying to test this is failing. Something is going on that I don't quite understand, which seems to depend on the order of (seemingly) unrelated calls. require 'spec_helper' describe "Sessions" do it 'allows user to login' do #line one user = Factory(:user) #For SO, this