minitest-utils 0.1.1 → 0.1.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: 53f5939edeb86d8fc6b8c73a994a6a71c489ee6f
4
- data.tar.gz: 7fb39036503556bb6736fdde724c253b28059b0a
3
+ metadata.gz: 700f67bcfb5d5fe53a2a75b7bf3ec8843ccc82f9
4
+ data.tar.gz: 9d5ad7d010ddc713d2ee5e420e93ccd3a9afec0c
5
5
  SHA512:
6
- metadata.gz: 7f8950291223aafaaad93d73c5561467dc81dfc45e4d090c3657da1d628fe2e9ece5517c323100d4236dd6080370d5a397fe471d026c25bac44ab73d34740f30
7
- data.tar.gz: 109bd388af199abc5176793cf89d1d963fce8ef59eaccad5db0e319e4694e76d28d95435bdb07257059c4c94998b5f0550ecbd900cfba9daddc1bcfdfa606779
6
+ metadata.gz: caf2e42d4875292a0bb788cefce0f9ea3d3cbe76925250401c1e84e7b236bf572158e6b1b5d03c87ad7e53e55ff53b16173be74823295bc562899312fe9cebea
7
+ data.tar.gz: 0b1ea576e5cabae344f583f8a623164a299f1b6024c6889f37bccad16705e68c62563ea08628fce6ed610a678d328f0b8d6e5bbf47096d0e7541f1ec8bbbb58f
data/README.md CHANGED
@@ -25,6 +25,20 @@ Or install it yourself as:
25
25
 
26
26
  $ gem install minitest-utils
27
27
 
28
+ ## Defining tests
29
+
30
+ This gem adds the `Minitest::Test.test` method, so you can easy define your methods like the following:
31
+
32
+ ```ruby
33
+ class SampleTest < Minitest::Test
34
+ test 'useless test' do
35
+ assert true
36
+ end
37
+ end
38
+ ```
39
+
40
+ This is equivalent to defining a method named `test_useless_test`. You can also skip the block, which will define a [flunk](https://github.com/seattlerb/minitest/blob/77120c5b2511c4665610cda06c8058c801b28e7f/lib/minitest/assertions.rb#L477-L480) call.
41
+
28
42
  ## Screenshots
29
43
 
30
44
  ![](https://raw.githubusercontent.com/fnando/minitest-utils/master/screenshots/light-failing.png)
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
 
4
- Rake::TestTask.new(:spec) do |t|
5
- t.libs << 'spec'
6
- t.test_files = FileList['spec/**/*_spec.rb']
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/**/*_test.rb']
7
7
  t.verbose = true
8
8
  end
9
9
 
10
- task :default => :spec
10
+ task :default => :test
@@ -0,0 +1,18 @@
1
+ module Minitest
2
+ class Test
3
+ def self.test(name, &block)
4
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
5
+ defined = method_defined? test_name
6
+
7
+ raise "#{test_name} is already defined in #{self}" if defined
8
+
9
+ if block_given?
10
+ define_method(test_name, &block)
11
+ else
12
+ define_method(test_name) do
13
+ flunk "No implementation provided for #{name}"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -79,7 +79,7 @@ module Minitest
79
79
  end
80
80
 
81
81
  def display_replay_command(result)
82
- location = filter_backtrace(result.failure.backtrace).first.gsub(/:\d+.*?$/, '')
82
+ location = find_test_file(result)
83
83
  command = %[rake TEST=#{location} TESTOPTS="--name=#{result.name}"]
84
84
  str = "\n"
85
85
  str << color(command, :red)
@@ -87,6 +87,12 @@ module Minitest
87
87
  io.print str
88
88
  end
89
89
 
90
+ def find_test_file(result)
91
+ filter_backtrace(result.failure.backtrace)
92
+ .find {|line| line.match(%r(^(test|spec)/.*?_(test|spec).rb)) }
93
+ .gsub(/:\d+.*?$/, '')
94
+ end
95
+
90
96
  def backtrace(backtrace)
91
97
  backtrace = filter_backtrace(backtrace).map {|line| location(line) }
92
98
  return if backtrace.empty?
@@ -94,10 +100,11 @@ module Minitest
94
100
  end
95
101
 
96
102
  def location(location)
103
+ location = File.expand_path(location[/^([^:]+)/, 1])
104
+
97
105
  return location unless location.start_with?(Dir.pwd)
98
106
 
99
- location = location.gsub(%r[^#{Regexp.escape(Dir.pwd)}/], '')
100
- "./#{location}"
107
+ location.gsub(%r[^#{Regexp.escape(Dir.pwd)}/], '')
101
108
  end
102
109
 
103
110
  def filter_backtrace(backtrace)
@@ -1,5 +1,5 @@
1
1
  module Minitest
2
2
  module Utils
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ module Minitest
3
3
  require 'minitest'
4
4
  require 'minitest/utils/version'
5
5
  require 'minitest/utils/reporter'
6
+ require 'minitest/utils/extension'
6
7
  require 'minitest/utils/test_notifier_reporter'
7
8
  end
8
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-30 00:00:00.000000000 Z
11
+ date: 2015-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -81,6 +81,7 @@ files:
81
81
  - bin/rake
82
82
  - bin/setup
83
83
  - lib/minitest/utils.rb
84
+ - lib/minitest/utils/extension.rb
84
85
  - lib/minitest/utils/rails.rb
85
86
  - lib/minitest/utils/rails/capybara.rb
86
87
  - lib/minitest/utils/rails/factory_girl.rb