schmurfy-bacon 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+
3
+ $LOAD_PATH.unshift << File.expand_path('../../lib/', __FILE__)
4
+
5
+ require 'bacon'
6
+
7
+ Bacon.summary_on_exit
8
+
9
+ # define this if you want to be sure you are
10
+ # executing every tests.
11
+ # (I use this in my "rake test" task)
12
+ #
13
+ # Bacon.allow_focused_run = false
14
+
15
+ describe 'FocusSpec' do
16
+ focus "could do something"
17
+
18
+ it 'does nothing' do
19
+ 1.should == 1
20
+ end
21
+
22
+ it 'also does nothing' do
23
+ 1.should == 1
24
+ end
25
+
26
+ it 'could do something' do
27
+ 1.should == 1
28
+ end
29
+
30
+ end
31
+
32
+ describe 'FocusContextSpec' do
33
+ focus_context "sub context"
34
+
35
+ it 'does nothing' do
36
+ 1.should == 1
37
+ end
38
+
39
+ describe 'sub context' do
40
+ it 'also does nothing' do
41
+ 2.should == 1
42
+ end
43
+
44
+ it 'does nothing once more but pass' do
45
+ 1.should == 1
46
+ end
47
+ end
48
+
49
+ it 'could do something' do
50
+ 1.should == 1
51
+ end
52
+
53
+ end
data/lib/bacon.rb CHANGED
@@ -14,9 +14,6 @@ module Bacon
14
14
  raise NameError, "no such context: #{name.inspect}"
15
15
  }
16
16
 
17
- RestrictName = // unless defined? RestrictName
18
- RestrictContext = // unless defined? RestrictContext
19
-
20
17
  Backtraces = true unless defined? Backtraces
21
18
 
22
19
 
@@ -31,6 +28,18 @@ module Bacon
31
28
  extend SpecDoxOutput
32
29
  end
33
30
 
31
+ # focus ----
32
+ @allow_focused_run = true
33
+
34
+ class <<self
35
+ attr_accessor :allow_focused_run
36
+ alias_method :allow_focused_run?, :allow_focused_run
37
+
38
+ attr_accessor :focus_name_regexp, :focus_context_regexp
39
+ end
40
+
41
+ # ------
42
+
34
43
  @backtrace_size = nil
35
44
 
36
45
  def self.backtrace_size=(n)
@@ -100,7 +109,6 @@ module Bacon
100
109
  end
101
110
 
102
111
  def run
103
- return unless name =~ RestrictContext
104
112
  Counter[:context_depth] += 1
105
113
  Bacon.handle_specification(name) { instance_eval(&block) }
106
114
  Counter[:context_depth] -= 1
@@ -122,8 +130,20 @@ module Bacon
122
130
  end
123
131
  end
124
132
 
133
+
134
+ def focus(spec_str)
135
+ raise "focused test forbidden" unless Bacon::allow_focused_run?
136
+ Bacon::focus_name_regexp = %r{#{spec_str}}
137
+ end
138
+
139
+ def focus_context(context_str)
140
+ raise "focused test forbidden" unless Bacon::allow_focused_run?
141
+ Bacon::focus_context_regexp = %r{#{context_str}}
142
+ end
143
+
125
144
  def it(description, &block)
126
- return unless description =~ RestrictName
145
+ return unless name =~ Bacon::focus_context_regexp
146
+ return unless description =~ Bacon::focus_name_regexp
127
147
  block ||= lambda { should.flunk "not implemented" }
128
148
  Counter[:specifications] += 1
129
149
  run_requirement description, block
@@ -242,7 +262,12 @@ end
242
262
 
243
263
  module Kernel
244
264
  private
245
- def describe(*args, &block) Bacon::Context.new(args.join(' '), &block).run end
265
+ def describe(*args, &block)
266
+ Bacon::focus_name_regexp = //
267
+ Bacon::focus_context_regexp = //
268
+ Bacon::Context.new(args.join(' '), &block).run
269
+ end
270
+
246
271
  def shared(name, &block) Bacon::Shared[name] = block end
247
272
  end
248
273
 
@@ -13,13 +13,13 @@ module Bacon
13
13
  end
14
14
  end
15
15
 
16
- class Context
17
- include Mocha::API
18
-
19
- alias_method :it_before_mocha, :it
16
+ module MochaSpec
17
+ def self.included(base)
18
+ base.send(:include, Mocha::API)
19
+ end
20
20
 
21
- def it(description, &block)
22
- it_before_mocha(description) do
21
+ def execute_spec(&block)
22
+ super do
23
23
  begin
24
24
  mocha_setup
25
25
  block.call
@@ -31,5 +31,8 @@ module Bacon
31
31
  end
32
32
  end
33
33
  end
34
+
34
35
  end
36
+
37
+ Context.send(:include, MochaSpec)
35
38
  end
data/lib/bacon/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bacon
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schmurfy-bacon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: term-ansicolor
16
- requirement: &70141825879320 !ruby/object:Gem::Requirement
16
+ requirement: &70177919026240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70141825879320
24
+ version_requirements: *70177919026240
25
25
  description: ! 'Bacon is a small RSpec clone weighing less than 350 LoC but
26
26
 
27
27
  nevertheless providing all essential features.
@@ -45,6 +45,7 @@ files:
45
45
  - bacon.gemspec
46
46
  - bin/bacon
47
47
  - examples/em_spec.rb
48
+ - examples/focus_spec.rb
48
49
  - examples/mocha_spec.rb
49
50
  - lib/autotest/bacon.rb
50
51
  - lib/autotest/bacon_rspec.rb
@@ -75,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
76
  version: '0'
76
77
  segments:
77
78
  - 0
78
- hash: 3626099875100681830
79
+ hash: -3207212041725113050
79
80
  required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  none: false
81
82
  requirements:
@@ -84,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
85
  version: '0'
85
86
  segments:
86
87
  - 0
87
- hash: 3626099875100681830
88
+ hash: -3207212041725113050
88
89
  requirements: []
89
90
  rubyforge_project:
90
91
  rubygems_version: 1.8.11