focused-test 0.4.0 → 0.5.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/VERSION.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  ---
2
- :major: 0
3
- :minor: 4
4
2
  :patch: 0
3
+ :build:
4
+ :major: 0
5
+ :minor: 5
data/lib/focused_test.rb CHANGED
@@ -13,18 +13,24 @@ class FocusedTest
13
13
  end
14
14
 
15
15
  def run
16
- test_type = nil
17
- current_method = nil
16
+ strategy_for_file.call
17
+ end
18
18
 
19
+ private
20
+ def strategy_for_file
21
+ if @file_path =~ /\.feature/
22
+ return proc { run_feature }
23
+ elsif @file_path =~ /_spec\.rb/
24
+ return proc { run_example }
25
+ end
26
+
19
27
  content = IO.read(@file_path)
20
28
  if content =~ /class .*Test < (.*TestCase|ActionController::IntegrationTest)/
21
29
  if content =~ /should\s+['"].*['"]\s+do/
22
- run_should content
30
+ return proc { run_should content }
23
31
  else
24
- run_test content
32
+ return proc { run_test content }
25
33
  end
26
- else
27
- run_example
28
34
  end
29
35
  end
30
36
 
@@ -32,8 +38,10 @@ class FocusedTest
32
38
  def parse(args)
33
39
  @file_path = nil
34
40
  @line_number = nil
41
+ @format = nil
35
42
  @rspec_version = ""
36
43
  @show_backtrace = false
44
+
37
45
  options = OptionParser.new do |o|
38
46
  o.on('-f', '--filepath=FILEPATH', String, "File to run test on") do |path|
39
47
  @file_path = path
@@ -42,6 +50,7 @@ class FocusedTest
42
50
  o.on('-l', '--linenumber=LINENUMBER', Integer, "Line of the test") do |line|
43
51
  @line_number = line
44
52
  end
53
+
45
54
  o.on('-r', '--rspec-version=VERSION', String, "Version of Rspec to Run") do |version|
46
55
  @rspec_version = "_#{version}_"
47
56
  end
@@ -53,6 +62,10 @@ class FocusedTest
53
62
  o.on('-X', '--drb', String, "Run examples via DRb.") do
54
63
  @drb = true
55
64
  end
65
+
66
+ o.on('-F', '--format=FORMAT', String, "Output formatter for rspec or cucumber") do |format|
67
+ @format = format
68
+ end
56
69
  end
57
70
  options.order(args)
58
71
  end
@@ -82,7 +95,6 @@ class FocusedTest
82
95
  puts "Running '#{current_method}' in file #{@file_path}" unless current_method.nil?
83
96
  end
84
97
 
85
-
86
98
  def run_should(content)
87
99
  unless @line_number
88
100
  return run_test(content)
@@ -128,10 +140,27 @@ class FocusedTest
128
140
  cmd << " --line #{@line_number}" if @line_number
129
141
  cmd << ' --backtrace' if @show_backtrace
130
142
  cmd << ' --drb' if @drb
143
+ cmd << " --format #{@format ? @format : 'progress'}"
131
144
  system cmd
132
145
  end
146
+
147
+ def run_feature
148
+ cmd = ""
149
+ ["script/cucumber", `which cucumber`.strip, "/usr/bin/cucumber"].each do |cucumber_executable|
150
+ if File.exists?(cucumber_executable)
151
+ cmd = cucumber_executable
152
+ break
153
+ end
154
+ end
155
+
156
+ cmd << " #{@file_path}"
157
+ cmd << ":#{@line_number}" if @line_number
158
+ cmd << " --format #{@format ? @format : 'pretty'}"
159
+
160
+ system cmd
161
+ end
133
162
 
134
163
  def parse_from_quotes(name)
135
164
  name.to_s.gsub(/^(?:.*"(.*)"|.*'(.*)').*$/) { $1 || $2 }
136
165
  end
137
- end
166
+ end
@@ -0,0 +1,3 @@
1
+ Then /^"([^\"]*)" gets done$/ do |thing|
2
+ puts "does #{thing}"
3
+ end
@@ -74,8 +74,73 @@ describe FocusedTest do
74
74
  output.should include("does something 2")
75
75
  end
76
76
  end
77
+
78
+ context 'format' do
79
+ context 'when passed "--format specdoc"' do
80
+ it 'should use the specdoc formatter' do
81
+ output = run_test("-f #{@file} --format specdoc")
82
+ output.should include("does something 1\n- does something 1")
83
+ output.should_not include(".does something 2")
84
+ end
85
+ end
86
+
87
+ context 'when not passed a format' do
88
+ it 'should default to the progress formater' do
89
+ output = run_test("-f #{@file}")
90
+ output.should include(".does something 2")
91
+ output.should_not include("does something 1\n- does something 1")
92
+ end
93
+ end
94
+ end
77
95
  end
78
96
 
97
+ context "when passed a filepath that ends with .feature" do
98
+ before do
99
+ features_path = File.expand_path("#{dir}/fixtures/features/")
100
+ @file = "#{features_path}/focused-test.feature"
101
+ end
102
+
103
+ context "when passed a --line" do
104
+ it 'runs the focused scenario' do
105
+ output = run_test("-f #{@file} -l 6")
106
+ output.should include("does something 1")
107
+ output.should_not include("does something 2")
108
+ output.should include("1 scenario (1 passed)")
109
+ output.should include("1 step (1 passed)")
110
+ end
111
+ end
112
+
113
+ context "when not passed a --line" do
114
+ it "runs the entire feature file" do
115
+ output = run_test("-f #{@file}")
116
+ output.should include("does something 1")
117
+ output.should include("does something 2")
118
+ output.should include("2 scenarios (2 passed)")
119
+ output.should include("2 steps (2 passed)")
120
+ end
121
+ end
122
+
123
+ context "format" do
124
+ context 'when passed "--format progress"' do
125
+ it 'should use the progress formatter' do
126
+ output = run_test("-f #{@file} --format progress")
127
+ output.should_not include("Scenario: Doing something 1")
128
+ output.should_not include("Scenario: Doing something 2")
129
+ output.should include(".does something 2")
130
+ end
131
+ end
132
+
133
+ context 'when not passed a format' do
134
+ it 'should default to the pretty formater' do
135
+ output = run_test("-f #{@file}")
136
+ output.should include("Scenario: Doing something 1")
137
+ output.should include("Scenario: Doing something 2")
138
+ output.should_not include(".does something 2")
139
+ end
140
+ end
141
+ end
142
+ end
143
+
79
144
  def dir
80
145
  File.dirname(__FILE__)
81
146
  end
@@ -84,4 +149,4 @@ describe FocusedTest do
84
149
  `ruby -e "require '#{dir}/../lib/focused_test'; FocusedTest.run('#{command_line.split(/\s/).join(%q[','])}')"`
85
150
  end
86
151
  end
87
- end
152
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 4
7
+ - 5
8
8
  - 0
9
- version: 0.4.0
9
+ version: 0.5.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brian Takita
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2009-08-30 00:00:00 -07:00
17
+ date: 2010-05-25 00:00:00 -07:00
18
18
  default_executable: focused-test
19
19
  dependencies: []
20
20
 
@@ -64,8 +64,9 @@ signing_key:
64
64
  specification_version: 3
65
65
  summary: Script to run a focused test or spec.
66
66
  test_files:
67
- - spec/focused_test_spec.rb
68
67
  - spec/spec_helper.rb
69
- - spec/fixtures/fixture_shoulda.rb
70
- - spec/fixtures/fixture_test.rb
71
68
  - spec/fixtures/fixture_spec.rb
69
+ - spec/fixtures/features/step_definitions/focused-test_steps.rb
70
+ - spec/fixtures/fixture_test.rb
71
+ - spec/fixtures/fixture_shoulda.rb
72
+ - spec/focused_test_spec.rb