问题
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