Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add --repeat option fo mspec for unstable examples #32

Merged
merged 1 commit into from

3 participants

Ryo Onodera Brian Shirai Dirkjan Bussink
Ryo Onodera

No description provided.

Brian Shirai
Owner

If you use #times inside #repeat, and just have #repeat yield, this would be better encapsulated and we could add events around repeating.

Ryo Onodera

Thanks for a suggestion. I moved #times inside #repeat. It is surely a good encapsulation! Should I also add events around repeating?

Brian Shirai
Owner

If you want to write a reporter or other tooling for the repeat feature, you can add events now. Otherwise, we can wait until we need them.

Ryo Onodera

No, I don't want to write a reporter or other things. I forgo adding events atm. So is this pull request ready to be merged in?

@brixen Thanks for a detailed explanation! I hope this is also merged in the copy in Rubinius. :)

lib/mspec/runner/mspec.rb
@@ -229,6 +230,16 @@ def self.randomize?
@randomize == true
end
+ def self.repeat=(times)
+ @repeat = times
+ end
+
+ def self.repeat(&block)
Dirkjan Bussink
dbussink added a note

Any reason here to capture the block?

Ryo Onodera
ryoqun added a note

Err. This is left from old edits. I'll fix this soon...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Brian Shirai brixen merged commit 008eb0f into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 3, 2012
  1. Ryo Onodera
This page is out of date. Refresh to see the latest.
1  lib/mspec/commands/mspec-run.rb
View
@@ -34,6 +34,7 @@ def options(argv=ARGV)
options.configure { |f| load f }
options.name
options.randomize
+ options.repeat
options.pretend
options.background
options.interrupt
34 lib/mspec/runner/context.rb
View
@@ -197,24 +197,26 @@ def process
if protect "before :all", pre(:all)
@examples.each do |state|
- @state = state
- example = state.example
- MSpec.actions :before, state
-
- if protect "before :each", pre(:each)
- MSpec.clear_expectations
- if example
- passed = protect nil, example
- MSpec.actions :example, state, example
- protect nil, @expectation_missing unless MSpec.expectation? or not passed
+ MSpec.repeat do
+ @state = state
+ example = state.example
+ MSpec.actions :before, state
+
+ if protect "before :each", pre(:each)
+ MSpec.clear_expectations
+ if example
+ passed = protect nil, example
+ MSpec.actions :example, state, example
+ protect nil, @expectation_missing unless MSpec.expectation? or not passed
+ end
+ protect "after :each", post(:each)
+ protect "Mock.verify_count", @mock_verify
end
- protect "after :each", post(:each)
- protect "Mock.verify_count", @mock_verify
- end
- protect "Mock.cleanup", @mock_cleanup
- MSpec.actions :after, state
- @state = nil
+ protect "Mock.cleanup", @mock_cleanup
+ MSpec.actions :after, state
+ @state = nil
+ end
end
protect "after :all", post(:all)
else
11 lib/mspec/runner/mspec.rb
View
@@ -24,6 +24,7 @@ module MSpec
@features = {}
@exception = nil
@randomize = nil
+ @repeat = nil
@expectation = nil
@expectations = false
@@ -229,6 +230,16 @@ def self.randomize?
@randomize == true
end
+ def self.repeat=(times)
+ @repeat = times
+ end
+
+ def self.repeat
+ (@repeat || 1).times do
+ yield
+ end
+ end
+
def self.shuffle(ary)
return if ary.empty?
7 lib/mspec/utils/options.rb
View
@@ -385,6 +385,13 @@ def randomize
end
end
+ def repeat
+ on("-R", "--repeat", "NUMBER",
+ "Repeatedly run an example NUMBER times") do |o|
+ MSpec.repeat = o.to_i
+ end
+ end
+
def verbose
on("-V", "--verbose", "Output the name of each file processed") do
obj = Object.new
24 spec/utils/options_spec.rb
View
@@ -1092,6 +1092,30 @@
end
end
+describe "The -R, --repeat option" do
+ before :each do
+ @options, @config = new_option
+ @options.repeat
+ end
+
+ it "is enabled with #repeat" do
+ @options.should_receive(:on).with("-R", "--repeat", "NUMBER", an_instance_of(String))
+ @options.repeat
+ end
+
+ it "registers the MSpec repeat mode" do
+ ["-R", "--repeat"].each do |opt|
+ MSpec.repeat = 1
+ @options.parse [opt, "10"]
+ repeat_count = 0
+ MSpec.repeat do
+ repeat_count += 1
+ end
+ repeat_count.should == 10
+ end
+ end
+end
+
describe "The -V, --verbose option" do
before :each do
@options, @config = new_option
Something went wrong with that request. Please try again.