Skip to content

Commit

Permalink
Rebrand to pry-test.
Browse files Browse the repository at this point in the history
Also changed the workflow to always use pry.
  • Loading branch information
hopsoft committed Nov 17, 2014
1 parent ce08ae2 commit b6a3a47
Show file tree
Hide file tree
Showing 29 changed files with 99 additions and 124 deletions.
47 changes: 22 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[![Lines of Code](http://img.shields.io/badge/loc-480-brightgreen.svg)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
[![Code Status](https://codeclimate.com/github/hopsoft/micro_test.png)](https://codeclimate.com/github/hopsoft/micro_test)
[![Dependency Status](https://gemnasium.com/hopsoft/micro_test.png)](https://gemnasium.com/hopsoft/micro_test)
[![Build Status](https://travis-ci.org/hopsoft/micro_test.png)](https://travis-ci.org/hopsoft/micro_test)
[![Coverage Status](https://img.shields.io/coveralls/hopsoft/micro_test.svg)](https://coveralls.io/r/hopsoft/micro_test?branch=master)
[![Code Status](https://codeclimate.com/github/hopsoft/pry-test.png)](https://codeclimate.com/github/hopsoft/pry-test)
[![Dependency Status](https://gemnasium.com/hopsoft/pry-test.png)](https://gemnasium.com/hopsoft/pry-test)
[![Build Status](https://travis-ci.org/hopsoft/pry-test.png)](https://travis-ci.org/hopsoft/pry-test)
[![Coverage Status](https://img.shields.io/coveralls/hopsoft/pry-test.svg)](https://coveralls.io/r/hopsoft/pry-test?branch=master)

# MicroTest
# PryTest

#### Speed up your test workflow: `fail` -> `pry` -> `pass`

Expand All @@ -15,15 +15,15 @@
* Async test runs
* Works with all major Rubies

[An important note on debugging test failures with Pry.](https://github.com/hopsoft/micro_test/wiki/Debug-Test-Failures-with-Pry#gemfile-considerations)
[An important note on debugging test failures with Pry.](https://github.com/hopsoft/pry-test/wiki/Debug-Test-Failures-with-Pry#gemfile-considerations)

## The API

Everything you need to know about MicroTest's API is outlined here.
Everything you need to know about PryTest's API is outlined here.

<table>
<tr>
<td><strong><code>MicroTest::Test</code></strong></td>
<td><strong><code>PryTest::Test</code></strong></td>
<td></td>
</tr>
<tr>
Expand Down Expand Up @@ -70,7 +70,7 @@ Everything you need to know about MicroTest's API is outlined here.
The entire public interface is used in this basic example.

```ruby
class MathTest < MicroTest::Test
class MathTest < PryTest::Test

before do
# runs before each test method
Expand All @@ -89,45 +89,42 @@ end

## Get Started

MicroTest ships with a demo so you can try it out easily.
PryTest ships with a demo so you can try it out easily.

```sh
gem install micro_test
mt --help
mt --demo
gem install pry-test
pry-test --help
pry-test --demo
```

Try some advanced features.

```sh
mt --demo --pry
mt --demo --async
mt --demo --formatter doc
pry-test --demo --pry
pry-test --demo --async
pry-test --demo --formatter doc
```

## Testing Your Own Projects

MicroTest assumes your test directory is located at `PROJECT_ROOT/test`;
PryTest assumes your test directory is located at `PROJECT_ROOT/test`;
however, this isn't a requirement. You can indicate your test directory location.

```sh
mt /path/to/test/dir
pry-test /path/to/test/dir
```

If you have multiple versions of MicroTest installed,
If you have multiple versions of PryTest installed,
it's safest to run your tests with `bundle exec`.

```sh
bundle exec mt /path/to/test/dir
bundle exec pry-test /path/to/test/dir
```

MicroTest is small & unobtrusive.
PryTest is small & unobtrusive.
It plays nice with other test frameworks, & can be introduced to existing projects incrementally.

## Advanced

[See the wiki](https://github.com/hopsoft/micro_test/wiki)
[See the wiki](https://github.com/hopsoft/pry-test/wiki)
to troubleshoot or get help with more advanced topics.

*Also, checkout [MicroMock](https://github.com/hopsoft/micro_mock) for a lightweight mocking solution.*

2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ task :default => [:test]

desc "Runs the test suite."
task :test do
exec File.expand_path("../bin/mt", __FILE__)
exec File.expand_path("../bin/pry-test", __FILE__)
end

54 changes: 14 additions & 40 deletions bin/mt → bin/pry-test
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/usr/bin/env ruby
require "optparse"
require_relative "../lib/micro_test"
require_relative "../lib/pry-test"

include MicroTest::Color
include PryTest::Color

# setup the formatters list ---------------------------------------------------
formatter_names = MicroTest.formatters.map(&:short_name).sort
formatter_names = PryTest.formatters.map(&:short_name).sort

# setup the options -----------------------------------------------------------
options = {}
parser = OptionParser.new do |opts|
opts.banner = "MicroTest Usage: mt [options] /path/to/test/dir_or_file"
opts.banner = "PryTest Usage: pry-test [options] /path/to/test/dir_or_file"

desc = "Runs tests asynchronously."
opts.on("-a", "--async", desc) { |value| options[:async] = value }

desc = "Runs the MicroTest test suite and some additional demo tests."
desc = "Runs the PryTest test suite and some additional demo tests."
opts.on("--demo", desc) { |value| options[:demo] = value }

desc = "The formatter to use. [#{formatter_names.join(", ")}]"
Expand All @@ -26,43 +26,18 @@ parser = OptionParser.new do |opts|
desc = "Stops the test run after the first failure. "
opts.on("--fail-fast", desc) { |value| options[:fail_fast] = value }

desc = "Starts a PRY session whenever a test fails. "
opts.on("--pry", desc) { |value| options[:pry] = value }

opts.on("-v", "--version", "Show version.") do
puts "MicroTest #{MicroTest::VERSION}"
puts "PryTest #{PryTest::VERSION}"
exit 0
end

opts.on_tail("-h", "--help", "Show this message.") do
puts opts
exit 0
end

end
parser.parse!

# apply rules to the options --------------------------------------------------
if RUBY_ENGINE == "jruby"
if options[:pry]
options[:pry] = nil
puts red("Unfortunately the pry option is not available on jruby")
puts red("due to a dependency on pry-stack_explorer & binding_of_caller.")
puts "However, the pry workflow is awesome. Switch to #{green "mri 1.9"} to try it."
end
end
if RUBY_ENGINE == "rbx"
if options[:pry]
options[:pry] = nil
puts red("Unfortunately the pry option is not available on rubinius at this time")
puts red("due to weird behavior related to pry & pry-stack_explorer.")
puts "However, the pry workflow is awesome. Switch to #{green "mri 1.9"} to try it."
end
end
if options[:async] && options[:pry]
options[:pry] = nil
puts red("Disabling pry while runing in async mode to avoid interleaved pry session chaos.")
end
ENV["MT_DEMO"] = "true" if options[:demo]

# setup the test path ---------------------------------------------------------
Expand All @@ -82,21 +57,23 @@ else
end

# setup the formatter ---------------------------------------------------------
formatter = MicroTest.formatters.find { |f| f.short_name == options[:formatter] }
formatter = PryTest.formatters.find { |f| f.short_name == options[:formatter] }
formatter ||= begin
if options[:async]
MicroTest.formatters.find { |f| f.short_name == "default_async" }
PryTest.formatters.find { |f| f.short_name == "default_async" }
else
MicroTest.formatters.find { |f| f.short_name == "default" }
PryTest.formatters.find { |f| f.short_name == "default" }
end
end

# setup the test runner -------------------------------------------------------
runner = MicroTest::Runner.new(formatter.new, options)
runner = PryTest::Runner.new(formatter.new, options)

# setup pry -------------------------------------------------------------------
if options[:pry]

if RUBY_ENGINE == "jruby" || RUBY_ENGINE == "rbx" || options[:async]
puts red("Disabling pry when running with: #{RUBY_ENGINE}; #{options.inspect}")
exit runner.run
else
begin
require "pry"
require "pry-stack_explorer"
Expand All @@ -123,7 +100,4 @@ if options[:pry]
end

exit Pry.rescue { runner.run }
else
exit runner.run
end

5 changes: 0 additions & 5 deletions lib/micro_test.rb

This file was deleted.

5 changes: 5 additions & 0 deletions lib/pry-test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
path = File.expand_path("../pry-test/*.rb", __FILE__)
Dir[path].each { |file| require file }

path = File.expand_path("../pry-test/formatters/**/*.rb", __FILE__)
Dir[path].each { |file| require file }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module MicroTest
module PryTest

class << self
def formatters
Expand All @@ -14,7 +14,7 @@ class BaseFormatter

class << self
def inherited(subclass)
MicroTest.formatters << subclass
PryTest.formatters << subclass
end

def short_name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module MicroTest
module PryTest
module Color
extend self

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative "base_formatter"

module MicroTest
class DefaultAsyncFormatter < MicroTest::BaseFormatter
module PryTest
class DefaultAsyncFormatter < PryTest::BaseFormatter
set_short_name "default_async"

def after_test(test)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative "base_formatter"

module MicroTest
class DefaultFormatter < MicroTest::BaseFormatter
module PryTest
class DefaultFormatter < PryTest::BaseFormatter
set_short_name "default"

def before_class(test_class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_relative "color"

module MicroTest
module PryTest
class Template
include Color

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

--------------------------------------------------------------------------------
<%= green "#{@context.passed} Passed" -%>, <%= red "#{@context.failed} Failed" -%>
<%= green "#{@context.passed} Passed" -%>
<% if @context.failed > 0 -%>
, <%= red "#{@context.failed} Failed" -%>
<% end -%>
Finished in <%= yellow @context.duration %> seconds.
--------------------------------------------------------------------------------

8 changes: 4 additions & 4 deletions lib/micro_test/runner.rb → lib/pry-test/runner.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "os"
require "thread"

module MicroTest
module PryTest
class Runner
class << self
attr_accessor :exit
Expand All @@ -16,7 +16,7 @@ def initialize(formatter, options={})
end

def run
test_classes = MicroTest::Test.subclasses.shuffle
test_classes = PryTest::Test.subclasses.shuffle
tests = test_classes.map{ |klass| klass.tests }.flatten
formatter.before_suite(test_classes)
start = Time.now
Expand Down Expand Up @@ -57,11 +57,11 @@ def run_threads
threads = []
thread_count = OS.cpu_count
thread_count = 2 if thread_count < 2
puts "MicroTest is running #{thread_count} threads."
puts "PryTest is running #{thread_count} threads."
thread_count.times do
threads << Thread.new do
while @tests.empty? == false
Thread.current.kill if MicroTest::Runner.exit
Thread.current.kill if PryTest::Runner.exit
@tests.pop.invoke(@formatter, @options)
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/micro_test/test.rb → lib/pry-test/test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module MicroTest
module PryTest

# Superclass for all test classes.
# @example Create a subclass with a test.
# class SimpleTest < MicroTest::Test
# class SimpleTest < PryTest::Test
# test "common sense" do
# assert 1 > 0
# end
Expand All @@ -11,19 +11,19 @@ class Test
class << self

# All subclasses of this class.
# @return [Array<MicroTest::Test>]
# @return [Array<PryTest::Test>]
def subclasses
@subclasses ||= []
end

# All individual tests defined in this class.
# @return [Array<MicroTest::TestWrapper>]
# @return [Array<PryTest::TestWrapper>]
def tests
@tests ||= []
end

# All files that define subclasses of this class.
# @note Primarily used in the context of MicroTest::Test.
# @note Primarily used in the context of PryTest::Test.
# @example Files are stored in a Hash with the following format.
# {
# "path/to/file1.rb" => ["line 1", "line 2", "line 3", ...],
Expand Down Expand Up @@ -68,13 +68,13 @@ def after(what=nil, &block)
# @yield A block that defines the test code.
#
# @example
# class SimpleTest < MicroTest::Test
# class SimpleTest < PryTest::Test
# test "common sense" do
# assert 1 > 0
# end
# end
def test(desc, &block)
wrapper = MicroTest::TestWrapper.new(self, desc, &block)
wrapper = PryTest::TestWrapper.new(self, desc, &block)
wrapper.create_method(:before, &@before) if @before
wrapper.create_method(:after, &@after) if @after
tests << wrapper
Expand Down
Loading

0 comments on commit b6a3a47

Please sign in to comment.