2016-07-25 3 views
0

indexメソッドに2つの配列があるが、配列の長さの等価性をテストしたいが、機能しない(手作業でテストした後に配列の長さが等しい)rpecの配列(インスタンス変数)の長さを確認

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 
+0

2つの配列の長さを互いに比較する[\ 'rspec \ ']の可能な複製](http://stackoverflow.com/questions/38579733/rspec-comparing-two-arrays-lengths-against-each-other ) –

答えて

0
describe CountriesController do 
    describe 'index' do 
    it 'has a country for each capital' do 
     #create 3 countries here something like 
     3.times do 
     Country.create(capitol: :capitol) 
     end 

     get :index 

     expect(assigns(countries.length)).to eq (assigns(capitals.length)) 

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

は、この情報がお役に立てば幸いです。

関連する問題