Skip to content

Commit

Permalink
Omg, I don't even know what's happening >.<
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshCheek committed May 27, 2015
1 parent 284fcf0 commit 1a4e9ba
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
74 changes: 74 additions & 0 deletions features/mrspec.feature
Expand Up @@ -88,6 +88,39 @@ Feature: mrspec
And stdout does not include "Minitest.run_one_method"


Scenario: Minitest::Spec definitions without bodies show line of the declaration in the backtrace, and not the full backtrace
Given the file "skip_spec.rb":
"""
require 'minitest/spec'
describe 'a' do
it 'has no body'
it('calls skip') { skip }
end
class A < Minitest::Spec
it 'has no body'
it('calls skip') { skip }
end
class Wat < Minitest::Test
extend Minitest::Spec::DSL
register_spec_type /^lol/, self
end
describe 'lol' do
it 'has no body'
it('calls skip') { skip }
end
"""
When I run "mrspec skip_spec.rb"
Then stdout includes "skip_spec.rb:3"
Then stdout includes "skip_spec.rb:4"
Then stdout includes "skip_spec.rb:8"
Then stdout includes "skip_spec.rb:9"
Then stdout includes "skip_spec.rb:17"
Then stdout includes "skip_spec.rb:18"
And stdout does not include "/mrspec/"


Scenario: Works with Minitest::Test, choosing intelligent names
Given the file "some_test.rb":
"""
Expand Down Expand Up @@ -313,6 +346,47 @@ Feature: mrspec
And stdout includes "tagged with 1 only"
And stdout includes "untagged"


Scenario: Can add metadata to Minitest::Specs
Given the file "a_spec.rb":
"""
require 'minitest/spec'
describe 'First' do
classmeta runthis: true
it('spec1') { }
end
class MySpec < Minitest::Spec
meta runthis: true
it('spec2') { }
it('spec3') { }
it('spec4') { }
end
class Wat < Minitest::Test
extend Minitest::Spec::DSL
register_spec_type /^Lol/, self
def bbq
'rofl'
end
end
describe 'LolSpec!' do
meta runthis: true
it 'has different inheritance' do
assert self.kind_of? Wat
end
end
"""
When I run 'mrspec -t runthis a_spec.rb'
Then the program ran successfully
And stdout includes "3 examples"
And stdout includes "0 failures"



Scenario: Intelligently formats Minitest's assertions
Given the file "test/some_assertions.rb":
"""
Expand Down
24 changes: 23 additions & 1 deletion lib/mrspec/declare_minitests.rb
@@ -1,6 +1,28 @@
require 'minitest'
require 'mrspec/minitest_assertion_for_rspec'

require 'minitest/spec'

dsl = Minitest::Spec::DSL
it_location = dsl.instance_method(:it).source_location
dsl.instance_methods
.map { |name| [name, dsl.instance_method(name)] }
.select { |name, method| method.source_location == it_location }
.each { |name, method|
# Redefining Minitest::Spec#it, and aliases to record the block in the user's code,
# this way the backtrace lines up with the logical definition site,
# and we don't risk filtering the entire backtrace
# which causes RSpec to abandon th filter, and the entire backtrace is quite distracting
dsl.__send__ :define_method, name do |*args, &block|
callsite = caller[0] || 'unknown-location:0:' # can't think of a case where this wouldn't be true, but just in case
callsite =~ /^(.*?):(\d+):/
caller_filename, caller_lineno = $1, $2.to_i
block ||= eval 'proc { skip "(no tests defined)" }', binding, caller_filename, caller_lineno
method.bind(self).call(*args, &block)
end
}


module MRspec
module DeclareMinitests
extend self
Expand Down Expand Up @@ -46,7 +68,7 @@ def wrap_class(rspec, klass)

def wrap_test(example_group, klass, mname)
metadata = klass.example_metadata[mname.intern]
example = example_group.example example_name(mname), metadata do
example = example_group.example example_name(mname), metadata do
instance = Minitest.run_one_method klass, mname
next if instance.passed?
pending 'skipped' if instance.skipped?
Expand Down
1 change: 1 addition & 0 deletions test/test_mrspec.rb
Expand Up @@ -155,6 +155,7 @@ def test_a; end
it 'omits minitest code from the backtrace'
it 'omits rspec code from the backtrace'
it 'omits mrspec code from the backtrace'
it 'allows Minitest::Spec to be declared without bodies, and backtrace shows the call to the it block'
end

describe 'identifying which test to run' do
Expand Down

0 comments on commit 1a4e9ba

Please sign in to comment.