2013-11-27 32 views
0

我正在成功運行此命令,直到我剛剛開始文件中的最後一個規格(describe'DELETE #destroy')。現在,當我運行此問題標題中列出的命令時,似乎我的終端凍結或超時。終端命令rspec spec/controllers/teams_controller_spec.rb超時

這裏是我的關聯文件和終端輸出。

enter image description here

的Gemfile

source 'https://rubygems.org' 

'ruby' '2.0.0' 
gem 'rails', '3.2.14' 
gem 'pg' 
gem 'devise' 
gem 'composite_primary_keys' 
gem 'bootstrap-sass', '~> 3.0.2.0' 
gem 'bootstrap-datetimepicker-rails' 
gem 'twitter-bootstrap-rails', git: 'git://github.com/seyhunak/twitter-bootstrap-rails.git' 

group :assets do 
    gem 'sass-rails', '~> 3.2.3' 
    gem 'coffee-rails', '~> 3.2.1' 
    gem 'uglifier',  '>= 1.0.3' 
end 

group :development, :test do 
    gem 'rspec-rails', '~> 2.0' 
    gem 'shoulda-matchers' 
    gem 'shoulda' 
    gem 'factory_girl_rails', require: false 
    gem 'pry' 
    gem 'pry-rails' 
    gem 'pry-remote' 
    gem 'guard-zeus' 
    gem 'guard-rspec', require: false 
end 

gem 'jquery-rails' 

spec_helper.rb

# This file is copied to spec/ when you run 'rails generate rspec:install' 
ENV["RAILS_ENV"] ||= 'test' 
require File.expand_path("../../config/environment", __FILE__) 
require 'rspec/rails' 
require 'factory_girl_rails' 
require 'shoulda' 
require 'shoulda-matchers' 


# Requires supporting ruby files with custom matchers and macros, etc, 
# in spec/support/ and its subdirectories. 
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } 

RSpec.configure do |config| 
    # config.include FactoryGirl::Syntax::Methods 
    # FactoryGirl.find_definitions 
    # ## Mock Framework 
    # 
    # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: 
    # 
    # config.mock_with :mocha 
    # config.mock_with :flexmock 
    # config.mock_with :rr 

    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 
    config.fixture_path = "#{::Rails.root}/spec/fixtures" 

    # If you're not using ActiveRecord, or you'd prefer not to run each of your 
    # examples within a transaction, remove the following line or assign false 
    # instead of true. 
    config.use_transactional_fixtures = true 

    # If true, the base class of anonymous controllers will be inferred 
    # automatically. This will be the default behavior in future versions of 
    # rspec-rails. 
    config.infer_base_class_for_anonymous_controllers = false 

    # Run specs in random order to surface order dependencies. If you find an 
    # order dependency and want to debug it, you can fix the order by providing 
    # the seed, which is printed after each run. 
    #  --seed 1234 
    config.order = "random" 
end 

工廠/ teams.rb

FactoryGirl.define do 
    factory :team do |f| 
    f.name 'Bengals' 
    f.sport_type 'softball' 
    # f.university_id '1' 
    f.association :university 
    end 
end 

teams_controller_spec.rb

require 'spec_helper' 

describe TeamsController do 
    describe 'GET #index' do 
    before(:each) { @university = FactoryGirl.create(:university) } 

    it 'returns http success' do 
     get :index, university_id: @university.id 
     expect(response).to be_success 
    end 

    it 'assigns every team object into an @teams array' do 
     @team = FactoryGirl.create :team, university_id: @university.id 
     get :index, university_id: @university.id 
     expect(assigns(:teams)).to eq [@team] and be_success 
    end 

    it 'renders the index template' do 
     @university = FactoryGirl.create :university 
     get :index, university_id: @university.id 
     expect(response).to render_template(:index) 
    end 
    end 

    describe 'GET #new' do 
    before(:each) { @university = FactoryGirl.create(:university) } 
    it 'returns http success and instantiates a @team' do 
     @university = FactoryGirl.create :university 
     @team = FactoryGirl.create :team 
     get :new, university_id: @university.id, id: @team.id 
     expect(@team).to be_a_kind_of Team 
    end 

    it 'renders the #new template' do 
     @university = FactoryGirl.create :university 
     get :new, university_id: @university.id 
     expect(response).to render_template(:new) 
    end 
    end 

    describe 'GET #create' do 
    context 'given valid credentials' do 
     before(:each) { @university = FactoryGirl.create(:university) } 

     it 'returns http success and redirects to the #show template' do 
     @university = FactoryGirl.create :university 
     post :create, team: FactoryGirl.attributes_for(:team), 
     university_id: @university.id 
     team = Team.order(:created_at).last 
     expect(response).to be_redirect 
     end 
    end 

    context 'given invalid credentials' do 
     before(:each) { @university = FactoryGirl.create(:university) } 

     it 'returns http client error' do 
     post :create, team: FactoryGirl.attributes_for(:team), 
     university_id: @university.id 
     team = Team.order(:created_at).last 
     expect(response).not_to be_success 
     end 

     it 'should render the #new template' do 
     post :create, university_id: @university.id 
     expect(response).to render_template(:new) 
     end 
    end 
    end 

    describe 'GET #show' do 
    before(:each) { @university = FactoryGirl.create(:university) } 

    it 'returns http success and renders the #show template' do 
     @team = FactoryGirl.create :team 
     get :show, university_id: @team.university_id, id: @team.id 
     expect(response).to be_success 
     expect(response).to render_template(:show) 
    end 
    end 

    describe 'GET #edit' do 
    before(:each) { @university = FactoryGirl.create(:university) } 

    it 'returns http success and renders the #edit template' do 
     @team = FactoryGirl.create :team 
     get :edit, university_id: @team.university_id, id: @team.id 
     expect(response).to be_success 
     expect(response).to render_template(:edit) 
    end 
    end 

    describe 'GET #update' do 
    before(:each) { @university = FactoryGirl.create(:university) } 
    it 'returns http success and redirects to the #show template' do 
     @team = FactoryGirl.create :team 
     get :update, university_id: @team.university_id, id: @team.id 
     expect(response).to eql 200 
     expect(response).to be_redirect 
    end 
    end 

    describe 'DELETE #destroy' do 
    it 'should destroy object from the database and redirect to teams_path' do 
     delete :destroy, university_id: @team.university_id, id: @team.id 
     expect(@university.delete).to be_true 
     expect(response).to redirect_to universities_path 
    end 
    end 
end 

回答

0

我在添加完所有文件後找到了答案,所以我認爲最好是發佈一個答案,以防其他人遇到此問題。這是一個嵌套控制器,我的意思是它與University.rb有一個父關聯關係。我很難讓兩個id(大學和團隊)得到正確的填寫,而且我變得更加明確,各種錯誤都停止了。

我意識到,通過後代的實例變量訪問家長協會的ID我能夠找到像這樣適當的資源:

get :show, university_id: @team.university_id, id: @team.id 

我能得到早期規範通過查找正確的資源是不太明顯的,當我在這個規範文件的末尾,我的猜測是,它開始抱怨我先前暗示ID發現

get :show, [@university, @team] 
get :show, university_id: @university.id, id: @team.id 

希望這可以幫助別人的未來。時間準備thanskgiving準備。