Mocking within a Proc/Block?

The following works:

it “should evaluate a passed in block in the context of the
interview object” do
block = Proc.new { raise unless self.is_a?
(Interview) }.should_not raise_error
Interview.create(:title => “Text”, &block)
end

However, the following does not:

it “should evaluate a passed in block in the context of the
interview object” do
block = Proc.new { self.should be_an_instance_of(Interview) }
Interview.create(:title => “Text”, &block)
end

I’d far prefer to use the latter. However “be_an_instance_of” is not
defined on my Interview class per the interpreter. While I’ve poked
a little inside RSpec for insights, I’m just a tad too tired to dig
in for an answer for this one. Can someone help me out after
clobbering me for what is likely to turn out to be a foolish question?

Thanks,
Evan

On 10/24/07, Evan David L. [email protected] wrote:

it “should evaluate a passed in block in the context of the
interview object” do
block = Proc.new { self.should be_an_instance_of(Interview) }
Interview.create(:title => “Text”, &block)
end

I’d far prefer to use the latter. However “be_an_instance_of” is not
defined on my Interview class per the interpreter.

That is correct. It gets evaluated, as your example narrative states:
in the context of the interview object.

How about something like this?

it “should evaluate …” do
$interview = nil
Interview.create(:title => “Text”) do
$interview = self
end
$interview.should be_an_instance_of(Interview)
end
end