pry-test 0.6.1 → 0.6.2

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: c6be3ce3aa63e94c3beabb6d47c14c802e069fb7
4
- data.tar.gz: 613bd4bc5764a6e2ba508e23d899e39f0549bbe7
3
+ metadata.gz: 1ab4536d7f94d75381a941153dae9c1901aa9719
4
+ data.tar.gz: 2cbb7a04ea59caa9f0dfe0ab52fb995cd1abd177
5
5
  SHA512:
6
- metadata.gz: 6ad0f9396749efb2f64d69cb113bd7e6da860b245cb3491b56a9f15222784a80c762dfe7759e6b56ecc102af027f1f05a27464636432a136952ce8db301c1f0e
7
- data.tar.gz: d51093a0c22db3918871bbe720a9fc68208c6251aa9bf910b11602244019a77cdbf8ad556719048623c05b845de60821b2915e4620c5a9d58babffb91e10ae49
6
+ metadata.gz: 110e6acb0b10ecbf5056e062d507a72d66c9a0810f9367a1a4fb3385b424acb3da71a2bdc8b8998fb6247380e00ea19f9fc0ef9b6681e1f95693e5265ca29b45
7
+ data.tar.gz: 5628e553fd90faa0f21d443dff45555ea42e4e8dff13dda9a11dc73a646da00885fd15896f8bd19f5aeb28332f1a18a41e9a9a617868efae0017b791779a3693
@@ -22,22 +22,8 @@ module PryTest
22
22
  @tests ||= []
23
23
  end
24
24
 
25
- # All files that define subclasses of this class.
26
- # @note Primarily used in the context of PryTest::Test.
27
- # @example Files are stored in a Hash with the following format.
28
- # {
29
- # "path/to/file1.rb" => ["line 1", "line 2", "line 3", ...],
30
- # "path/to/file2.rb" => ["line 1", "line 2", "line 3", ...]
31
- # }
32
- # @return [Hash]
33
- def files
34
- @files ||= {}
35
- end
36
-
37
25
  # A callback provided by Ruby that is invoked whenever a subclass is created.
38
26
  def inherited(subclass)
39
- file_path = caller[0][0, caller[0].index(/:[0-9]+:/)]
40
- files[file_path] = File.open(file_path).readlines
41
27
  subclasses << subclass
42
28
  end
43
29
 
@@ -59,7 +59,8 @@ module PryTest
59
59
  # end
60
60
  # end
61
61
  def assert(value)
62
- @asserts << assert_info(caller).merge(:value => value)
62
+ info = assert_info(value, caller_locations.first)
63
+ @asserts << info.merge(:value => value)
63
64
 
64
65
  if !value
65
66
  Pry.start unless @options[:disable_pry]
@@ -96,9 +97,10 @@ module PryTest
96
97
 
97
98
  private
98
99
 
99
- # Builds a Hash of assert information for the given call stack.
100
+ # Builds a Hash of assert information for the given assert value & call stack location.
100
101
  #
101
- # @param [Array<String>] stack The call stack to extract info from.
102
+ # @params [Boolean] value The value of assert.
103
+ # @param [Thread::Backtrace::Location] location The call stack location to extract info from.
102
104
  #
103
105
  # @example
104
106
  # {
@@ -108,26 +110,33 @@ module PryTest
108
110
  # }
109
111
  #
110
112
  # @return [Hash]
111
- def assert_info(stack)
112
- file_path = stack[0][0, stack[0].index(/:[0-9]+:/)]
113
- lines = PryTest::Test.files[file_path]
114
- line_num = line_number(stack, 0)
115
- line_index = line_num - 1
116
- line = lines[line_index]
117
- {
118
- :file_path => file_path,
119
- :lines => lines,
120
- :line_num => line_num,
121
- :line => line
113
+ def assert_info(value, location)
114
+ info = {
115
+ :file_path => location.absolute_path,
116
+ :line_num => location.lineno
122
117
  }
118
+
119
+ info.merge! line_info(location) unless value
120
+ info
123
121
  end
124
122
 
125
- # Returns a line number from a call stack.
126
- # @param [Array<String>] stack The call stack to pull a path from.
127
- # @param [Integer] index The index of the call stack entry to use.
128
- # @return [String]
129
- def line_number(stack, index)
130
- stack[index].scan(/:[0-9]+:/).first.gsub(/:/, "").to_i
123
+ # Builds a Hash of line/source information for the given call stack location.
124
+ #
125
+ # @param [Thread::Backtrace::Location] location The call stack location to extract info from.
126
+ #
127
+ # @example
128
+ # {
129
+ # :lines => ["line one", "line two"]
130
+ # :line => "line two"
131
+ # }
132
+ #
133
+ # @return [Hash]
134
+ def line_info(location)
135
+ lines = File.open(location.absolute_path).readlines
136
+ {
137
+ :lines => lines,
138
+ :line => lines[location.lineno]
139
+ }
131
140
  end
132
141
 
133
142
  end
@@ -1,3 +1,3 @@
1
1
  module PryTest
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
@@ -33,12 +33,6 @@ unless ENV["PRY_TEST_DEMO"]
33
33
  assert @Example.tests.first.is_a?(PryTest::TestWrapper)
34
34
  end
35
35
 
36
- test "stores files" do
37
- file = __FILE__
38
- assert @test_test.files[file].is_a?(Array)
39
- assert @test_test.files[file].select{ |l| l.start_with?(" assert @test_test.files[file].select{ |l| l.start_with?(") }.length > 0
40
- end
41
-
42
36
  test ".before" do
43
37
  assert @Example.instance_eval { @before } == @before_callback
44
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-22 00:00:00.000000000 Z
11
+ date: 2015-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry