Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

init commit

  • Loading branch information...
commit 598c859251480bcc3c125de2e3b8c68893741ed1 0 parents
allenwei authored January 17, 2011
7  .gitignore
... ...
@@ -0,0 +1,7 @@
  1
+pkg/*
  2
+*.gem
  3
+.bundle
  4
+*.swp
  5
+.rvm
  6
+/.rvmrc
  7
+/tmp
4  Gemfile
... ...
@@ -0,0 +1,4 @@
  1
+source "http://rubygems.org"
  2
+
  3
+# Specify your gem's dependencies in rt.gemspec
  4
+gemspec
59  Gemfile.lock
... ...
@@ -0,0 +1,59 @@
  1
+PATH
  2
+  remote: .
  3
+  specs:
  4
+    rt (0.0.1)
  5
+
  6
+GEM
  7
+  remote: http://rubygems.org/
  8
+  specs:
  9
+    activesupport (2.3.10)
  10
+    aruba (0.3.2)
  11
+      childprocess (~> 0.1.6)
  12
+      cucumber (~> 0.10.0)
  13
+      rspec (~> 2.3.0)
  14
+    builder (3.0.0)
  15
+    childprocess (0.1.6)
  16
+      ffi (~> 0.6.3)
  17
+    columnize (0.3.2)
  18
+    cucumber (0.10.0)
  19
+      builder (>= 2.1.2)
  20
+      diff-lcs (~> 1.1.2)
  21
+      gherkin (~> 2.3.2)
  22
+      json (~> 1.4.6)
  23
+      term-ansicolor (~> 1.0.5)
  24
+    diff-lcs (1.1.2)
  25
+    ffi (0.6.3)
  26
+      rake (>= 0.8.7)
  27
+    gherkin (2.3.3)
  28
+      json (~> 1.4.6)
  29
+    json (1.4.6)
  30
+    linecache (0.43)
  31
+    rake (0.8.7)
  32
+    rr (1.0.2)
  33
+    rspec (2.3.0)
  34
+      rspec-core (~> 2.3.0)
  35
+      rspec-expectations (~> 2.3.0)
  36
+      rspec-mocks (~> 2.3.0)
  37
+    rspec-core (2.3.1)
  38
+    rspec-expectations (2.3.0)
  39
+      diff-lcs (~> 1.1.2)
  40
+    rspec-mocks (2.3.0)
  41
+    ruby-debug (0.10.4)
  42
+      columnize (>= 0.1)
  43
+      ruby-debug-base (~> 0.10.4.0)
  44
+    ruby-debug-base (0.10.4)
  45
+      linecache (>= 0.3)
  46
+    shoulda (2.11.3)
  47
+    term-ansicolor (1.0.5)
  48
+
  49
+PLATFORMS
  50
+  ruby
  51
+
  52
+DEPENDENCIES
  53
+  activesupport (~> 2.3.8)
  54
+  aruba (~> 0.3.2)
  55
+  cucumber (~> 0.10.0)
  56
+  rr
  57
+  rt!
  58
+  ruby-debug
  59
+  shoulda
44  README.md
Source Rendered
... ...
@@ -0,0 +1,44 @@
  1
+rt
  2
+========
  3
+
  4
+A unit test runner 
  5
+
  6
+Support run by file number 
  7
+Support run by file path pattern 
  8
+Support run by file line number 
  9
+
  10
+
  11
+Support different format (In development)
  12
+
  13
+
  14
+Installation 
  15
+-------
  16
+
  17
+  gem install rt
  18
+
  19
+
  20
+Usage
  21
+-----
  22
+
  23
+  `rt test_file.rb`
  24
+
  25
+  `rt test/**/test_*.rb`  
  26
+
  27
+Support specify line number:
  28
+
  29
+  `rt test_file.rb:5` 
  30
+
  31
+
  32
+Load Path
  33
+--------
  34
+automatic add "./test" to load path, so you don't need "-Itest" option
  35
+
  36
+
  37
+Roadmap
  38
+=========
  39
+
  40
+* Support red green
  41
+* Support Formatter  
  42
+* Support Rspec compatible Formatter
  43
+* Support growl notify
  44
+* Support tag
2  Rakefile
... ...
@@ -0,0 +1,2 @@
  1
+require 'bundler'
  2
+Bundler::GemHelper.install_tasks
37  bin/rt
... ...
@@ -0,0 +1,37 @@
  1
+#!/usr/bin/env ruby 
  2
+
  3
+$LOAD_PATH.unshift(File.join("./test"))
  4
+
  5
+require File.join("rt.rb")
  6
+
  7
+ARGV.each do |f|
  8
+  if f =~ /\*/ 
  9
+    Dir.glob(f) do |test_file|
  10
+    load test_file
  11
+    end
  12
+  elsif f =~ /(.*):(\d+)$/ 
  13
+    file_name = $1
  14
+    line_num = $2
  15
+    line = `sed -n "#{line_num}p" #{file_name}` 
  16
+    test_name = nil
  17
+    %w[UnitTest ActiveSupportTestCase Shoulda].each do |matcher|
  18
+      klass = eval("Rt::Matchers::#{matcher}") 
  19
+      break if test_name = klass.test_name(line) 
  20
+    end
  21
+    if test_name
  22
+      ARGV << "--name=/#{test_name}/"
  23
+      load file_name
  24
+    else 
  25
+      STDERR.puts "Can not find test in file #{file_name} line #{line_num}"
  26
+      exit 1
  27
+    end
  28
+  elsif File.directory?(f)  
  29
+    Dir.glob("**/*.rb") do |test_file|
  30
+      load test_file
  31
+    end
  32
+  elsif File.exist?(f)
  33
+    load f
  34
+  end
  35
+
  36
+end
  37
+
3  cucumber.yml
... ...
@@ -0,0 +1,3 @@
  1
+default: --require features --strict --format progress --tags ~@wip features
  2
+wip:     --require features --tags @wip:3 --wip features
  3
+
36  features/cli.feature
... ...
@@ -0,0 +1,36 @@
  1
+Feature: Runner 
  2
+
  3
+  Background:
  4
+    Given a test file "test/test_one.rb" with:
  5
+      """
  6
+        def test_one  
  7
+          assert true
  8
+        end
  9
+      """
  10
+    And a test file "test/test_two.rb" with:
  11
+      """
  12
+        def test_two
  13
+          assert true
  14
+        end
  15
+      """
  16
+
  17
+  Scenario: Run single file from command-line 
  18
+    When I run "bundle exec rt test/test_one.rb" 
  19
+    Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
  20
+    And the exit status should be 0 
  21
+
  22
+  Scenario: Run two file from command-line 
  23
+    When I run "bundle exec rt test/test_one.rb test/test_two.rb" 
  24
+    Then the stdout should contain "2 tests, 2 assertions, 0 failures, 0 errors"
  25
+    And the exit status should be 0 
  26
+
  27
+  Scenario: Run tests in folder
  28
+    When I run "bundle exec rt test" 
  29
+    Then the stdout should contain "2 tests, 2 assertions, 0 failures, 0 errors"
  30
+    And the exit status should be 0 
  31
+
  32
+  Scenario: Run tests with regular expression
  33
+    When I run "bundle exec rt **/*_one.rb" 
  34
+    Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
  35
+    And the exit status should be 0 
  36
+
88  features/cli_line_number.feature
... ...
@@ -0,0 +1,88 @@
  1
+Feature: run single test according to line number
  2
+
  3
+  Scenario: Support ActiveSupport::TestCase 
  4
+    Given a file named "test_one.rb" with: 
  5
+    """ 
  6
+    require 'test/unit'
  7
+    require 'active_support/test_case'
  8
+
  9
+    class TestOne < ActiveSupport::TestCase
  10
+    test "test one" do 
  11
+    assert true
  12
+    end
  13
+
  14
+    test 'test two' do 
  15
+    assert true
  16
+    end
  17
+    end
  18
+    """
  19
+    When I successfully run "bundle exec rt test_one.rb:5" 
  20
+    Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
  21
+    When I successfully run "bundle exec rt test_one.rb:9" 
  22
+    Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
  23
+
  24
+  Scenario: Support shoulda should method
  25
+    Given a file named "test_one.rb" with: 
  26
+    """ 
  27
+    require 'test/unit'
  28
+    require 'active_support/test_case'
  29
+    require 'shoulda'
  30
+
  31
+    class TestOne < ActiveSupport::TestCase
  32
+      should "test one" do 
  33
+        assert true
  34
+      end
  35
+
  36
+      should 'test two' do 
  37
+        assert true
  38
+      end
  39
+    end
  40
+    """
  41
+    When I successfully run "bundle exec rt test_one.rb:6" 
  42
+    Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
  43
+    When I successfully run "bundle exec rt test_one.rb:10" 
  44
+    Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
  45
+
  46
+  Scenario: Support shoulda should method
  47
+    Given a file named "test_one.rb" with: 
  48
+    """ 
  49
+    require 'test/unit'
  50
+    require 'active_support/test_case'
  51
+    require 'shoulda'
  52
+
  53
+    class TestOne < ActiveSupport::TestCase
  54
+      context "a context" do 
  55
+        should "test one" do 
  56
+          assert true
  57
+        end
  58
+      end
  59
+
  60
+      should 'test two' do 
  61
+        assert true
  62
+      end
  63
+    end
  64
+    """
  65
+    When I successfully run "bundle exec rt test_one.rb:6" 
  66
+    Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
  67
+    When I successfully run "bundle exec rt test_one.rb:12" 
  68
+    Then the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
  69
+
  70
+
  71
+
  72
+  Scenario: get warning can not find test if can not find test in spacified line 
  73
+    Given a file named "test_one.rb" with: 
  74
+    """ 
  75
+    require 'test/unit'
  76
+    require 'active_support/test_case'
  77
+
  78
+    class TestOne < ActiveSupport::TestCase
  79
+    test "test one" do 
  80
+    assert true
  81
+    end
  82
+    end
  83
+    """
  84
+    When I run "bundle exec rt test_one.rb:1" 
  85
+    Then the stderr should contain "Can not find test in file test_one.rb line 1"
  86
+    And the exit status should be 1
  87
+
  88
+
19  features/cli_load_path.feature
... ...
@@ -0,0 +1,19 @@
  1
+Feature: Load path when running test 
  2
+
  3
+  Scenario: default load path is "test" folder 
  4
+    Given a file named "test/test_helper.rb" with: 
  5
+      """
  6
+      puts 'load test_helper' 
  7
+      """
  8
+    And a test file "test_one.rb" with: 
  9
+      """ 
  10
+      require 'test_helper' 
  11
+
  12
+      def test_one 
  13
+        assert true
  14
+      end
  15
+      """
  16
+      When I run "bundle exec rt test_one.rb" 
  17
+      Then the stdout should contain "load test_helper"
  18
+      And the stdout should contain "1 tests, 1 assertions, 0 failures, 0 errors"
  19
+      And the exit status should be 0 
9  features/step_definitions/test_file_helper_step.rb
... ...
@@ -0,0 +1,9 @@
  1
+Given /^a test file "(.*)" with:$/ do |filename, content|
  2
+  Given "a file named \"#{filename}\" with:", <<-EOF
  3
+    require 'test/unit'
  4
+
  5
+    class #{camelize(File.basename(filename,'.rb'))} < Test::Unit::TestCase  
  6
+      #{content}
  7
+    end
  8
+  EOF
  9
+end
9  features/support/env.rb
... ...
@@ -0,0 +1,9 @@
  1
+require 'aruba/cucumber'
  2
+
  3
+module Rt::World 
  4
+  def camelize(str)
  5
+    str.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  6
+  end
  7
+end
  8
+
  9
+World(Rt::World)
11  lib/rt.rb
... ...
@@ -0,0 +1,11 @@
  1
+require 'rt/matcher'
  2
+require 'rt/matchers/unit_test'
  3
+require 'rt/matchers/active_support_test_case'
  4
+require 'rt/matchers/shoulda'
  5
+
  6
+
  7
+module Rt
  8
+  module Matchers 
  9
+    
  10
+  end
  11
+end
14  lib/rt/matcher.rb
... ...
@@ -0,0 +1,14 @@
  1
+module Rt
  2
+  class Matcher 
  3
+    def self.match(arg)
  4
+      raise "Not implement"
  5
+    end
  6
+
  7
+    def self.test_name(line) 
  8
+      if match = self.match(line) 
  9
+        return match.gsub!(/\s+/,"_")
  10
+      end
  11
+      return nil
  12
+    end
  13
+  end
  14
+end
9  lib/rt/matchers/active_support_test_case.rb
... ...
@@ -0,0 +1,9 @@
  1
+module Rt
  2
+  module Matchers
  3
+    class ActiveSupportTestCase < Rt::Matcher 
  4
+      def self.match(arg) 
  5
+        return arg[/\s*test\s+["']+(.*)["']+\s+do/,1]
  6
+      end
  7
+    end 
  8
+  end
  9
+end
14  lib/rt/matchers/shoulda.rb
... ...
@@ -0,0 +1,14 @@
  1
+module Rt
  2
+  module Matchers
  3
+    class Shoulda < Rt::Matcher
  4
+      def self.match(arg) 
  5
+        return arg[/\s*[should|context]+\s+["']+(.*)["']+\s+do/,1]
  6
+      end
  7
+
  8
+      def self.test_name(line) 
  9
+        return self.match(line)
  10
+      end
  11
+    end 
  12
+  end
  13
+end
  14
+
11  lib/rt/matchers/unit_test.rb
... ...
@@ -0,0 +1,11 @@
  1
+module Rt
  2
+  module Matchers
  3
+    class UnitTest < Rt::Matcher 
  4
+      def self.match(arg) 
  5
+        return arg[/\s*def\s+(test\S+)\s*/,1]
  6
+      end
  7
+    end 
  8
+  end
  9
+end
  10
+
  11
+
3  lib/rt/version.rb
... ...
@@ -0,0 +1,3 @@
  1
+module Rt
  2
+  VERSION = "0.0.1"
  3
+end
30  rt.gemspec
... ...
@@ -0,0 +1,30 @@
  1
+# -*- encoding: utf-8 -*-
  2
+$:.push File.expand_path("../lib", __FILE__)
  3
+require "rt/version"
  4
+
  5
+Gem::Specification.new do |s|
  6
+  s.name        = "rt"
  7
+  s.version     = Rt::VERSION
  8
+  s.platform    = Gem::Platform::RUBY
  9
+  s.authors     = ["Allen Wei"]
  10
+  s.email       = ["digruby@gmail.com"]
  11
+  s.homepage    = "https://github.com/allenwei/rt"
  12
+  s.summary     = %q{unit test runner}
  13
+  s.description = %q{unit test runner, support run tests by regular expression, line num and printing test result in different fomatter }
  14
+
  15
+  s.rubyforge_project = "rt"
  16
+
  17
+  s.files         = `git ls-files`.split("\n")
  18
+  s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
  19
+  s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
  20
+  s.require_paths = ["lib"]
  21
+
  22
+  
  23
+  s.add_development_dependency 'cucumber', "~> 0.10.0"
  24
+  s.add_development_dependency 'aruba', "~> 0.3.2"
  25
+  s.add_development_dependency 'activesupport', "~> 2.3.8"
  26
+  s.add_development_dependency 'shoulda'
  27
+  s.add_development_dependency 'ruby-debug'
  28
+  s.add_development_dependency 'rr'
  29
+
  30
+end
11  spec/rt/matcher_spec.rb
... ...
@@ -0,0 +1,11 @@
  1
+require 'spec_helper' 
  2
+
  3
+describe Rt::Matcher do 
  4
+  context ".test_name" do 
  5
+    it "should replace blank with '_'" do 
  6
+      line = "test 'a b c' do"
  7
+      Rt::Matcher.should_receive(:match).with(line).and_return("a b c") 
  8
+      Rt::Matcher.test_name(line).should == "a_b_c"
  9
+    end
  10
+  end
  11
+end
35  spec/rt/matchers/active_support_test_case_spec.rb
... ...
@@ -0,0 +1,35 @@
  1
+require 'spec_helper' 
  2
+
  3
+describe Rt::ActiveSupportTestCase do
  4
+
  5
+  context ".match" do 
  6
+    it "should match test with double quote" do  
  7
+      Rt::ActiveSupportTestCase.match(%Q{test "test_one" do}).should == "test_one"
  8
+    end
  9
+
  10
+    it "should match test with double quote and blank at begining" do  
  11
+      Rt::ActiveSupportTestCase.match(%Q{   test "test_one" do}).should == "test_one"
  12
+    end
  13
+
  14
+    it "should match test with double quote and blank after 'test'" do  
  15
+      Rt::ActiveSupportTestCase.match(%Q{   test    "test_one" do}).should == "test_one"
  16
+    end
  17
+
  18
+    it "should match test with double quote and blank after 'test' before do " do  
  19
+      Rt::ActiveSupportTestCase.match(%Q{   test    "test_one" do}).should == "test_one"
  20
+    end
  21
+
  22
+    it "should match test with double quote and blank after 'test' after do " do  
  23
+      Rt::ActiveSupportTestCase.match(%Q{   test    "test_one" do}).should == "test_one"
  24
+    end
  25
+
  26
+    it "should not match is not a test" do  
  27
+      Rt::ActiveSupportTestCase.match(%Q{test1    "test_one" do}).should be_nil
  28
+    end
  29
+
  30
+    it "should match test with single qoute" do 
  31
+      Rt::ActiveSupportTestCase.match(%Q{test 'test_one' do}).should == "test_one"
  32
+    end
  33
+  end
  34
+end
  35
+
22  spec/rt/matchers/shoulda_spec.rb
... ...
@@ -0,0 +1,22 @@
  1
+require 'spec_helper' 
  2
+
  3
+describe Rt::Matchers::Shoulda  do 
  4
+  context ".match" do 
  5
+    it "should match line with should in double qoute" do 
  6
+      Rt::Matchers::Shoulda.match(%q{should "test one" do}).should == "test one"
  7
+    end
  8
+
  9
+    it "should match line with should in single quote" do 
  10
+      Rt::Matchers::Shoulda.match(%q{should 'test one' do}).should == "test one"
  11
+    end
  12
+    
  13
+    it "should match line with context in double qoute" do 
  14
+      Rt::Matchers::Shoulda.match(%q{context "test one" do}).should == "test one"
  15
+    end
  16
+
  17
+    it "should match line with context in single qoute" do 
  18
+      Rt::Matchers::Shoulda.match(%q{context 'test one' do}).should == "test one"
  19
+    end
  20
+  end
  21
+end
  22
+
17  spec/rt/matchers/unit_test_spec.rb
... ...
@@ -0,0 +1,17 @@
  1
+require 'spec_helper'
  2
+
  3
+describe Rt::Matchers::UnitTest do 
  4
+  context ".match" do
  5
+    it "should match def" do 
  6
+      Rt::Matchers::UnitTest.match("def test_a_b_c").should == "test_a_b_c"
  7
+    end
  8
+
  9
+    it "should match def with extra blank" do 
  10
+      Rt::Matchers::UnitTest.match(" def   test_a_b_c  ").should == "test_a_b_c"
  11
+    end
  12
+
  13
+    it "should only match method name start with 'test'" do 
  14
+      Rt::Matchers::UnitTest.match(" def   a_b_c  ").should be_nil
  15
+    end
  16
+  end
  17
+end
14  spec/spec_helper.rb
... ...
@@ -0,0 +1,14 @@
  1
+require 'rubygems'
  2
+require 'bundler/setup'
  3
+require 'rspec'
  4
+
  5
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'..','lib'))
  6
+$LOAD_PATH.unshift(File.dirname(__FILE__))
  7
+
  8
+require 'rt'
  9
+
  10
+RSpec.configure do |config|
  11
+  config.mock_with :rspec
  12
+end
  13
+
  14
+

0 notes on commit 598c859

Please sign in to comment.
Something went wrong with that request. Please try again.