sfb_scripts 1.6 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e7279bb5e7fffd4a2b44fad0f7ae8f2b6cf0ce7
4
- data.tar.gz: 8a1131704ff90b965179f71f41ea62f68de24482
3
+ metadata.gz: f85e393c87cefd7c1457d0cdb1ef0e4701619a34
4
+ data.tar.gz: d6dfb9262c26a4914f92a6bb0aa4cb7ee0830c84
5
5
  SHA512:
6
- metadata.gz: 31638c99f1501a7b035bdda11105e69792722269ece7d8ac5add2ce85d1ff85d092a75979df327361e4dfbaf0fa35f67d5644996a910fd9afe55006b9f323da1
7
- data.tar.gz: 8005900cb970a8725b2e2f97d518485b2ce93fc7f1d89e1a80617fb8045bc7775bf07c60344da99eaf007ceaaf3d70b1530881b411f5dd327892df62eb22c9e1
6
+ metadata.gz: d350584195bd7d960fb1c635a3e72f0c7de42fbffeecf8332fc987d80176b58a68d3230dae49152431903ae85808f05b97e8f9d2e9ad99242a9f954f6a73319b
7
+ data.tar.gz: eedf607c18f39d291863208cf6d777a5fbc1d7f834236060b416fe536f104f2c77a08173aa57cbd8a001960539a720499965084bf87c851d5ffc907115aa330b
data/bin/test_runner CHANGED
@@ -22,6 +22,7 @@ class CLI < Thor
22
22
  desc "find", <<-DESC
23
23
  Find tests and run them. By trying to match an individual test or the name of a test file(s).
24
24
  DESC
25
+ option :timid, type: :boolean, desc: "Always ask user which tests to run if multiple test files are found. Defaults to false", default: false
25
26
  def find(input)
26
27
  if input == '--help'
27
28
  puts "use 'test_runner --help find' to see the help"
@@ -83,7 +83,8 @@ class NeedsManager
83
83
  def create_test_runner
84
84
  env[:test_runner] = TestRunner.new(
85
85
  shell: env[:shell],
86
- all_engines: options[:all_engines]
86
+ all_engines: options[:all_engines],
87
+ always_ask_before_grouping_tests: options[:timid]
87
88
  )
88
89
  end
89
90
 
@@ -39,6 +39,19 @@ class ShellRunner
39
39
  return answer != 'n'
40
40
  end
41
41
 
42
+ def get_number_list_for_question(question)
43
+ warn question
44
+ answer = STDIN.gets.strip
45
+
46
+ answer.split(',').map do |term|
47
+ if term.include?('-')
48
+ (term.split('-')[0].to_i..term.split('-')[1].to_i).to_a
49
+ else
50
+ term.to_i
51
+ end
52
+ end.flatten
53
+ end
54
+
42
55
  def deny?(question)
43
56
  ! confirm?(question)
44
57
  end
@@ -7,11 +7,16 @@ class TestCollection
7
7
  def initialize(tests_data=[], query: '')
8
8
  @query = query
9
9
  @tests = tests_data.map do |test_data|
10
- test_data = {file: test_data} if test_data.is_a?(String)
11
- TestCase.new(
12
- full_path: test_data[:file],
13
- line: test_data[:line]
14
- )
10
+ if test_data.is_a? TestCase
11
+ test_data
12
+ else
13
+ test_data = {file: test_data} if test_data.is_a?(String)
14
+
15
+ TestCase.new(
16
+ full_path: test_data[:file],
17
+ line: test_data[:line]
18
+ )
19
+ end
15
20
  end.compact
16
21
  end
17
22
 
@@ -19,6 +24,10 @@ class TestCollection
19
24
  tests.empty?
20
25
  end
21
26
 
27
+ def uniq!
28
+ @tests = @tests.uniq {|e| "#{e.full_path} #{e.test_name} #{e.working_dir}" }
29
+ end
30
+
22
31
  def present?
23
32
  ! empty?
24
33
  end
@@ -1,9 +1,10 @@
1
1
  class TestRunner
2
2
 
3
- attr_reader :shell, :all_engines_param
3
+ attr_reader :shell, :all_engines_param, :always_ask_before_grouping_tests
4
4
  def initialize(env)
5
5
  @shell = env[:shell]
6
6
  @all_engines_param = env[:all_engines]
7
+ @always_ask_before_grouping_tests = env[:always_ask_before_grouping_tests]
7
8
  end
8
9
 
9
10
  # Hack: this could use *a lot* of love
@@ -17,7 +18,8 @@ class TestRunner
17
18
  elsif tests.is_one_test_method?
18
19
  test = tests.first
19
20
  run_method(path: test.relative_path, name: test.test_name, dir: test.working_dir)
20
-
21
+ elsif always_ask_before_grouping_tests
22
+ ask_user_which_tests_to_run(tests)
21
23
  elsif tests.in_one_file? && tests.all? {|t| t.is_method? }
22
24
  shell.notify "Multiple matches in same file. Running those tests"
23
25
  test = tests.first
@@ -32,20 +34,31 @@ class TestRunner
32
34
  run_files(tests)
33
35
 
34
36
  else
35
- shell.warn 'Found too many tests:'
36
- tests[0..10].each {|t| shell.notify "#{t.full_path}: #{t.test_name}" }
37
- shell.notify '...'
38
- exit
39
-
37
+ ask_user_which_tests_to_run(tests)
40
38
  end
41
39
  end
42
40
 
43
41
  def run_method(path:, name:, dir:)
44
42
  test_runner = named_test_runner(dir)
45
-
46
43
  shell.exec("#{test_runner} #{path} --name=/#{name}/", dir: dir)
47
44
  end
48
45
 
46
+ def ask_user_which_tests_to_run(tests)
47
+ shell.warn 'Found too many tests. Please choose which matches you would like to run:'
48
+
49
+ tests.uniq!.each_with_index do |t, index|
50
+ shell.notify "(#{index}) #{t.full_path}: #{t.test_name}"
51
+ end
52
+
53
+ tests_to_run = shell.get_number_list_for_question('Please enter the match numbers you would like to run(comma seperated)')
54
+
55
+ new_tests = tests_to_run.map do |index|
56
+ tests[index]
57
+ end
58
+ @always_ask_before_grouping_tests = false
59
+ run(TestCollection.new(new_tests))
60
+ end
61
+
49
62
  def run_files(tests)
50
63
  begin
51
64
  test_runner = test_collection_runner(tests.working_dir)
@@ -0,0 +1,3 @@
1
+ module SfbScripts
2
+ VERSION = "1.7.0"
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfb_scripts
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.6'
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Kinnecom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-06 00:00:00.000000000 Z
11
+ date: 2014-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -86,6 +86,7 @@ files:
86
86
  - lib/sfb_scripts/test_running/test_runner.rb
87
87
  - lib/sfb_scripts/tester.rb
88
88
  - lib/sfb_scripts/upper.rb
89
+ - lib/sfb_scripts/version.rb
89
90
  homepage: http://github.com/petekinnecom/sfb_scripts/
90
91
  licenses:
91
92
  - MIT