Class: TestCollection
- Inherits:
-
Object
- Object
- TestCollection
- Defined in:
- lib/sfb_scripts/test_running/test_collection.rb
Constant Summary collapse
- MultipleWorkingDirectoriesError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#tests ⇒ Object
readonly
Returns the value of attribute tests.
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #all?(&block) ⇒ Boolean
- #empty? ⇒ Boolean
- #first ⇒ Object
- #full_paths ⇒ Object
- #in_one_engine? ⇒ Boolean
- #in_one_file? ⇒ Boolean
- #include_selenium? ⇒ Boolean
-
#initialize(tests_data = [], query: '') ⇒ TestCollection
constructor
A new instance of TestCollection.
- #is_one_test_method? ⇒ Boolean
- #present? ⇒ Boolean
- #relative_paths ⇒ Object
- #relative_paths_in(working_directory) ⇒ Object
- #remove_selenium! ⇒ Object
- #selenium_tests ⇒ Object
- #size ⇒ Object
- #uniq! ⇒ Object
- #working_dir ⇒ Object
- #working_dirs ⇒ Object
Constructor Details
#initialize(tests_data = [], query: '') ⇒ TestCollection
Returns a new instance of TestCollection.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 7 def initialize(tests_data=[], query: '') @query = query @tests = tests_data.map do |test_data| if test_data.is_a? TestCase test_data else test_data = {file: test_data} if test_data.is_a?(String) TestCase.new( full_path: test_data[:file], line: test_data[:line] ) end end.compact end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
5 6 7 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 5 def query @query end |
#tests ⇒ Object (readonly)
Returns the value of attribute tests.
5 6 7 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 5 def tests @tests end |
Instance Method Details
#[](*args) ⇒ Object
43 44 45 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 43 def [](*args) tests[*args] end |
#all?(&block) ⇒ Boolean
47 48 49 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 47 def all?(&block) tests.all?(&block) end |
#empty? ⇒ Boolean
23 24 25 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 23 def empty? tests.empty? end |
#first ⇒ Object
39 40 41 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 39 def first tests.first end |
#full_paths ⇒ Object
59 60 61 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 59 def full_paths @full_paths ||= tests.map {|t| t.full_path }.uniq end |
#in_one_engine? ⇒ Boolean
55 56 57 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 55 def in_one_engine? working_dirs.size == 1 end |
#in_one_file? ⇒ Boolean
51 52 53 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 51 def in_one_file? full_paths.size == 1 end |
#include_selenium? ⇒ Boolean
75 76 77 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 75 def include_selenium? ! selenium_tests.empty? end |
#is_one_test_method? ⇒ Boolean
93 94 95 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 93 def is_one_test_method? (size == 1) && tests.first.is_method? end |
#present? ⇒ Boolean
31 32 33 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 31 def present? ! empty? end |
#relative_paths ⇒ Object
63 64 65 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 63 def relative_paths @relative_paths ||= tests.map {|t| t.relative_path }.uniq end |
#relative_paths_in(working_directory) ⇒ Object
71 72 73 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 71 def relative_paths_in(working_directory) tests.select {|t| t.working_dir == working_directory}.map {|t| t.relative_path }.uniq end |
#remove_selenium! ⇒ Object
79 80 81 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 79 def remove_selenium! @tests = tests - selenium_tests end |
#selenium_tests ⇒ Object
83 84 85 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 83 def selenium_tests tests.select {|t| t.full_path.match(/selenium/)} end |
#size ⇒ Object
35 36 37 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 35 def size tests.size end |
#uniq! ⇒ Object
27 28 29 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 27 def uniq! @tests = @tests.uniq {|e| "#{e.full_path} #{e.test_name} #{e.working_dir}" } end |
#working_dir ⇒ Object
87 88 89 90 91 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 87 def working_dir raise MultipleWorkingDirectoriesError.new("Can't run tests for more than one engine") unless working_dirs.size == 1 return working_dirs.first end |
#working_dirs ⇒ Object
67 68 69 |
# File 'lib/sfb_scripts/test_running/test_collection.rb', line 67 def working_dirs @working_dirs ||= tests.map {|t| t.working_dir }.uniq end |