【问题标题】:`rspec` - comparing two arrays' lengths against each other`rspec` - 比较两个数组的长度
【发布时间】:2016-07-26 01:21:05
【问题描述】:

index 方法中有 2 个数组,我想测试数组长度的相等性,但它不起作用(手动测试后数组的长度相等)

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

【问题讨论】:

    标签: ruby-on-rails rspec


    【解决方案1】:

    您似乎没有请求该操作...也就是说..get :index 呼叫在哪里?

    【讨论】:

      【解决方案2】:

      应该是这样的:

      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
      

      【讨论】:

        猜你喜欢
        • 2013-04-02
        • 1970-01-01
        • 2022-12-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多