runtest 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in runtest.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tom Scott
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Runtest
2
+
3
+ A little Ruby library that helps you run single tests files using
4
+ Test::Unit (or Minitest). It allows running single examples by line
5
+ number as well as full files. Runtest uses `bundle exec ruby -Itest` as
6
+ its test run command.
7
+
8
+ ## Installation
9
+
10
+ Add the gem to your `:development` group, as it will only be run on
11
+ development servers:
12
+
13
+ group :development do
14
+ gem 'runtest', require: false # no need to require it since it
15
+ # isn't part of the app or testing
16
+ # framework..
17
+ end
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install runtest
26
+
27
+ ## Usage
28
+
29
+ Just pass a test file into the `rtest` binary:
30
+
31
+ $ rtest test/unit/my_model_test.rb
32
+
33
+ Or, you can run a single example in the file:
34
+
35
+ $ rtest test/unit/my_model_test.rb:45
36
+
37
+ Line 45 must include an example, like `test "blah blah" do`. Runtest
38
+ will also work flawlessly with `shoulda_context` and `minitest`
39
+ variations on this syntax. It does *not* work with Minitest's spec
40
+ syntax just yet..
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ end
data/bin/rtest ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'runtest'
5
+
6
+ ARGV.each { |from_argument| Runtest::Command.new(from_argument).perform! }
data/lib/runtest.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "runtest/version"
2
+ require "runtest/command"
3
+
4
+ module Runtest
5
+ # An exception thrown when the file passed in does not exist.
6
+ class FileNotFound < StandardError; end
7
+ end
@@ -0,0 +1,60 @@
1
+ module Runtest
2
+ class Command
3
+ SYNTAX = /^(test|should)\s(\"|\')|(\"|\')\sdo$/
4
+ attr_accessor :file_name, :line_number, :options
5
+
6
+ def initialize argument
7
+ arguments = argument.split ':'
8
+ @file_name = arguments[0] || ""
9
+ @line_number = arguments[1].to_i || 0
10
+ @base_command = "bundle exec ruby -Itest"
11
+
12
+ raise FileNotFound unless File.exists? file_name
13
+ end
14
+
15
+ def perform!
16
+ if line_number <= 0
17
+ run_test
18
+ else
19
+ run_test "-n '#{closest_example}'"
20
+ end
21
+ end
22
+
23
+ def closest_example
24
+ line_at_line_number.gsub SYNTAX, ''
25
+ end
26
+
27
+ def file_name
28
+ "#{@file_name}".strip
29
+ end
30
+
31
+ def line_number
32
+ if @line_number <= 0
33
+ 0
34
+ else
35
+ @line_number.to_i - 1
36
+ end
37
+ end
38
+
39
+ def base_command
40
+ @base_command ||= "ruby -Itest"
41
+ end
42
+
43
+ def line_at_line_number
44
+ file_contents[line_number].strip
45
+ end
46
+
47
+ def file_contents
48
+ File.read(file_name).split "\n"
49
+ end
50
+
51
+ def run_test options=""
52
+ @options = options
53
+ system consolidated_command
54
+ end
55
+
56
+ def consolidated_command
57
+ [ base_command, file_name, options ].join ' '
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module Runtest
2
+ VERSION = "0.0.1"
3
+ end
data/runtest.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'runtest/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "runtest"
8
+ spec.version = Runtest::VERSION
9
+ spec.authors = ["Tom Scott"]
10
+ spec.email = ["tubbo@psychedeli.ca"]
11
+ spec.description = %q{A singleton test runner for Minitest}
12
+ spec.summary = %q{A singleton test runner for Minitest}
13
+ spec.homepage = "http://github.com/tubbo/runtest"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^test/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest"
24
+ spec.add_development_dependency "shoulda-context"
25
+ end
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+ require 'runtest/command'
3
+
4
+ module Runtest
5
+ class CommandTest < Test::Unit::TestCase
6
+ should "throw an error when the example to run is blank" do
7
+ assert_raises FileNotFound do
8
+ @command = Command.new "not/a/real/file.rb"
9
+ end
10
+ end
11
+
12
+ context "when running a full test file" do
13
+ setup { @command = Command.new "test/lib/runtest/command_test.rb" }
14
+
15
+ should "run all examples in the file" do
16
+ assert_equal "test/lib/runtest/command_test.rb", @command.file_name
17
+ end
18
+
19
+ should "resolve to a blank line number" do
20
+ assert_equal 0, @command.line_number
21
+ end
22
+ end
23
+
24
+ context "when specifying a line number in a test file" do
25
+ setup { @command = Command.new "test/lib/runtest/command_test.rb:15" }
26
+
27
+ should "find the file correctly" do
28
+ assert_equal "test/lib/runtest/command_test.rb", @command.file_name
29
+ end
30
+
31
+ should "resolve to the correct line number" do
32
+ assert_equal 14, @command.line_number
33
+ end
34
+
35
+ should "find the closest example to said line number" do
36
+ assert_equal "run all examples in the file", @command.closest_example
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ require 'bundler/setup'
2
+ require 'test/unit'
3
+ require 'runtest'
4
+ require 'shoulda-context'
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: runtest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tom Scott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: shoulda-context
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: A singleton test runner for Minitest
79
+ email:
80
+ - tubbo@psychedeli.ca
81
+ executables:
82
+ - rtest
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .bundle/config
87
+ - .gitignore
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - bin/rtest
93
+ - lib/runtest.rb
94
+ - lib/runtest/command.rb
95
+ - lib/runtest/version.rb
96
+ - runtest.gemspec
97
+ - test/lib/runtest/command_test.rb
98
+ - test/test_helper.rb
99
+ homepage: http://github.com/tubbo/runtest
100
+ licenses:
101
+ - MIT
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ segments:
113
+ - 0
114
+ hash: -3331557307084673125
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ segments:
122
+ - 0
123
+ hash: -3331557307084673125
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 1.8.23
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: A singleton test runner for Minitest
130
+ test_files:
131
+ - test/lib/runtest/command_test.rb
132
+ - test/test_helper.rb