focused-test 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +13 -0
- data/README.markdown +10 -0
- data/Rakefile +15 -0
- data/VERSION.yml +4 -0
- data/bin/focused-test +6 -0
- data/lib/focused_test.rb +137 -0
- data/spec/fixtures/fixture_shoulda.rb +24 -0
- data/spec/fixtures/fixture_spec.rb +11 -0
- data/spec/fixtures/fixture_test.rb +11 -0
- data/spec/focused_test_spec.rb +87 -0
- data/spec/spec_helper.rb +11 -0
- metadata +71 -0
data/CHANGES
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
0.4.0
|
2
|
+
Can now handle shoulda tests/focused tests. (Patch by Neal Clark)
|
3
|
+
Run a focused should by specifying a line anywhere inside of the should. (Patch by Neal Clark)
|
4
|
+
Run a focused context by specifying the line on which the context starts. (Patch by Neal Clark)
|
5
|
+
|
6
|
+
0.2.0
|
7
|
+
FocusedTest.run and FocusedTest.new now take a splatted array.
|
8
|
+
|
9
|
+
0.1.1
|
10
|
+
FocusedTest#parse properly uses args local variable instead of using ARGV.
|
11
|
+
|
12
|
+
0.1.0
|
13
|
+
Initial Release
|
data/README.markdown
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |s|
|
4
|
+
s.name = "focused-test"
|
5
|
+
s.executables = "focused-test"
|
6
|
+
s.summary = "Script to run a focused test or spec."
|
7
|
+
s.email = "brian.takita@gmail.com"
|
8
|
+
s.homepage = "http://github.com/technicalpickles/jeweler"
|
9
|
+
s.summary = "Script to run a focused test or spec."
|
10
|
+
s.authors = ["Brian Takita"]
|
11
|
+
s.files = FileList["[A-Z]*", "{bin,lib,test}/**/*"]
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
15
|
+
end
|
data/VERSION.yml
ADDED
data/bin/focused-test
ADDED
data/lib/focused_test.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
class FocusedTest
|
5
|
+
class << self
|
6
|
+
def run(*args)
|
7
|
+
new(*args).run
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(*args)
|
12
|
+
parse args
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
test_type = nil
|
17
|
+
current_method = nil
|
18
|
+
|
19
|
+
content = IO.read(@file_path)
|
20
|
+
if content =~ /class .*Test < (.*TestCase|ActionController::IntegrationTest)/
|
21
|
+
if content =~ /should\s+['"].*['"]\s+do/
|
22
|
+
run_should content
|
23
|
+
else
|
24
|
+
run_test content
|
25
|
+
end
|
26
|
+
else
|
27
|
+
run_example
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
def parse(args)
|
33
|
+
@file_path = nil
|
34
|
+
@line_number = nil
|
35
|
+
@rspec_version = ""
|
36
|
+
@show_backtrace = false
|
37
|
+
options = OptionParser.new do |o|
|
38
|
+
o.on('-f', '--filepath=FILEPATH', String, "File to run test on") do |path|
|
39
|
+
@file_path = path
|
40
|
+
end
|
41
|
+
|
42
|
+
o.on('-l', '--linenumber=LINENUMBER', Integer, "Line of the test") do |line|
|
43
|
+
@line_number = line
|
44
|
+
end
|
45
|
+
o.on('-r', '--rspec-version=VERSION', String, "Version of Rspec to Run") do |version|
|
46
|
+
@rspec_version = "_#{version}_"
|
47
|
+
end
|
48
|
+
|
49
|
+
o.on('-b', '--backtrace', String, "Show the backtrace of errors") do
|
50
|
+
@show_backtrace = true
|
51
|
+
end
|
52
|
+
|
53
|
+
o.on('-X', '--drb', String, "Run examples via DRb.") do
|
54
|
+
@drb = true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
options.order(args)
|
58
|
+
end
|
59
|
+
|
60
|
+
def run_test(content)
|
61
|
+
current_line = 0
|
62
|
+
current_method = nil
|
63
|
+
|
64
|
+
require @file_path
|
65
|
+
runner = nil
|
66
|
+
if @line_number
|
67
|
+
content.split("\n").each do |line|
|
68
|
+
break if current_line > @line_number
|
69
|
+
if /def +(test_[A-Za-z0-9_!?]*)/ =~ line
|
70
|
+
current_method = Regexp.last_match(1)
|
71
|
+
end
|
72
|
+
current_line += 1
|
73
|
+
end
|
74
|
+
|
75
|
+
runner = Test::Unit::AutoRunner.new(false) do |runner|
|
76
|
+
runner.filters << proc{|t| current_method == t.method_name ? true : false}
|
77
|
+
end
|
78
|
+
else
|
79
|
+
runner = Test::Unit::AutoRunner.new(false)
|
80
|
+
end
|
81
|
+
runner.run
|
82
|
+
puts "Running '#{current_method}' in file #{@file_path}" unless current_method.nil?
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def run_should(content)
|
87
|
+
unless @line_number
|
88
|
+
return run_test(content)
|
89
|
+
end
|
90
|
+
|
91
|
+
require @file_path
|
92
|
+
|
93
|
+
should, context, description = '', '', ''
|
94
|
+
|
95
|
+
content = content.split("\n")
|
96
|
+
lines = content[0...@line_number].reverse
|
97
|
+
context = lines.find { |line| line =~ /^\s*context\b/ }
|
98
|
+
|
99
|
+
unless content[@line_number - 1] =~ /^\s*context\b/
|
100
|
+
should = parse_from_quotes(lines.find { |line| line =~ /^\s*should\b/ })
|
101
|
+
end
|
102
|
+
|
103
|
+
if !context.empty?
|
104
|
+
context = parse_from_quotes( context )
|
105
|
+
description = should.empty? ? context : "#{context} should #{should}"
|
106
|
+
method_regex = description.gsub(/[\+\.\s\'\"\(\)]/,'.')
|
107
|
+
|
108
|
+
runner = Test::Unit::AutoRunner.new(false) do |runner|
|
109
|
+
runner.filters << proc{|t| t.method_name.match(method_regex) ? true : false }
|
110
|
+
end
|
111
|
+
|
112
|
+
runner.run
|
113
|
+
|
114
|
+
puts "Running '#{description}' in file #{@file_path}" unless description.empty?
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def run_example
|
119
|
+
cmd = nil
|
120
|
+
["script/spec", "vendor/plugins/rspec/bin/spec", "/usr/bin/spec"].each do |spec_file|
|
121
|
+
if File.exists?(spec_file)
|
122
|
+
cmd = spec_file
|
123
|
+
break
|
124
|
+
end
|
125
|
+
end
|
126
|
+
cmd = (RUBY_PLATFORM =~ /[^r]win/) ? "spec.cmd" : "spec" unless cmd
|
127
|
+
cmd << "#{@rspec_version} #{@file_path}"
|
128
|
+
cmd << " --line #{@line_number}" if @line_number
|
129
|
+
cmd << ' --backtrace' if @show_backtrace
|
130
|
+
cmd << ' --drb' if @drb
|
131
|
+
system cmd
|
132
|
+
end
|
133
|
+
|
134
|
+
def parse_from_quotes(name)
|
135
|
+
name.to_s.gsub(/^(?:.*"(.*)"|.*'(.*)').*$/) { $1 || $2 }
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'shoulda'
|
3
|
+
|
4
|
+
class FixtureShouldaTest < Test::Unit::TestCase
|
5
|
+
context "fixture test with shoulda" do
|
6
|
+
should "do something 1" do
|
7
|
+
puts "does something 1"
|
8
|
+
end
|
9
|
+
|
10
|
+
should "do something 2" do
|
11
|
+
puts "does something 2"
|
12
|
+
end
|
13
|
+
|
14
|
+
context "I am a context" do
|
15
|
+
should "run this whole context" do
|
16
|
+
puts "context 1"
|
17
|
+
end
|
18
|
+
|
19
|
+
should "be run this whole context" do
|
20
|
+
puts "context 2"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/spec_helper"
|
2
|
+
|
3
|
+
describe FocusedTest do
|
4
|
+
describe "#run" do
|
5
|
+
context "when passed in file has a test in it" do
|
6
|
+
before { @file = "#{dir}/fixtures/fixture_test.rb" }
|
7
|
+
|
8
|
+
context "when passed a --line" do
|
9
|
+
it "runs the focused test" do
|
10
|
+
output = run_test("-f #{@file} -l 5")
|
11
|
+
output.should include("test_1")
|
12
|
+
output.should_not include("test_2")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when not passed a --line" do
|
17
|
+
it "runs the entire test" do
|
18
|
+
output = run_test("-f #{@file}")
|
19
|
+
output.should include("test_1")
|
20
|
+
output.should include("test_2")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when passed in file has a shoulda test in it" do
|
26
|
+
before { @file = "#{dir}/fixtures/fixture_shoulda.rb" }
|
27
|
+
|
28
|
+
context "when passed a --line" do
|
29
|
+
context "at the head of a context block" do
|
30
|
+
it "runs the focused context" do
|
31
|
+
output = run_test("-f #{@file} -l 14")
|
32
|
+
output.should include("context 1")
|
33
|
+
output.should include("context 2")
|
34
|
+
output.should_not include("does something 1")
|
35
|
+
output.should_not include("does something 2")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "at the head or inside of a should block" do
|
40
|
+
it "runs the focused should" do
|
41
|
+
output = run_test("-f #{@file} -l 7")
|
42
|
+
output.should include("does something 1")
|
43
|
+
output.should_not include("does something 2")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when not passed a --line" do
|
49
|
+
it "runs the entire test" do
|
50
|
+
output = run_test("-f #{@file}")
|
51
|
+
output.should include("does something 1")
|
52
|
+
output.should include("does something 2")
|
53
|
+
output.should include("context 1")
|
54
|
+
output.should include("context 2")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when passed a filepath that ends with _spec.rb" do
|
60
|
+
before { @file = "#{dir}/fixtures/fixture_spec.rb" }
|
61
|
+
|
62
|
+
context "when passed a --line" do
|
63
|
+
it "runs the focused spec" do
|
64
|
+
output = run_test("-f #{@file} -l 5")
|
65
|
+
output.should include("does something 1")
|
66
|
+
output.should_not include("does something 2")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when not passed a --line" do
|
71
|
+
it "runs the entire spec" do
|
72
|
+
output = run_test("-f #{@file}")
|
73
|
+
output.should include("does something 1")
|
74
|
+
output.should include("does something 2")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def dir
|
80
|
+
File.dirname(__FILE__)
|
81
|
+
end
|
82
|
+
|
83
|
+
def run_test(command_line)
|
84
|
+
`ruby -e "require '#{dir}/../lib/focused_test'; FocusedTest.run('#{command_line.split(/\s/).join(%q[','])}')"`
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
require "rubygems"
|
3
|
+
$LOAD_PATH.unshift(File.expand_path("#{File.dirname(__FILE__)}/../lib"))
|
4
|
+
require "focused_test"
|
5
|
+
require "spec"
|
6
|
+
require "spec/autorun"
|
7
|
+
require "rr"
|
8
|
+
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
config.mock_with :rr
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: focused-test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 4
|
8
|
+
- 0
|
9
|
+
version: 0.4.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Brian Takita
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2009-08-30 00:00:00 -07:00
|
18
|
+
default_executable: focused-test
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description:
|
22
|
+
email: brian.takita@gmail.com
|
23
|
+
executables:
|
24
|
+
- focused-test
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README.markdown
|
29
|
+
files:
|
30
|
+
- CHANGES
|
31
|
+
- README.markdown
|
32
|
+
- Rakefile
|
33
|
+
- VERSION.yml
|
34
|
+
- bin/focused-test
|
35
|
+
- lib/focused_test.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/technicalpickles/jeweler
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --charset=UTF-8
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
version: "0"
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.3.6
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Script to run a focused test or spec.
|
66
|
+
test_files:
|
67
|
+
- spec/focused_test_spec.rb
|
68
|
+
- spec/spec_helper.rb
|
69
|
+
- spec/fixtures/fixture_shoulda.rb
|
70
|
+
- spec/fixtures/fixture_test.rb
|
71
|
+
- spec/fixtures/fixture_spec.rb
|