pry-test 0.6.0 → 0.6.1

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: 020727b338a4685172a46d1316cf2da5fd1fdc38
4
- data.tar.gz: 760b17b36e795fbc62468e044f91cd400c210a24
3
+ metadata.gz: c6be3ce3aa63e94c3beabb6d47c14c802e069fb7
4
+ data.tar.gz: 613bd4bc5764a6e2ba508e23d899e39f0549bbe7
5
5
  SHA512:
6
- metadata.gz: 419fa946efa0f52d0d92ae1bcd6c39da0b071937f0219ceeadb6dd34ec5a43e99b087367872e9f4131e5c1405332caddb3b0b821f528aac2fd781b9db8af7760
7
- data.tar.gz: ef66f74defd2b4f0ae5258b40111a5dd5eea28d3a196c7dbb7f83bf2227f60318cfb2f82c3c5841f09770d762e0798386e9ff0e6aa530efecab706a19824b4cc
6
+ metadata.gz: 6ad0f9396749efb2f64d69cb113bd7e6da860b245cb3491b56a9f15222784a80c762dfe7759e6b56ecc102af027f1f05a27464636432a136952ce8db301c1f0e
7
+ data.tar.gz: d51093a0c22db3918871bbe720a9fc68208c6251aa9bf910b11602244019a77cdbf8ad556719048623c05b845de60821b2915e4620c5a9d58babffb91e10ae49
@@ -86,13 +86,17 @@ include PryTest::Color
86
86
 
87
87
  options[:disable_pry] = true if options[:async]
88
88
  if options[:disable_pry]
89
- puts "Disabline pry #{options.inspect}"
89
+ puts "Disabling pry #{options.inspect}"
90
90
  exit runner(options).run
91
91
  else
92
92
  require "pry"
93
93
  require "pry-stack_explorer"
94
94
  require "pry-byebug"
95
95
  require "pry-rescue"
96
- require "binding_of_caller"
96
+
97
+ Pry.config.hooks.add_hook :before_session, :print_instructions do |_, _, _pry_|
98
+ PryStackExplorer.frame_manager(_pry_).change_frame_to 1
99
+ end
100
+
97
101
  exit Pry.rescue { runner(options).run }
98
102
  end
@@ -27,7 +27,7 @@ module PryTest
27
27
  end
28
28
 
29
29
  def render_output_for_test(test)
30
- return unless test.finished?
30
+ return unless test.invoked?
31
31
 
32
32
  if test.passed?
33
33
  render "default/test_pass", test
@@ -13,64 +13,83 @@ module PryTest
13
13
  end
14
14
  end
15
15
 
16
- attr_reader :formatter, :options, :active_test, :duration, :passed, :failed
16
+ attr_reader :formatter, :options, :duration, :passed, :failed
17
17
 
18
18
  def initialize(formatter, options={})
19
19
  @formatter = formatter
20
20
  @options = options
21
- reset
22
21
  end
23
22
 
24
23
  def run
25
- test_classes = PryTest::Test.subclasses.shuffle
26
- tests = test_classes.map{ |klass| klass.tests }.flatten
27
24
  formatter.before_suite(test_classes)
28
- start = Time.now
25
+ run_test_classes
26
+ formatter.after_suite(test_classes)
27
+ failed
28
+ end
29
29
 
30
- test_classes.each do |test_class|
31
- if !PryTest::Runner.terminate?
32
- formatter.before_class(test_class)
33
- test_class.tests.shuffle.each do |test|
34
- @active_test = test
35
- if @options[:async]
36
- @tests ||= Queue.new
37
- @tests << test
38
- else
39
- test.invoke(@formatter, @options)
40
- end
41
- end
42
- formatter.after_class(test_class)
43
- end
44
- end
30
+ def test_classes
31
+ @test_classes ||= PryTest::Test.subclasses.shuffle
32
+ end
33
+
34
+ def tests
35
+ @tests ||= test_classes.map{ |klass| klass.tests }.flatten
36
+ end
45
37
 
46
- run_threads if @options[:async]
38
+ def failed_tests
39
+ tests.select{ |test| test.invoked? && !test.passed? }
40
+ end
41
+
42
+ def failed
43
+ failed_tests.length
44
+ end
47
45
 
46
+ def passed_tests
47
+ tests.select{ |test| test.invoked? && test.passed? }
48
+ end
49
+
50
+ def passed
51
+ passed_tests.length
52
+ end
53
+
54
+ private
55
+
56
+ def run_test_classes
57
+ start = Time.now
58
+ queue ||= Queue.new if options[:async]
59
+ test_classes.each do |test_class|
60
+ run_test_class test_class, queue
61
+ end
62
+ run_threads(queue) if options[:async]
48
63
  @duration = Time.now - start
49
- @passed = tests.select{ |test| test.invoked? && test.passed? }.count
50
- @failed = tests.select{ |test| test.invoked? && !test.passed? }.count
51
64
  formatter.after_results(self)
52
- formatter.after_suite(test_classes)
53
- @failed
54
65
  end
55
66
 
56
- def reset
57
- @duration = 0
58
- @passed = 0
59
- @failed = 0
67
+ def run_test_class(test_class, queue)
68
+ return if PryTest::Runner.terminate?
69
+ formatter.before_class(test_class)
70
+ test_class.tests.shuffle.each do |test|
71
+ if options[:async]
72
+ queue << test
73
+ else
74
+ test.invoke(formatter, options)
75
+ end
76
+ end
77
+ formatter.after_class(test_class)
60
78
  end
61
79
 
62
- protected
80
+ def thread_count
81
+ count = OS.cpu_count
82
+ count < 2 ? 2 : count
83
+ end
63
84
 
64
- def run_threads
65
- threads = []
66
- thread_count = OS.cpu_count
67
- thread_count = 2 if thread_count < 2
85
+ def run_threads(queue)
68
86
  puts "PryTest is running #{thread_count} threads."
69
- thread_count.times do
70
- threads << Thread.new do
71
- while !@tests.empty?
72
- Thread.current.kill if PryTest::Runner.terminate?
73
- @tests.pop.invoke(@formatter, @options)
87
+ threads = thread_count.times.map do
88
+ Thread.new do
89
+ while !queue.empty?
90
+ Thread.current.terminate if PryTest::Runner.terminate?
91
+ test = queue.pop
92
+ test.invoke(formatter, options)
74
93
  end
75
94
  end
76
95
  end
@@ -34,12 +34,6 @@ module PryTest
34
34
  @files ||= {}
35
35
  end
36
36
 
37
- # Resets the state in preparation for a new test run.
38
- def reset
39
- tests.each { |test| test.reset }
40
- subclasses.each { |subclass| subclass.reset }
41
- end
42
-
43
37
  # A callback provided by Ruby that is invoked whenever a subclass is created.
44
38
  def inherited(subclass)
45
39
  file_path = caller[0][0, caller[0].index(/:[0-9]+:/)]
@@ -16,8 +16,8 @@ module PryTest
16
16
  super() # inits MonitorMixin
17
17
  @test_class = test_class
18
18
  @desc = desc
19
+ @asserts = []
19
20
  create_method(:test, &block)
20
- reset
21
21
  end
22
22
 
23
23
  # Creates a method on this instance.
@@ -36,7 +36,6 @@ module PryTest
36
36
  # @formatter [PryTest::Formatter] The formatter to use.
37
37
  # @options [Hash]
38
38
  def invoke(formatter, options={})
39
- reset
40
39
  @formatter = formatter
41
40
  @options = options
42
41
  @formatter.before_test(self)
@@ -44,8 +43,8 @@ module PryTest
44
43
  before
45
44
  test
46
45
  @invoked = true
47
- after
48
46
  @duration = Time.now - start
47
+ after
49
48
  @formatter.after_test(self)
50
49
  end
51
50
 
@@ -63,7 +62,7 @@ module PryTest
63
62
  @asserts << assert_info(caller).merge(:value => value)
64
63
 
65
64
  if !value
66
- Pry.start binding.of_caller(0) unless @options[:disable_pry]
65
+ Pry.start unless @options[:disable_pry]
67
66
 
68
67
  # TODO: I don't really like the coupling to the runner here
69
68
  PryTest::Runner.terminate if @options[:fail_fast]
@@ -72,12 +71,6 @@ module PryTest
72
71
  value
73
72
  end
74
73
 
75
- # Indicates if this test has finished running.
76
- # @return [Boolean]
77
- def finished?
78
- !@duration.nil?
79
- end
80
-
81
74
  # Indicates if this test has been invoked.
82
75
  # @return [Boolean]
83
76
  def invoked?
@@ -92,17 +85,9 @@ module PryTest
92
85
 
93
86
  # Returns a list of all failed asserts.
94
87
  def failed_asserts
95
- return [] if passed?
96
88
  @asserts.select { |a| !a[:value] }
97
89
  end
98
90
 
99
- # Resets this test in preparation for a clean test run.
100
- def reset
101
- @invoked = false
102
- @asserts = []
103
- @duration = nil
104
- end
105
-
106
91
  # Rounded duration.
107
92
  def duration
108
93
  return nil if @duration.nil?
@@ -1,3 +1,3 @@
1
1
  module PryTest
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -39,17 +39,6 @@ unless ENV["PRY_TEST_DEMO"]
39
39
  assert @test_test.files[file].select{ |l| l.start_with?(" assert @test_test.files[file].select{ |l| l.start_with?(") }.length > 0
40
40
  end
41
41
 
42
- test ".reset" do
43
- @Example.tests.first.instance_eval do
44
- @asserts = nil
45
- @duration = nil
46
- end
47
- @Example.reset
48
- assert @Example.tests.length == 1
49
- assert @Example.tests.first.asserts == []
50
- assert @Example.tests.first.duration == nil
51
- end
52
-
53
42
  test ".before" do
54
43
  assert @Example.instance_eval { @before } == @before_callback
55
44
  end
@@ -11,7 +11,6 @@ unless ENV["PRY_TEST_DEMO"]
11
11
  assert t.test == ".new"
12
12
  assert t.invoked? == false
13
13
  assert t.passed? == false
14
- assert t.finished? == false
15
14
  assert t.duration.nil?
16
15
  assert t.asserts.empty?
17
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: binding_of_caller
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: os
85
71
  requirement: !ruby/object:Gem::Requirement