Permalink
Browse files

init commit

  • Loading branch information...
0 parents commit 598c859251480bcc3c125de2e3b8c68893741ed1 @allenwei committed Jan 16, 2011
@@ -0,0 +1,7 @@
+pkg/*
+*.gem
+.bundle
+*.swp
+.rvm
+/.rvmrc
+/tmp
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in rt.gemspec
+gemspec
@@ -0,0 +1,59 @@
+PATH
+ remote: .
+ specs:
+ rt (0.0.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activesupport (2.3.10)
+ aruba (0.3.2)
+ childprocess (~> 0.1.6)
+ cucumber (~> 0.10.0)
+ rspec (~> 2.3.0)
+ builder (3.0.0)
+ childprocess (0.1.6)
+ ffi (~> 0.6.3)
+ columnize (0.3.2)
+ cucumber (0.10.0)
+ builder (>= 2.1.2)
+ diff-lcs (~> 1.1.2)
+ gherkin (~> 2.3.2)
+ json (~> 1.4.6)
+ term-ansicolor (~> 1.0.5)
+ diff-lcs (1.1.2)
+ ffi (0.6.3)
+ rake (>= 0.8.7)
+ gherkin (2.3.3)
+ json (~> 1.4.6)
+ json (1.4.6)
+ linecache (0.43)
+ rake (0.8.7)
+ rr (1.0.2)
+ rspec (2.3.0)
+ rspec-core (~> 2.3.0)
+ rspec-expectations (~> 2.3.0)
+ rspec-mocks (~> 2.3.0)
+ rspec-core (2.3.1)
+ rspec-expectations (2.3.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.3.0)
+ ruby-debug (0.10.4)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.4.0)
+ ruby-debug-base (0.10.4)
+ linecache (>= 0.3)
+ shoulda (2.11.3)
+ term-ansicolor (1.0.5)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activesupport (~> 2.3.8)
+ aruba (~> 0.3.2)
+ cucumber (~> 0.10.0)
+ rr
+ rt!
+ ruby-debug
+ shoulda
@@ -0,0 +1,44 @@
+rt
+========
+
+A unit test runner
+
+Support run by file number
+Support run by file path pattern
+Support run by file line number
+
+
+Support different format (In development)
+
+
+Installation
+-------
+
+ gem install rt
+
+
+Usage
+-----
+
+ `rt test_file.rb`
+
+ `rt test/**/test_*.rb`
+
+Support specify line number:
+
+ `rt test_file.rb:5`
+
+
+Load Path
+--------
+automatic add "./test" to load path, so you don't need "-Itest" option
+
+
+Roadmap
+=========
+
+* Support red green
+* Support Formatter
+* Support Rspec compatible Formatter
+* Support growl notify
+* Support tag
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
37 bin/rt
@@ -0,0 +1,37 @@
+#!/usr/bin/env ruby
+
+$LOAD_PATH.unshift(File.join("./test"))
+
+require File.join("rt.rb")
+
+ARGV.each do |f|
+ if f =~ /\*/
+ Dir.glob(f) do |test_file|
+ load test_file
+ end
+ elsif f =~ /(.*):(\d+)$/
+ file_name = $1
+ line_num = $2
+ line = `sed -n "#{line_num}p" #{file_name}`
+ test_name = nil
+ %w[UnitTest ActiveSupportTestCase Shoulda].each do |matcher|
+ klass = eval("Rt::Matchers::#{matcher}")
+ break if test_name = klass.test_name(line)
+ end
+ if test_name
+ ARGV << "--name=/#{test_name}/"
+ load file_name
+ else
+ STDERR.puts "Can not find test in file #{file_name} line #{line_num}"
+ exit 1
+ end
+ elsif File.directory?(f)
+ Dir.glob("**/*.rb") do |test_file|
+ load test_file
+ end
+ elsif File.exist?(f)
+ load f
+ end
+
+end
+
@@ -0,0 +1,3 @@
+default: --require features --strict --format progress --tags ~@wip features
+wip: --require features --tags @wip:3 --wip features
+
@@ -0,0 +1,36 @@
+Feature: Runner
+
+ Background:
+ Given a test file "test/test_one.rb" with:
+ """
+ def test_one
+ assert true
+ end
+ """
+ And a test file "test/test_two.rb" with:
+ """
+ def test_two
+ assert true
+ end
+ """
+
+ Scenario: Run single file from command-line
+ When I run "bundle exec rt test/test_one.rb"
+ Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
+ And the exit status should be 0
+
+ Scenario: Run two file from command-line
+ When I run "bundle exec rt test/test_one.rb test/test_two.rb"
+ Then the stdout should contain "2 tests, 2 assertions, 0 failures, 0 errors"
+ And the exit status should be 0
+
+ Scenario: Run tests in folder
+ When I run "bundle exec rt test"
+ Then the stdout should contain "2 tests, 2 assertions, 0 failures, 0 errors"
+ And the exit status should be 0
+
+ Scenario: Run tests with regular expression
+ When I run "bundle exec rt **/*_one.rb"
+ Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
+ And the exit status should be 0
+
@@ -0,0 +1,88 @@
+Feature: run single test according to line number
+
+ Scenario: Support ActiveSupport::TestCase
+ Given a file named "test_one.rb" with:
+ """
+ require 'test/unit'
+ require 'active_support/test_case'
+
+ class TestOne < ActiveSupport::TestCase
+ test "test one" do
+ assert true
+ end
+
+ test 'test two' do
+ assert true
+ end
+ end
+ """
+ When I successfully run "bundle exec rt test_one.rb:5"
+ Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
+ When I successfully run "bundle exec rt test_one.rb:9"
+ Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
+
+ Scenario: Support shoulda should method
+ Given a file named "test_one.rb" with:
+ """
+ require 'test/unit'
+ require 'active_support/test_case'
+ require 'shoulda'
+
+ class TestOne < ActiveSupport::TestCase
+ should "test one" do
+ assert true
+ end
+
+ should 'test two' do
+ assert true
+ end
+ end
+ """
+ When I successfully run "bundle exec rt test_one.rb:6"
+ Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
+ When I successfully run "bundle exec rt test_one.rb:10"
+ Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
+
+ Scenario: Support shoulda should method
+ Given a file named "test_one.rb" with:
+ """
+ require 'test/unit'
+ require 'active_support/test_case'
+ require 'shoulda'
+
+ class TestOne < ActiveSupport::TestCase
+ context "a context" do
+ should "test one" do
+ assert true
+ end
+ end
+
+ should 'test two' do
+ assert true
+ end
+ end
+ """
+ When I successfully run "bundle exec rt test_one.rb:6"
+ Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
+ When I successfully run "bundle exec rt test_one.rb:12"
+ Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
+
+
+
+ Scenario: get warning can not find test if can not find test in spacified line
+ Given a file named "test_one.rb" with:
+ """
+ require 'test/unit'
+ require 'active_support/test_case'
+
+ class TestOne < ActiveSupport::TestCase
+ test "test one" do
+ assert true
+ end
+ end
+ """
+ When I run "bundle exec rt test_one.rb:1"
+ Then the stderr should contain "Can not find test in file test_one.rb line 1"
+ And the exit status should be 1
+
+
@@ -0,0 +1,19 @@
+Feature: Load path when running test
+
+ Scenario: default load path is "test" folder
+ Given a file named "test/test_helper.rb" with:
+ """
+ puts 'load test_helper'
+ """
+ And a test file "test_one.rb" with:
+ """
+ require 'test_helper'
+
+ def test_one
+ assert true
+ end
+ """
+ When I run "bundle exec rt test_one.rb"
+ Then the stdout should contain "load test_helper"
+ And the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
+ And the exit status should be 0
@@ -0,0 +1,9 @@
+Given /^a test file "(.*)" with:$/ do |filename, content|
+ Given "a file named \"#{filename}\" with:", <<-EOF
+ require 'test/unit'
+
+ class #{camelize(File.basename(filename,'.rb'))} < Test::Unit::TestCase
+ #{content}
+ end
+ EOF
+end
@@ -0,0 +1,9 @@
+require 'aruba/cucumber'
+
+module Rt::World
+ def camelize(str)
+ str.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
+ end
+end
+
+World(Rt::World)
@@ -0,0 +1,11 @@
+require 'rt/matcher'
+require 'rt/matchers/unit_test'
+require 'rt/matchers/active_support_test_case'
+require 'rt/matchers/shoulda'
+
+
+module Rt
+ module Matchers
+
+ end
+end
@@ -0,0 +1,14 @@
+module Rt
+ class Matcher
+ def self.match(arg)
+ raise "Not implement"
+ end
+
+ def self.test_name(line)
+ if match = self.match(line)
+ return match.gsub!(/\s+/,"_")
+ end
+ return nil
+ end
+ end
+end
@@ -0,0 +1,9 @@
+module Rt
+ module Matchers
+ class ActiveSupportTestCase < Rt::Matcher
+ def self.match(arg)
+ return arg[/\s*test\s+["']+(.*)["']+\s+do/,1]
+ end
+ end
+ end
+end
@@ -0,0 +1,14 @@
+module Rt
+ module Matchers
+ class Shoulda < Rt::Matcher
+ def self.match(arg)
+ return arg[/\s*[should|context]+\s+["']+(.*)["']+\s+do/,1]
+ end
+
+ def self.test_name(line)
+ return self.match(line)
+ end
+ end
+ end
+end
+
@@ -0,0 +1,11 @@
+module Rt
+ module Matchers
+ class UnitTest < Rt::Matcher
+ def self.match(arg)
+ return arg[/\s*def\s+(test\S+)\s*/,1]
+ end
+ end
+ end
+end
+
+
@@ -0,0 +1,3 @@
+module Rt
+ VERSION = "0.0.1"
+end
Oops, something went wrong.

0 comments on commit 598c859

Please sign in to comment.