priority_test 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Gemfile +0 -1
- data/README.md +64 -1
- data/Rakefile +9 -12
- data/bin/pt +25 -0
- data/lib/priority_test/autorun.rb +2 -0
- data/lib/priority_test/core/all_tests.rb +30 -0
- data/lib/priority_test/core/configuration.rb +23 -0
- data/lib/priority_test/core/configuration_options.rb +19 -0
- data/lib/priority_test/core/option_parser.rb +84 -0
- data/lib/priority_test/core/priority.rb +62 -0
- data/lib/priority_test/core/priority_sort_element.rb +23 -0
- data/lib/priority_test/core/runner.rb +26 -0
- data/lib/priority_test/core/service.rb +14 -0
- data/lib/priority_test/core/test.rb +53 -0
- data/lib/priority_test/core/test_result.rb +25 -0
- data/lib/priority_test/core/test_result_collector.rb +40 -0
- data/lib/priority_test/core/validations_helper.rb +17 -0
- data/lib/priority_test/core.rb +41 -0
- data/lib/priority_test/gateway/migrations/001_create_tests.rb +11 -0
- data/lib/priority_test/gateway/migrations/002_create_test_results.rb +12 -0
- data/lib/priority_test/gateway/sequel.rb +33 -0
- data/lib/priority_test/gateway.rb +13 -0
- data/lib/priority_test/rspec.rb +19 -0
- data/lib/priority_test/rspec2/example_group_sorter.rb +24 -0
- data/lib/priority_test/rspec2/example_sorter.rb +12 -0
- data/lib/priority_test/rspec2/formatter.rb +35 -0
- data/lib/priority_test/rspec2/patch/example_group.rb +18 -0
- data/lib/priority_test/rspec2/patch/world.rb +7 -0
- data/lib/priority_test/rspec2/relative_path.rb +13 -0
- data/lib/priority_test/rspec2.rb +20 -0
- data/lib/priority_test/version.rb +1 -1
- data/lib/priority_test.rb +25 -2
- data/priority_test.gemspec +4 -5
- data/spec/core/all_tests_spec.rb +53 -0
- data/spec/core/config_spec.rb +53 -0
- data/spec/core/configuration_options_spec.rb +16 -0
- data/spec/core/option_parser_spec.rb +42 -0
- data/spec/core/priority_spec.rb +9 -0
- data/spec/core/service_spec.rb +55 -0
- data/spec/core/test_result_spec.rb +29 -0
- data/spec/core/test_spec.rb +121 -0
- data/spec/gateways/sequel_spec.rb +43 -0
- data/spec/rspec2/formatter_spec.rb +67 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/rspec_factory.rb +17 -0
- metadata +80 -5
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
require_path 'rspec2'
|
3
|
+
require_path 'rspec2/patch/world'
|
4
|
+
require_path 'rspec2/patch/example_group'
|
5
|
+
|
6
|
+
config_options = PriorityTest::Core::ConfigurationOptions.new(['rspec'] + ENV['PT_OPTS'].split)
|
7
|
+
config_options.configure(PriorityTest.configuration)
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.formatters << PriorityTest::RSpec2.formatter
|
11
|
+
|
12
|
+
if PriorityTest.configuration.priority?
|
13
|
+
config.inclusion_filter = { :priority_filter => PriorityTest::RSpec2.filter }
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
end
|
16
|
+
|
17
|
+
# Patch RSpec::Core::ExampleGroup
|
18
|
+
config.extend PriorityTest::RSpec2::Patch::ExampleGroup
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module PriorityTest
|
2
|
+
module RSpec2
|
3
|
+
module ExampleGroupSorter
|
4
|
+
def self.sort(example_group1, example_group2)
|
5
|
+
sorted_elements1 = sorted_elements(example_group1)
|
6
|
+
sorted_elements2 = sorted_elements(example_group2)
|
7
|
+
|
8
|
+
sorted_elements1 <=> sorted_elements2
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def self.sorted_elements(example_group)
|
14
|
+
descendant_examples(example_group).collect do |e|
|
15
|
+
PriorityTest::Core::PrioritySortElement.new(e.full_description)
|
16
|
+
end.sort
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.descendant_examples(example_group)
|
20
|
+
example_group.descendants.collect(&:filtered_examples).flatten
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module PriorityTest
|
2
|
+
module RSpec2
|
3
|
+
module ExampleSorter
|
4
|
+
def self.sort(example1, example2)
|
5
|
+
element1 = PriorityTest::Core::PrioritySortElement.new(example1.full_description)
|
6
|
+
element2 = PriorityTest::Core::PrioritySortElement.new(example2.full_description)
|
7
|
+
|
8
|
+
element1 <=> element2
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rspec/core/formatters/base_formatter'
|
2
|
+
|
3
|
+
module PriorityTest
|
4
|
+
module RSpec2
|
5
|
+
class Formatter < RSpec::Core::Formatters::BaseFormatter
|
6
|
+
def initialize(test_result_collector)
|
7
|
+
@test_result_collector = test_result_collector
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def example_passed(example)
|
12
|
+
@test_result_collector.add_result(to_test_result(example))
|
13
|
+
end
|
14
|
+
|
15
|
+
def example_failed(example)
|
16
|
+
@test_result_collector.add_result(to_test_result(example))
|
17
|
+
end
|
18
|
+
|
19
|
+
def close
|
20
|
+
@test_result_collector.finish
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def to_test_result(example)
|
26
|
+
{ :identifier => example.full_description,
|
27
|
+
:file_path => RelativePath.convert(example.file_path),
|
28
|
+
:status => example.execution_result[:status],
|
29
|
+
:started_at => example.execution_result[:started_at],
|
30
|
+
:run_time => example.execution_result[:run_time]
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PriorityTest
|
2
|
+
module RSpec2
|
3
|
+
module Patch
|
4
|
+
# TODO Implement a SortedArray
|
5
|
+
module ExampleGroup
|
6
|
+
def filtered_examples
|
7
|
+
filtered_examples = super
|
8
|
+
filtered_examples.sort! { |e1, e2| ExampleSorter.sort(e1, e2) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def children
|
12
|
+
children = super
|
13
|
+
children.sort! { |eg1, eg2| ExampleGroupSorter.sort(eg1, eg2) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module PriorityTest
|
2
|
+
module RSpec2
|
3
|
+
module RelativePath
|
4
|
+
def self.convert(absolute_path)
|
5
|
+
relative_path = absolute_path.sub(File.expand_path("."), ".")
|
6
|
+
relative_path = relative_path.sub(/\A([^:]+:\d+)$/, '\\1')
|
7
|
+
return nil if relative_path == '-e:1'
|
8
|
+
|
9
|
+
relative_path
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
require_path 'rspec2/relative_path'
|
3
|
+
require_path 'rspec2/formatter'
|
4
|
+
require_path 'rspec2/example_sorter'
|
5
|
+
require_path 'rspec2/example_group_sorter'
|
6
|
+
|
7
|
+
module PriorityTest
|
8
|
+
module RSpec2
|
9
|
+
|
10
|
+
def self.formatter
|
11
|
+
Formatter.new(PriorityTest.test_result_collector)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.filter
|
15
|
+
lambda { |k, v|
|
16
|
+
PriorityTest.service.priority_test?(v[:full_description])
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/priority_test.rb
CHANGED
@@ -1,5 +1,28 @@
|
|
1
|
-
|
1
|
+
if defined?(require_relative)
|
2
|
+
def require_path(path)
|
3
|
+
require_relative "priority_test/#{path}"
|
4
|
+
end
|
5
|
+
else
|
6
|
+
def require_path(path)
|
7
|
+
require "priority_test/#{path}"
|
8
|
+
end
|
9
|
+
end
|
2
10
|
|
3
11
|
module PriorityTest
|
4
|
-
|
12
|
+
class << self
|
13
|
+
attr_accessor :env
|
14
|
+
end
|
15
|
+
self.env = ENV['PRIORITY_TEST_ENV'] || 'production'
|
5
16
|
end
|
17
|
+
|
18
|
+
require_path 'core'
|
19
|
+
require_path 'gateway'
|
20
|
+
require_path 'version'
|
21
|
+
|
22
|
+
PriorityTest.configure do |config|
|
23
|
+
if PriorityTest.env =~ /test/i
|
24
|
+
config.database = 'sqlite:/'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
PriorityTest::Gateway.setup
|
data/priority_test.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.
|
3
|
-
require
|
2
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
3
|
+
require 'priority_test/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "priority_test"
|
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
# s.add_runtime_dependency "rest-client"
|
21
|
+
s.add_runtime_dependency "sequel"
|
22
|
+
s.add_development_dependency "rspec"
|
24
23
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module PriorityTest::Core
|
4
|
+
describe AllTests do
|
5
|
+
it "gets test by identifier" do
|
6
|
+
test = Test.new(:identifier => "id")
|
7
|
+
all_tests = AllTests.new([test])
|
8
|
+
all_tests.get_test("id").should be
|
9
|
+
end
|
10
|
+
|
11
|
+
it "adds test by params" do
|
12
|
+
all_tests = AllTests.new
|
13
|
+
|
14
|
+
all_tests.add_test(:identifier => "id", :file_path => "path")
|
15
|
+
all_tests.get_test("id").should be
|
16
|
+
end
|
17
|
+
|
18
|
+
context "#add_test_result" do
|
19
|
+
it "adds test result by params" do
|
20
|
+
all_tests = AllTests.new
|
21
|
+
|
22
|
+
test = all_tests.add_test(:identifier => "id", :file_path => "path")
|
23
|
+
expect {
|
24
|
+
all_tests.add_test_result('id', :status => 'passed', :run_time => 1, :started_at => Time.now)
|
25
|
+
}.to change {
|
26
|
+
test.results.size
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
it "updates priority" do
|
31
|
+
all_tests = AllTests.new
|
32
|
+
|
33
|
+
test = all_tests.add_test(:identifier => "id", :file_path => "path")
|
34
|
+
expect {
|
35
|
+
all_tests.add_test_result('id', :status => 'passed', :run_time => 1, :started_at => Time.now)
|
36
|
+
}.to change {
|
37
|
+
test.priority
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
it "updates avg_run_time" do
|
42
|
+
all_tests = AllTests.new
|
43
|
+
|
44
|
+
test = all_tests.add_test(:identifier => "id", :file_path => "path")
|
45
|
+
expect {
|
46
|
+
all_tests.add_test_result('id', :status => 'passed', :run_time => 1, :started_at => Time.now)
|
47
|
+
}.to change {
|
48
|
+
test.avg_run_time
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module PriorityTest::Core
|
4
|
+
describe Configuration do
|
5
|
+
let(:config) { Configuration.new }
|
6
|
+
|
7
|
+
describe "#add_setting" do
|
8
|
+
context "with no additional options" do
|
9
|
+
before { config.add_setting :custom_option }
|
10
|
+
|
11
|
+
it "defaults to nil" do
|
12
|
+
config.custom_option.should be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "adds a predicate" do
|
16
|
+
config.custom_option?.should be_false
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can be overridden" do
|
20
|
+
config.custom_option = "a value"
|
21
|
+
config.custom_option.should eq("a value")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with :default => 'a value'" do
|
26
|
+
before { config.add_setting :custom_option, :default => 'a value' }
|
27
|
+
|
28
|
+
it "defaults to 'a value'" do
|
29
|
+
config.custom_option.should eq("a value")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns true for the predicate" do
|
33
|
+
config.custom_option?.should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can be overridden with a truthy value" do
|
37
|
+
config.custom_option = "a new value"
|
38
|
+
config.custom_option.should eq("a new value")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "can be overridden with nil" do
|
42
|
+
config.custom_option = nil
|
43
|
+
config.custom_option.should eq(nil)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "can be overridden with false" do
|
47
|
+
config.custom_option = false
|
48
|
+
config.custom_option.should eq(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module PriorityTest::Core
|
4
|
+
describe ConfigurationOptions do
|
5
|
+
it "sets configs" do
|
6
|
+
command_line_args = ["rspec", "file1", "--priority"]
|
7
|
+
|
8
|
+
config = Configuration.new
|
9
|
+
config_options = ConfigurationOptions.new(command_line_args)
|
10
|
+
config_options.configure(config)
|
11
|
+
|
12
|
+
config.test_framework.should == 'rspec'
|
13
|
+
config.priority.should == true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module PriorityTest::Core
|
4
|
+
describe OptionParser do
|
5
|
+
let(:parser) { OptionParser.new }
|
6
|
+
|
7
|
+
context "test-framework" do
|
8
|
+
it "parses available test-framework" do
|
9
|
+
args = ['rspec', 'file1']
|
10
|
+
options = parser.parse!(args)
|
11
|
+
|
12
|
+
options[:test_framework].should == 'rspec'
|
13
|
+
args.size.should == 1
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns nil if test-framework not supported" do
|
17
|
+
args = ['foo', 'file1']
|
18
|
+
expect {
|
19
|
+
options = parser.parse!(args)
|
20
|
+
}.to raise_error(::OptionParser::InvalidArgument)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "options" do
|
25
|
+
it "parses options" do
|
26
|
+
args = ['rspec', '--priority', 'file1']
|
27
|
+
options = parser.parse!(args)
|
28
|
+
|
29
|
+
options[:priority].should be_true
|
30
|
+
args.size.should == 1
|
31
|
+
end
|
32
|
+
|
33
|
+
it "ignore extra options" do
|
34
|
+
args = ['rspec', '--priority', 'file1', '-fp']
|
35
|
+
options = parser.parse!(args)
|
36
|
+
|
37
|
+
options[:priority].should be_true
|
38
|
+
args.size.should == 2
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module PriorityTest::Core
|
4
|
+
describe Service do
|
5
|
+
subject { Service.new }
|
6
|
+
|
7
|
+
# describe "#load_all_tests_in_priority_order" do
|
8
|
+
# it "loads tests ordered by failed status" do
|
9
|
+
# passed_test = TestFactory.create_test_result(:identifier => 'identifier1', :file_path => 'file_path1', :status => 'passed')
|
10
|
+
# failed_test = TestFactory.create_test_result(:identifier => 'identifier2', :file_path => 'file_path2', :status => 'failed')
|
11
|
+
|
12
|
+
# test_results = [ passed_test, failed_test ]
|
13
|
+
|
14
|
+
# subject.save(test_results)
|
15
|
+
|
16
|
+
# tests = subject.load_all_tests_in_priority_order
|
17
|
+
# tests.size.should == 2
|
18
|
+
# tests.first.identifier.should == "identifier2"
|
19
|
+
# end
|
20
|
+
|
21
|
+
# it "loads tests ordered by failure rate" do
|
22
|
+
# test_results = []
|
23
|
+
|
24
|
+
# # failure rate is 50%
|
25
|
+
# identifier1_failed_test = TestFactory.create_test_result(:identifier => 'identifier1', :file_path => 'file_path1', :status => 'failed')
|
26
|
+
# identifier1_passed_test = TestFactory.create_test_result(:identifier => 'identifier1', :file_path => 'file_path1', :status => 'failed')
|
27
|
+
# test_results += [ identifier1_failed_test, identifier1_passed_test ]
|
28
|
+
|
29
|
+
# # failure rate is 100%
|
30
|
+
# identifier2_failed_test1 = TestFactory.create_test_result(:identifier => 'identifier2', :file_path => 'file_path2', :status => 'failed')
|
31
|
+
# identifier2_failed_test2 = TestFactory.create_test_result(:identifier => 'identifier2', :file_path => 'file_path2', :status => 'failed')
|
32
|
+
# test_results += [ identifier2_failed_test1, identifier2_failed_test2 ]
|
33
|
+
|
34
|
+
# subject.save(test_results)
|
35
|
+
|
36
|
+
# tests = subject.load_all_tests_in_priority_order
|
37
|
+
# tests.size.should == 2
|
38
|
+
# tests.first.identifier.should == "identifier2"
|
39
|
+
# end
|
40
|
+
|
41
|
+
# it "loads tests ordered by run_time" do
|
42
|
+
# passed_test1 = TestFactory.create_test_result(:identifier => 'identifier1', :file_path => 'file_path1', :status => 'passed', :run_time => 2)
|
43
|
+
# passed_test2 = TestFactory.create_test_result(:identifier => 'identifier2', :file_path => 'file_path2', :status => 'passed', :run_time => 1)
|
44
|
+
|
45
|
+
# test_results = [ passed_test1, passed_test2 ]
|
46
|
+
|
47
|
+
# subject.save(test_results)
|
48
|
+
|
49
|
+
# tests = subject.load_all_tests_in_priority_order
|
50
|
+
# tests.size.should == 2
|
51
|
+
# tests.first.identifier.should == "identifier2"
|
52
|
+
# end
|
53
|
+
# end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PriorityTest::Core::TestResult do
|
4
|
+
subject { PriorityTest::Core::TestResult.new }
|
5
|
+
|
6
|
+
[ :status, :started_at, :run_time ].each do |field|
|
7
|
+
it "validates presence of #{field}" do
|
8
|
+
expect {
|
9
|
+
subject.save
|
10
|
+
}.to raise_error {
|
11
|
+
Sequel::ValidationFailed
|
12
|
+
}
|
13
|
+
|
14
|
+
subject.errors.should include(field)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "validates status to be 'passed' or 'failed'" do
|
19
|
+
subject.status = 'foo'
|
20
|
+
subject.validate
|
21
|
+
subject.errors.should include(:status)
|
22
|
+
|
23
|
+
subject.errors.clear
|
24
|
+
|
25
|
+
subject.status = 'passed'
|
26
|
+
subject.validate
|
27
|
+
subject.errors.should_not include(:status)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module PriorityTest::Core
|
4
|
+
describe Test do
|
5
|
+
context "validation" do
|
6
|
+
subject { Test.new }
|
7
|
+
|
8
|
+
[ :identifier, :file_path ].each do |field|
|
9
|
+
it "validates presence of #{field}" do
|
10
|
+
expect {
|
11
|
+
subject.save
|
12
|
+
}.to raise_error {
|
13
|
+
Sequel::ValidationFailed
|
14
|
+
}
|
15
|
+
|
16
|
+
subject.errors.should include(field)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#recent_results" do
|
22
|
+
it "loads last 5 results" do
|
23
|
+
test = Test.create(:identifier => 'identifier1', :file_path => 'file_path1')
|
24
|
+
10.times.each do |i|
|
25
|
+
time = Time.mktime(1984, 10, 28, 0, i, 0)
|
26
|
+
test.add_result(:status => 'passed', :run_time => 1, :started_at => time)
|
27
|
+
end
|
28
|
+
|
29
|
+
test.results.size.should == 5
|
30
|
+
(1..4).each do |i|
|
31
|
+
previous_result = test.results[i - 1]
|
32
|
+
current_result = test.results[i]
|
33
|
+
previous_result.started_at.should > current_result.started_at
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#recent_result_key" do
|
39
|
+
it "returns a key with P representing passed and F representing failed" do
|
40
|
+
test = Test.create(:identifier => 'identifier1', :file_path => 'file_path1')
|
41
|
+
10.times.each do |i|
|
42
|
+
status = ((i + 1) % 2 == 0) ? 'passed' : 'failed'
|
43
|
+
time = Time.mktime(1984, 10, 28, 0, i, 0)
|
44
|
+
test.add_result(:status => status, :run_time => 1, :started_at => time)
|
45
|
+
end
|
46
|
+
|
47
|
+
test.results_key.should == "PFPFP"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "populates with P in the end if number of results is less than 5" do
|
51
|
+
test = Test.create(:identifier => 'identifier1', :file_path => 'file_path1')
|
52
|
+
3.times.each do |i|
|
53
|
+
time = Time.mktime(1984, 10, 28, 0, i, 0)
|
54
|
+
test.add_result(:status => 'failed', :run_time => 1, :started_at => time)
|
55
|
+
end
|
56
|
+
|
57
|
+
test.results_key.should == "FFFPP"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "#<=>" do
|
62
|
+
it "compares by priority" do
|
63
|
+
test1 = Test.new(:identifier => "id1", :file_path => "path1", :priority => 1)
|
64
|
+
test2 = Test.new(:identifier => "id2", :file_path => "path2", :priority => 2)
|
65
|
+
|
66
|
+
(test1 < test2).should be_true
|
67
|
+
end
|
68
|
+
|
69
|
+
it "compares by avg_run_time" do
|
70
|
+
test1 = Test.new(:identifier => "id1", :file_path => "path1", :avg_run_time => 1)
|
71
|
+
test2 = Test.new(:identifier => "id2", :file_path => "path2", :priority => 2, :avg_run_time => 2)
|
72
|
+
|
73
|
+
(test1 < test2).should be_true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe ".all_in_priority_order" do
|
78
|
+
it "returns all tests ordered by priority" do
|
79
|
+
10.times.each do |i|
|
80
|
+
Test.create(:identifier => "id#{i}", :file_path => "path#{i}", :priority => i)
|
81
|
+
end
|
82
|
+
|
83
|
+
tests = Test.all_in_priority_order
|
84
|
+
tests.size.should == 10
|
85
|
+
|
86
|
+
(1..9).each do |i|
|
87
|
+
previous_test = tests[i-1]
|
88
|
+
current_test = tests[i]
|
89
|
+
previous_test.priority.should < current_test.priority
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns all tests ordered by avg_run_time" do
|
94
|
+
10.times.each do |i|
|
95
|
+
Test.create(:identifier => "id#{i}", :file_path => "path#{i}", :avg_run_time => i)
|
96
|
+
end
|
97
|
+
|
98
|
+
tests = Test.all_in_priority_order
|
99
|
+
tests.size.should == 10
|
100
|
+
|
101
|
+
(1..9).each do |i|
|
102
|
+
previous_test = tests[i-1]
|
103
|
+
current_test = tests[i]
|
104
|
+
previous_test.avg_run_time.should < current_test.avg_run_time
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it "eagerly loads recent results" do
|
109
|
+
test = Test.create(:identifier => 'identifier1', :file_path => 'file_path1')
|
110
|
+
3.times.each do |i|
|
111
|
+
time = Time.mktime(1984, 10, 28, 0, i, 0)
|
112
|
+
test.add_result(:status => 'failed', :run_time => 1, :started_at => time)
|
113
|
+
end
|
114
|
+
|
115
|
+
tests = Test.all_in_priority_order
|
116
|
+
tests.size.should == 1
|
117
|
+
tests.first.associations[:results].should be_any
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module PriorityTest::Gateways
|
4
|
+
describe Sequel do
|
5
|
+
# before :all do
|
6
|
+
# @gateway = Sequel.new(Connection.create)
|
7
|
+
# end
|
8
|
+
|
9
|
+
# subject { @gateway }
|
10
|
+
|
11
|
+
# it "bulk create tests" do
|
12
|
+
# tests = [
|
13
|
+
# TestFactory.create_test_result(:identifier => 'identifier1', :file_path => 'file_path1', :status => 'passed'),
|
14
|
+
# TestFactory.create_test_result(:identifier => 'identifier2', :file_path => 'file_path2', :status => 'failed')
|
15
|
+
# ]
|
16
|
+
|
17
|
+
# subject.bulk_create_test_results(tests)
|
18
|
+
# subject.dataset.count.should == 2
|
19
|
+
# end
|
20
|
+
|
21
|
+
# describe "#recent_test_results" do
|
22
|
+
# it "loads 5 recent test results" do
|
23
|
+
# test_results = []
|
24
|
+
|
25
|
+
# 10.times do |i|
|
26
|
+
# test_results << testfactory.create_test_result(:identifier => "identifier1", :file_path => "file_path1", :status => 'failed', :started_at => mktime(i))
|
27
|
+
# test_results << testfactory.create_test_result(:identifier => "identifier2", :file_path => "file_path2", :status => 'failed', :started_at => mktime(i + 1))
|
28
|
+
# end
|
29
|
+
|
30
|
+
# subject.bulk_create_test_results(test_results)
|
31
|
+
|
32
|
+
# test_results = subject.recent_test_results
|
33
|
+
|
34
|
+
# test_results.size.should == 10
|
35
|
+
# end
|
36
|
+
|
37
|
+
# def mktime(minutes)
|
38
|
+
# time.mktime(1984, 10, 28, 0, minutes, 0)
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|