vendredi 29 juillet 2016

Why is the first Rspec View test ran always the slowest?

Below is my Rspec output and as you can see the first test to run is always the slowest. The first time it was line 18, the second time it was line 27. Could the test be doing any sort of caching?

❯ spec spec/views/principals/show.html.haml_spec.rb -p                                                            mbc
Run options:
  include {:focus=>true}
  exclude {:ignore=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 25466
..

Top 2 slowest examples (3.47 seconds, 94.4% of total time):
  /principals/show the MINDEX tab a permitted user has tab and a link to the tab
    3.41 seconds ./spec/views/principals/show.html.haml_spec.rb:18
  /principals/show the MINDEX tab a not-permitted user does not have tab or a link to the tab
    0.05673 seconds ./spec/views/principals/show.html.haml_spec.rb:27

Finished in 3.68 seconds (files took 5.98 seconds to load)
2 examples, 0 failures

Randomized with seed 25466

❯ rspec spec/views/principals/show.html.haml_spec.rb -p                                                            mbc
Run options:
  include {:focus=>true}
  exclude {:ignore=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 33681
..

Top 2 slowest examples (3.98 seconds, 94.9% of total time):
  /principals/show the MINDEX tab a not-permitted user does not have tab or a link to the tab
    3.73 seconds ./spec/views/principals/show.html.haml_spec.rb:27
  /principals/show the MINDEX tab a permitted user has tab and a link to the tab
    0.25015 seconds ./spec/views/principals/show.html.haml_spec.rb:18

Finished in 4.2 seconds (files took 6.91 seconds to load)
2 examples, 0 failures

Randomized with seed 33681

And here are my tests....

RSpec.describe "/principals/show" do

  before do
    @principal = FactoryGirl.build_stubbed(:principal)
    FactoryGirl.build_stubbed(:financial_statement, principal: @principal)
    @financial_statements = @principal.financial_statements.paginate(per_page: 5, page: 1)
    @merchants_index = MerchantsIndex.new(@principal)
    allow(@view).to receive(:current_user).and_return(mock_model(User).as_null_object)
    allow(@view).to receive(:permitted_to?).and_return(true)
  end

  #it "works" do
  #  expect { render }.not_to raise_error
  #end

  describe "the MINDEX tab" do
    context "a permitted user" do
      it "has tab and a link to the tab" do
        expect(@view).to receive(:permitted_to?).with(:read, :merchants_index).twice.and_return(true)
        render
        expect(rendered).to have_selector("a[href='#mindex']")
        expect(rendered).to have_selector("div#mindex")
      end
    end

    context "a not-permitted user" do
      it "does not have tab or a link to the tab" do
        expect(@view).to receive(:permitted_to?).with(:read, :merchants_index).twice.and_return(false)
        render
        expect(rendered).not_to have_selector("a[href='#mindex']")
        expect(rendered).not_to have_selector("div#mindex")
      end
    end
  end

end

Aucun commentaire:

Enregistrer un commentaire