require 'spec_helper' require 'turnip_formatter/printer/tab_speed_statistics' module TurnipFormatter::Printer describe TabSpeedStatistics do include_context 'turnip_formatter scenario setup' include_context 'turnip_formatter standard scenario metadata' let :statistics do TurnipFormatter::Printer::TabSpeedStatistics end let :passed_scenarios do ([example] * 3).map do |ex| TurnipFormatter::Scenario::Pass.new(ex) end.each { |s| s.stub(:run_time).and_return(rand) } end describe '.print_out' do it 'should get string as HTML table' do html = statistics.print_out(passed_scenarios) passed_scenarios.each do |scenario| tag_scenario_name = "#{scenario.name}" tag_run_time = "#{scenario.run_time}" tag_feature_name = "#{scenario.feature_name}" expect_match = [ '', "#{tag_feature_name}", "#{tag_scenario_name}", "#{tag_run_time} sec", '' ].join('[[:space:]]+') expect(html).to match %r(#{expect_match}) end end end describe '.speed_analysis' do it 'should get array of scenario order by run_time' do scenarios = statistics.send(:speed_analysis, passed_scenarios) expect(scenarios).to have(3).elements run_time_list = scenarios.map(&:run_time) expect(run_time_list.sort).to eq run_time_list end end end end