`rspec` - comparing two arrays' lengths against each other

浪尽此生 提交于 2019-12-25 18:34:35

问题


Having 2 arrays in index method, I want to test the equality of the arrays' lengths but it's not working (the lengths of the arrays are equal after testing manually)

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

Rspec file:

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:


Doesn't look like you are making a request to that action... that is.. where is the get :index call?




回答2:


It should be like this:

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


来源:https://stackoverflow.com/questions/38579733/rspec-comparing-two-arrays-lengths-against-each-other

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!