2016-07-26 93 views
-1

index方法中有2個數組,我想測試數組的長度是否相等,但它不工作(手動測試後數組長度相等)`rspec` - 比較兩個陣列的長度相互之間的差異

def index 
    @countries = get_countries() 
    @capitals = get_capitals() 
end 

Rspec的文件:

describe CountriesController do 
    describe 'index' do 
    it 'countries.length == capitals.length' do 
     expect(assigns(countries.length)).to eq (assigns(capitals.length)) 
    end 
    end 
end 

回答

1

看起來不像你正在爲這一行動的請求...這是...哪裏是get :index電話嗎?

0

它應該是這樣的:

describe CountriesController do 
    describe 'index' do 
    it 'countries.length == capitals.length' do 
     get :index 
     expect(assigns(:countries).length).to eq assigns(:capitals).length 
    end 
    end 
end