rspec2

Object.save failed in spec data validation

折月煮酒 提交于 2019-12-12 02:46:15
问题 Here is the failed spec code for create in customer controller: describe CustomersController do before(:each) do #the following recognizes that there is a before filter without execution of it. controller.should_receive(:require_signin) controller.should_receive(:require_employee) end render_views describe "'create' successful" do before(:each) do category = Factory(:category) sales = Factory(:user) @customer = Factory.attributes_for(:customer, :category1_id => category.id, :sales_id => sales

spec with guard, rails 3.1.1, and ruby 1.9.3 getting cannot load such file errors

*爱你&永不变心* 提交于 2019-12-12 01:49:27
问题 HI all I just recently installed rvm and all that good stuff on my macbook air and I started my rails 3.1.1 app with ruby 1.9.3. In my gem file I put down guard and rspec, now when I try and run rspec by itself or with guard I get errors thrown at me and I'm not sure why, the output I get when I run is such, phantom:tasks maxmarze$ guard Please install rb-fsevent gem for Mac OSX FSEvents support Using polling (Please help us to support your system better than that). Please install growl

command be_true seems not to work in Rspec 2.1

只谈情不闲聊 提交于 2019-12-11 17:47:12
问题 I have this problem in RSPEC: be_true and be_false seems not to be working in Rspec 2.1 . This is my specs file for the class Zombie : spec/lib/zombie_spec.rb require "spec_helper" require "zombie" describe "A Zombie" do # your examples (tests) go here it "is named Ash" do zombie=Zombie.new zombie.name.should=="Ash" end it "has no brains" do zombie= Zombie.new #zombie.brains.should < 1 zombie.brains.should be <1 end it "is alive" do zombie=Zombie.new zombie.alive.should==false end it "is

Using Rails default exception translation in specs

北城以北 提交于 2019-12-11 13:57:22
问题 My controller is throwing ActiveRecord::RecordNotFound which is what to be expected to be translated into 404. Now I want to test this behaviour in my controller spec, but it gets exception rather than response_code equal to 404. How to make it get this code instead? 回答1: When Rails raise a ActiveRecord::RecordNotFound it simply telling you that ActiveRecord was not able to find a resource in your database (usually using find ). It is your responsability to catch the exception and to do

view spec fails with “Query does not return ResultSet”

喜欢而已 提交于 2019-12-11 07:29:19
问题 Just trying to do a simple view spec. When I first create this spec and run it, it worked great. But later on when I needed to create the model class (app/models/request.rb) it starts failing with the following error: Failure/Error: render ActionView::Template::Error: query does not return ResultSet Here is my view spec: require 'spec_helper' describe "requests/new.html.erb" do it "renders a form to reate a request" do assign(:request, mock_model("Request")) render rendered.should have

FactoryGirl Rspec ActionView::Template::Error: undefined method for nil:NilClass

寵の児 提交于 2019-12-11 07:15:28
问题 I'm new to rails and am trying to give TDD a try. I have a user model that has an admin attribute that is set to nil by default and a request model. Here's a test that I have for my request controller it "should grant access to 'destroy'" do req = Factory(:request, :user => @user) delete :destroy, :id => req.id response.should be_successful end When I run this I get the following error: ActionView::Template::Error:undefined method `admin' for nil:NilClass I'm guessing this is because my views

Testing parallel transactions using RSpec

风格不统一 提交于 2019-12-11 05:22:53
问题 Is there any way to test parallel transaction using RSpec? Saying I have a bank account balance that need to be locked inside a transaction before it is decreased or increased. However, currently, although I have turned off RSpec transactional_fixtures option, I cannot launch 2 parallel transaction in two separated threads. For some reason, both are hung. Given Account is a model Then this spec will hang: it "should ensure operations are performed correctly" do @account = Account.create(

Trouble on specifying explicit 'subject's?

烈酒焚心 提交于 2019-12-11 04:37:55
问题 I am using Ruby on Rails 3.0.9 and RSpect 2. I am trying to refactoring some spec file in the following way (in order to test with less code similar User class object attribute values): describe User do let(:user1) { Factory(:user, :users_attribute_a => 'invalid_value') } let(:user2) { Factory(:user, :users_attribute_b => 'invalid_value') } let(:user3) { Factory(:user, :users_attribute_c => 'invalid_value') } it "foreach user" do [ user1, user2, user3 ].each do |user| subject { user } it

How to write a diffable matcher with Rspec2

為{幸葍}努か 提交于 2019-12-11 03:42:46
问题 I'm trying to write a matcher which transforms object to a Hash before comparing to the expected value (let say that I want to compare 2 hashes without caring about the fact that keys are strings or symbols). I can easily define a matcher doing this RSpec::Matchers.define :my_matcher do |content| match { |to_match| my_hash_conversion(to_match) == my_hash_conversion(content) diffable end I add diffable so rspec displays the diff of the two objects when they don't match. However I want to

Rspec no route matches

删除回忆录丶 提交于 2019-12-11 02:54:43
问题 I'm getting the following error with rspec: 1) LandingController landing#index returns http success Failure/Error: get :index ActionController::RoutingError: No route matches {:controller=>"landing"} # ./spec/controllers/landing_controller_spec.rb:7:in `block (3 levels) in <top (required)>' This is the test require 'spec_helper' describe LandingController do describe "landing#index" do it "returns http success" do get :index response.should be_success end end end I mounted it as root :to =>