2012-02-23 5 views
6

मैं जब निम्न RSpec परीक्षण चलाने प्रतिक्रिया के रूप में एक खाली पृष्ठ हो रही है:रिक्त पृष्ठ हो रही है जब प्राप्त के लिए RSpec परीक्षण चलाने के 'नए'

require 'spec_helper' 

describe FriendshipsController do 
    include Devise::TestHelpers 
    render_views 

    before(:each) do 
    @user = User.create!(:email => "[email protected]", :password => "mustermann", :password_confirmation => "mustermann") 
    @friend = User.create!(:email => "[email protected]", :password => "password", :password_confirmation => "password")  
    sign_in @user 
    end 

    describe "GET 'new'" do 

    it "should be successful" do 
     get 'new', :user_id => @user.id 
     response.should be_success 
    end 

    it "should show all registered users on Friendslend, except the logged in user" do 
     get 'new', :user_id => @user.id 

     page.should have_select("Add new friend") 
     page.should have_content("div.users") 
     page.should have_selector("div.users li", :count => 1) 
    end 

    it "should not contain the logged in user" do 
     get 'new', :user_id => @user.id 
     response.should_not have_content(@user.email) 
    end 
    end 
end 

जब RSpec परीक्षण चल रहा है मैं केवल एक रिक्त पृष्ठ मिलता है। रिक्त पृष्ठ के साथ मेरा मतलब है कि DOCTYPE घोषणा के अलावा कोई अन्य HTML सामग्री नहीं है।

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> 

दिलचस्प बात यह है कि आरएसपीसी परीक्षण 'निर्माण' के लिए ठीक काम करता है। कोई संकेत?

मैं स्पेस-रेल, ककड़ी और कैपिबरा (Webrat के बजाय) के साथ रेल 3.2 का उपयोग कर रहा हूं।

+1

मैं उत्सुक, आप कभी भी इस समस्या का समाधान मिल गया था? – voxobscuro

+0

इस के समाधान के बारे में भी उत्सुक है .. – jay

+0

दुर्भाग्य से मेरे पास अभी तक कोई समाधान नहीं है ... –

उत्तर

6

समस्या यह है कि आप परीक्षण प्रकारों को मिश्रित कर रहे हैं। Capybara, page ऑब्जेक्ट प्रदान करता है visit path पर कॉल करके अनुरोध चश्मे में उपयोग किया जाता है।

अपनी समस्या को ठीक करने के लिए, आपको page ऑब्जेक्ट के बजाय response ऑब्जेक्ट को देखने की आवश्यकता है।

आप capybara के साथ सामग्री परीक्षण करना चाहते हैं, जिस तरह से है कि आप उस परीक्षण का निर्माण होगा कुछ इस तरह दिखेगा:

visit new_user_session_path 
fill_in "Email", :with => @user.email 
fill_in "Password", :with => @user.password 
click_button "Sign in" 
visit new_friendships_path(:user_id => @user.id) 
page.should have_content("Add new friend") 

कि कोड, एक नियंत्रक कल्पना के बजाय एक अनुरोध कल्पना में रखा जाना चाहिए द्वारा सम्मेलन।

8

मैं जोड़कर इस हल करने के लिए मेरी spec_helper.rb फ़ाइल में निम्न में सक्षम था:

RSpec.configure do |config| 
    config.render_views 
end 

वैकल्पिक रूप से आप व्यक्तिगत रूप से प्रत्येक नियंत्रक में render_views कॉल कर सकते हैं विशेषताएं।

https://github.com/rspec/rspec-rails/blob/master/features/controller_specs/render_views.feature

+1

धन्यवाद सर, वेब खोजने के घंटों के बाद, आपने मेरी मदद की –