-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://rspec-ext.rubyforge.org/svn/distributed/branches/bob_1_1_work@13 b9fc4567-813f-4f01-94b2-355dee807878
- Loading branch information
Showing
8 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Spec | ||
module Distributed | ||
class ExampleGroupValueHolder | ||
def initialize(example_group) | ||
@description = example_group.description | ||
@description = @description == "" ? example_group.name : @description # waiting on #187 in rspec | ||
# @spec_path = example_group.spec_path | ||
end | ||
|
||
def value | ||
rspec_options.example_groups.find do |eg| | ||
eg.description == @description || eg.name == @description # && | ||
# eg.spec_path == @spec_path | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Spec | ||
module Distributed | ||
class ExampleValueHolder | ||
def initialize(example) | ||
@description = example.description | ||
@example_group_value_holder = ExampleGroupValueHolder.new(example.class) | ||
end | ||
|
||
def value | ||
example_group = @example_group_value_holder.value | ||
e = example_group.examples.find do |e| | ||
e.description == @description | ||
end | ||
e | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
module Spec | ||
module Distributed | ||
# This is used as a reporter and just records method invocations. It is then | ||
# sent back to the master and all the invocations are replayed there on the master's | ||
# *real* reporter. Nifty, eh? | ||
class RecordingFormatter | ||
def initialize(watermark) | ||
@watermark = watermark | ||
@invocations = [] | ||
end | ||
|
||
def method_missing(method, *args) | ||
marshallable_args = args.map {|arg| pack_arg(arg)} | ||
# if method.to_s == 'add_example_group' | ||
# # Watermark each example group description so the final report says where it ran | ||
# marshallable_args[0].description << " (#{@watermark})" | ||
# end | ||
@invocations << [method, *marshallable_args] | ||
end | ||
|
||
def pack_arg(o) | ||
if Spec::Example::ExampleGroupMethods === o | ||
ExampleGroupValueHolder.new(o) | ||
elsif Spec::Example::ExampleGroupMethods === o.class | ||
ExampleValueHolder.new(o) | ||
else | ||
ValueHolder.new(o) | ||
end | ||
end | ||
|
||
def replay(target) | ||
@invocations.each do |method, *args| | ||
unpacked_args = args.map { |arg| arg.value } | ||
target.__send__(method, *unpacked_args) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
module Spec | ||
module Distributed | ||
# This is used as a reporter and just records method invocations. It is then | ||
# sent back to the master and all the invocations are replayed there on the master's | ||
# *real* reporter. Nifty, eh? | ||
class RecordingFormatter | ||
def initialize(watermark) | ||
@watermark = watermark | ||
@invocations = [] | ||
end | ||
|
||
def method_missing(method, *args) | ||
marshallable_args = args.map {|arg| pack_arg(arg)} | ||
# if method.to_s == 'add_example_group' | ||
# # Watermark each example group description so the final report says where it ran | ||
# marshallable_args[0].description << " (#{@watermark})" | ||
# end | ||
@invocations << [method, *marshallable_args] | ||
end | ||
|
||
def pack_arg(o) | ||
if Spec::Example::ExampleGroupMethods === o | ||
ExampleGroupValueHolder.new(o) | ||
elsif Spec::Example::ExampleGroupMethods === o.class | ||
ExampleValueHolder.new(o) | ||
else | ||
ValueHolder.new(o) | ||
end | ||
end | ||
|
||
def replay(target) | ||
@invocations.each do |method, *args| | ||
unpacked_args = args.map { |arg| arg.value } | ||
target.__send__(method, *unpacked_args) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Spec | ||
module Distributed | ||
class ValueHolder | ||
attr_reader :value | ||
def initialize(v) | ||
@value = v | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require File.dirname(__FILE__) + '/../../spec_helper.rb' | ||
module Spec | ||
module Distributed | ||
describe ExampleGroupValueHolder do | ||
attr_reader :example_group, :holder | ||
include OptionsHelper | ||
|
||
before do | ||
@example_group = mock("example_group") | ||
# @example_group.should_receive(:spec_path).twice.and_return("spec_path") | ||
|
||
@rspec_options = mock("rspec_options") | ||
@rspec_options.should_receive(:example_groups).and_return([@example_group]) | ||
end | ||
|
||
it "should return the example group when example group has a description" do | ||
@example_group.should_receive(:description).twice.and_return("description") | ||
@holder = ExampleGroupValueHolder.new(@example_group) | ||
|
||
with_rspec_options(@rspec_options) do | ||
holder.value.should equal(example_group) | ||
end | ||
end | ||
|
||
it "should return the example group when example group has no description (for #187 in rspec)" do | ||
@example_group.should_receive(:description).twice.and_return("") | ||
@example_group.should_receive(:name).twice.and_return("MyTestCase") | ||
@holder = ExampleGroupValueHolder.new(@example_group) | ||
|
||
with_rspec_options(@rspec_options) do | ||
holder.value.should equal(example_group) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require File.dirname(__FILE__) + '/../../spec_helper.rb' | ||
module Spec | ||
module Distributed | ||
describe ExampleValueHolder do | ||
include OptionsHelper | ||
attr_reader :example, :holder | ||
before do | ||
@example_group = mock('example_group') | ||
@example = mock("example") | ||
@example.should_receive(:class).twice.and_return(@example_group) | ||
@example.should_receive(:description).twice.and_return("description") | ||
|
||
# @example_group.should_receive(:spec_path).twice.and_return("spec_path") | ||
@example_group.should_receive(:description).twice.and_return("eg description") | ||
@example_group.should_receive(:examples).and_return([@example]) | ||
|
||
@rspec_options = mock("rspec_options") | ||
@rspec_options.should_receive(:example_groups).and_return([@example_group]) | ||
|
||
@holder = ExampleValueHolder.new(@example) | ||
end | ||
|
||
it "should return the example" do | ||
with_rspec_options(@rspec_options) do | ||
holder.value.should equal(example) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require File.dirname(__FILE__) + '/../../spec_helper.rb' | ||
module Spec | ||
module Distributed | ||
describe RecordingFormatter do | ||
attr_reader :recorder, :target | ||
before do | ||
@recorder = RecordingFormatter.new("Watermark") | ||
@target = mock("target reporter") | ||
end | ||
|
||
it "should replay a simple method call with no parameters" do | ||
target.should_receive(:simple_method_call) | ||
|
||
recorder.simple_method_call | ||
recorder.replay(target) | ||
end | ||
|
||
it "should replay a method call with parameters" do | ||
target.should_receive(:simple_method_call).with("parameter") | ||
recorder.simple_method_call("parameter") | ||
recorder.replay(target) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require File.dirname(__FILE__) + '/../../spec_helper.rb' | ||
module Spec | ||
module Distributed | ||
describe ValueHolder do | ||
it "should be constructed with a value" do | ||
ValueHolder.new("a") | ||
end | ||
|
||
it "should return the held value" do | ||
ValueHolder.new("a").value.should == "a" | ||
end | ||
end | ||
end | ||
end |