respec 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.5.0 2013-03-02
2
+
3
+ * Fix rerunning of specs defined in non-spec files (e.g. support files).
4
+
1
5
  == 0.4.1 2012-11-15
2
6
 
3
7
  * Run spec directory by default, like rspec.
@@ -4,9 +4,29 @@ module Respec
4
4
  class Formatter < RSpec::Core::Formatters::BaseFormatter
5
5
  def start_dump
6
6
  @failed_examples.each do |example|
7
- output.puts example.metadata[:location]
7
+ output.puts self.class.extract_spec_location(example.metadata)
8
8
  end
9
9
  end
10
+
11
+ def self.extract_spec_location(metadata)
12
+ root_metadata = metadata
13
+ until spec_path?(metadata[:location])
14
+ metadata = metadata[:example_group]
15
+ if !metadata
16
+ warn "no spec file found for #{root_metadata[:location]}"
17
+ return root_metadata[:location]
18
+ end
19
+ end
20
+ metadata[:location]
21
+ end
22
+
23
+ def self.spec_path?(path)
24
+ flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
25
+ if File.const_defined?(:FNM_EXTGLOB) # ruby >= 2
26
+ flags |= File::FNM_EXTGLOB
27
+ end
28
+ File.fnmatch(RSpec.configuration.pattern, path.sub(/:\d+\z/, ''), flags)
29
+ end
10
30
  end
11
31
  end
12
32
 
@@ -1,5 +1,5 @@
1
1
  module Respec
2
- VERSION = [0, 4, 1]
2
+ VERSION = [0, 5, 0]
3
3
 
4
4
  class << VERSION
5
5
  include Comparable
@@ -23,7 +23,7 @@ describe Respec do
23
23
  source = "describe 'test' do\n"
24
24
  (0...2).map do |i|
25
25
  if i < num_failures
26
- source << " it('#{i}') { 1.should == 2 }\n"
26
+ source << " it('#{i}') { expect(1).to == 2 }\n"
27
27
  else
28
28
  source << " it('#{i}') {}\n"
29
29
  end
@@ -40,18 +40,18 @@ describe Respec do
40
40
  Dir.chdir tmp do
41
41
  make_spec(:num_failures => 2)
42
42
  status, output = respec(spec_path)
43
- status.should_not be_success
44
- output.should include('2 examples, 2 failures')
43
+ expect(status).to_not be_success
44
+ expect(output).to include('2 examples, 2 failures')
45
45
 
46
46
  make_spec(:num_failures => 1)
47
47
  status, output = respec("#{spec_path} f")
48
- status.should_not be_success
49
- output.should include('2 examples, 1 failure')
48
+ expect(status).to_not be_success
49
+ expect(output).to include('2 examples, 1 failure')
50
50
 
51
51
  make_spec(:num_failures => 0)
52
52
  status, output = respec("#{spec_path} f")
53
- status.should be_success
54
- output.should include('1 example, 0 failures')
53
+ expect(status).to be_success
54
+ expect(output).to include('1 example, 0 failures')
55
55
  end
56
56
  end
57
57
  end
@@ -26,7 +26,7 @@ describe Respec::App do
26
26
  FileUtils.touch "#{tmp}/Gemfile"
27
27
  Dir.chdir tmp do
28
28
  app = Respec::App.new
29
- app.bundler_args.should == ['bundle', 'exec']
29
+ expect(app.bundler_args).to eq ['bundle', 'exec']
30
30
  end
31
31
  end
32
32
 
@@ -35,7 +35,7 @@ describe Respec::App do
35
35
  FileUtils.touch "#{tmp}/custom_gemfile"
36
36
  Dir.chdir tmp do
37
37
  app = Respec::App.new
38
- app.bundler_args.should == ['bundle', 'exec']
38
+ expect(app.bundler_args).to eq ['bundle', 'exec']
39
39
  end
40
40
  end
41
41
  end
@@ -44,7 +44,7 @@ describe Respec::App do
44
44
  with_hash_value ENV, 'BUNDLE_GEMFILE', nil do
45
45
  Dir.chdir tmp do
46
46
  app = Respec::App.new
47
- app.bundler_args.should == []
47
+ expect(app.bundler_args).to eq []
48
48
  end
49
49
  end
50
50
  end
@@ -53,19 +53,19 @@ describe Respec::App do
53
53
  describe "#formatter_args" do
54
54
  it "should update the stored failures if no args are given" do
55
55
  app = Respec::App.new
56
- app.formatter_args.should == [FORMATTER_PATH]
56
+ expect(app.formatter_args).to eq [FORMATTER_PATH]
57
57
  end
58
58
 
59
59
  it "should update the stored failures if 'f' is used" do
60
60
  make_failures_file 'a.rb:1'
61
61
  app = Respec::App.new('f')
62
- app.formatter_args.should == [FORMATTER_PATH]
62
+ expect(app.formatter_args).to eq [FORMATTER_PATH]
63
63
  end
64
64
 
65
65
  it "should not update the stored failures if a numeric argument is given" do
66
66
  make_failures_file 'a.rb:1'
67
67
  app = Respec::App.new('1')
68
- app.formatter_args.should == []
68
+ expect(app.formatter_args).to eq []
69
69
  end
70
70
  end
71
71
 
@@ -73,86 +73,86 @@ describe Respec::App do
73
73
  it "should pass all arguments that start with '-' to rspec" do
74
74
  FileUtils.touch "#{tmp}/file"
75
75
  app = Respec::App.new('-a', '-b', '-c', "#{tmp}/file")
76
- app.generated_args.should == ['-a', '-b', '-c', "#{tmp}/file"]
76
+ expect(app.generated_args).to eq ['-a', '-b', '-c', "#{tmp}/file"]
77
77
  end
78
78
 
79
79
  it "should pass arguments for rspec options that need them" do
80
80
  FileUtils.touch "#{tmp}/file"
81
- Respec::App.new('-I', 'lib', '-t', 'mytag', "#{tmp}/file").generated_args.should == ['-I', 'lib', '-t', 'mytag', "#{tmp}/file"]
81
+ expect(Respec::App.new('-I', 'lib', '-t', 'mytag', "#{tmp}/file").generated_args).to eq ['-I', 'lib', '-t', 'mytag', "#{tmp}/file"]
82
82
  end
83
83
 
84
84
  it "should run all failures if 'f' is given" do
85
85
  make_failures_file 'a.rb:1', 'b.rb:2'
86
86
  app = Respec::App.new('f')
87
- app.generated_args.should == ['a.rb:1', 'b.rb:2']
87
+ expect(app.generated_args).to eq ['a.rb:1', 'b.rb:2']
88
88
  end
89
89
 
90
90
  it "should run the n-th failure if a numeric argument 'n' is given" do
91
91
  make_failures_file 'a.rb:1', 'b.rb:2'
92
92
  app = Respec::App.new('2')
93
- app.generated_args.should == ['b.rb:2']
93
+ expect(app.generated_args).to eq ['b.rb:2']
94
94
  end
95
95
 
96
96
  it "should interpret existing file names as file name arguments" do
97
97
  FileUtils.touch "#{tmp}/existing.rb"
98
98
  app = Respec::App.new("#{tmp}/existing.rb")
99
- app.generated_args.should == ["#{tmp}/existing.rb"]
99
+ expect(app.generated_args).to eq ["#{tmp}/existing.rb"]
100
100
  end
101
101
 
102
102
  it "should pass existing file names with line numbers directly to rspec" do
103
103
  FileUtils.touch "#{tmp}/existing.rb"
104
104
  app = Respec::App.new("#{tmp}/existing.rb:123")
105
- app.generated_args.should == ["#{tmp}/existing.rb:123"]
105
+ expect(app.generated_args).to eq ["#{tmp}/existing.rb:123"]
106
106
  end
107
107
 
108
108
  it "should treat other arguments as example names" do
109
109
  FileUtils.touch "#{tmp}/FILE"
110
110
  app = Respec::App.new("#{tmp}/FILE")
111
- app.generated_args.should == ["#{tmp}/FILE"]
111
+ expect(app.generated_args).to eq ["#{tmp}/FILE"]
112
112
  end
113
113
 
114
114
  it "should not include named files if a numeric argument is given" do
115
115
  FileUtils.touch "#{tmp}/FILE"
116
116
  make_failures_file 'a.rb:1'
117
117
  app = Respec::App.new("#{tmp}/FILE", '1')
118
- app.generated_args.should == ['a.rb:1']
118
+ expect(app.generated_args).to eq ['a.rb:1']
119
119
  end
120
120
 
121
121
  it "should not include named files if an 'f' argument is given" do
122
122
  FileUtils.touch "#{tmp}/FILE"
123
123
  make_failures_file 'a.rb:1'
124
124
  app = Respec::App.new("#{tmp}/FILE", 'f')
125
- app.generated_args.should == ['a.rb:1']
125
+ expect(app.generated_args).to eq ['a.rb:1']
126
126
  end
127
127
 
128
128
  it "should explicitly add the spec directory if no files are given or errors to rerun" do
129
129
  app = Respec::App.new
130
- app.generated_args.should == ['spec']
130
+ expect(app.generated_args).to eq ['spec']
131
131
  end
132
132
 
133
133
  it "should not add the spec directory if any files are given" do
134
134
  FileUtils.touch "#{tmp}/FILE"
135
135
  app = Respec::App.new("#{tmp}/FILE")
136
- app.generated_args.should == ["#{tmp}/FILE"]
136
+ expect(app.generated_args).to eq ["#{tmp}/FILE"]
137
137
  end
138
138
 
139
139
  it "should not add the spec directory if a numeric argument is given" do
140
140
  make_failures_file 'a.rb:1'
141
141
  app = Respec::App.new('1')
142
- app.generated_args.should == ["a.rb:1"]
142
+ expect(app.generated_args).to eq ["a.rb:1"]
143
143
  end
144
144
 
145
145
  it "should not add the spec directory if an 'f' argument is given" do
146
146
  make_failures_file 'a.rb:1'
147
147
  app = Respec::App.new('f')
148
- app.generated_args.should == ["a.rb:1"]
148
+ expect(app.generated_args).to eq ["a.rb:1"]
149
149
  end
150
150
  end
151
151
 
152
152
  describe "#raw_args" do
153
153
  it "should pass arguments after '--' directly to rspec" do
154
154
  app = Respec::App.new('--', '--blah')
155
- app.raw_args.should == ['--blah']
155
+ expect(app.raw_args).to eq ['--blah']
156
156
  end
157
157
  end
158
158
 
@@ -161,7 +161,7 @@ describe Respec::App do
161
161
  Dir.chdir tmp do
162
162
  FileUtils.touch 'Gemfile'
163
163
  app = Respec::App.new('--', '-t', 'TAG')
164
- app.command.should == ['bundle', 'exec', 'rspec', 'spec', '-t', 'TAG', FORMATTER_PATH]
164
+ expect(app.command).to eq ['bundle', 'exec', 'rspec', 'spec', '-t', 'TAG', FORMATTER_PATH]
165
165
  end
166
166
  end
167
167
  end
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Respec::Formatter do
4
+ describe ".extract_spec_location" do
5
+ use_attribute_value RSpec.configuration, :pattern, "**/*_spec.rb"
6
+
7
+ it "should find the spec file for normal examples" do
8
+ metadata = {:location => './spec/models/user_spec.rb:47'}
9
+ expect(described_class.extract_spec_location(metadata)).
10
+ to eq './spec/models/user_spec.rb:47'
11
+ end
12
+
13
+ it "should find the spec file for shared examples" do
14
+ metadata = {
15
+ :location => './spec/support/breadcrumbs.rb:75',
16
+ :example_group => {:location => './spec/requests/breadcrumbs_spec.rb:218'},
17
+ }
18
+ expect(described_class.extract_spec_location(metadata)).
19
+ to eq './spec/requests/breadcrumbs_spec.rb:218'
20
+ end
21
+
22
+ it "should warn when no spec file is found, and return the root location" do
23
+ Respec::Formatter.should_receive(:warn)
24
+ metadata = {:location => './spec/models/user.rb:47'}
25
+ expect(described_class.extract_spec_location(metadata)).
26
+ to eq './spec/models/user.rb:47'
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: respec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-15 00:00:00.000000000 Z
12
+ date: 2013-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -82,6 +82,7 @@ files:
82
82
  - respec.gemspec
83
83
  - spec/integration_spec.rb
84
84
  - spec/respec/app_spec.rb
85
+ - spec/respec/formatter_spec.rb
85
86
  - spec/spec_helper.rb
86
87
  homepage: http://github.com/oggy/respec
87
88
  licenses:
@@ -96,25 +97,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
97
  - - ! '>='
97
98
  - !ruby/object:Gem::Version
98
99
  version: '0'
99
- segments:
100
- - 0
101
- hash: -2382265690551011023
102
100
  required_rubygems_version: !ruby/object:Gem::Requirement
103
101
  none: false
104
102
  requirements:
105
103
  - - ! '>='
106
104
  - !ruby/object:Gem::Version
107
105
  version: '0'
108
- segments:
109
- - 0
110
- hash: -2382265690551011023
111
106
  requirements: []
112
107
  rubyforge_project:
113
- rubygems_version: 1.8.24
108
+ rubygems_version: 1.8.23
114
109
  signing_key:
115
110
  specification_version: 3
116
111
  summary: Rerun failing RSpec examples easily.
117
112
  test_files:
118
113
  - spec/integration_spec.rb
119
114
  - spec/respec/app_spec.rb
115
+ - spec/respec/formatter_spec.rb
120
116
  - spec/spec_helper.rb
117
+ has_rdoc: