[rspec-devel] [ rspec-Feature Requests-10539 ] Add class_type constraint for mocks

noreply at rubyforge.org noreply at rubyforge.org
Sun Nov 18 21:49:23 EST 2007


Feature Requests item #10539, was opened at 2007-05-03 02:30
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=10539&group_id=797

Category: mock module
Group: None
>Status: Closed
Priority: 3
Submitted By: Brian Takita (btakita)
Assigned to: Nobody (None)
Summary: Add class_type constraint for mocks

Initial Comment:
I know that we are all supposed to think Duck Typing :), but sometimes its more convenient and useful to have a constraint on a Class type.

Maybe we can add a class_type method to be used in addition to the duck_type method.



----------------------------------------------------------------------

Comment By: Chad Humphries (spicycode)
Date: 2007-11-19 02:31

Message:
Moved to http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/42-10539-add-class_type-constraint-for-mocks#ticket-42-2

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2007-05-03 19:00

Message:
No. It's for matching expressions. The mock thing is the sneaky part :)

It's intent is more for expectations like:

File.should exist(path)



----------------------------------------------------------------------

Comment By: Brian Takita (btakita)
Date: 2007-05-03 18:57

Message:
That works. So predicate_matchers is a spec/mock only thing
right?

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2007-05-03 04:23

Message:
You can kinda fake this now - it's sneaky, but....

describe "sneaky use of predicate matchers as mock argument matcher" do
  predicate_matchers[:a] = :is_a?
  
  it "should make Brian happy" do
    m = mock("thing")
    m.should_receive(:message).with(a(String))
    m.message("this is a string")
  end
end

WDYT?



----------------------------------------------------------------------

Comment By: Brian Takita (btakita)
Date: 2007-05-03 03:51

Message:
Sorry, here is an example.

it "sets Expectations differ when differ_class is set" do
  @options.differ_class = Spec::Expectations::Differs::Default
 
Spec::Expectations.should_receive(:differ=).with(:anything).and_return
do |arg|
    arg.class.should == Spec::Expectations::Differs::Default
  end
  @options.create_behaviour_runner
end

It would be nice to say:
Spec::Expectations.should_receive(:differ=).with(class_type(Spec::Expectations::Differs::Default))

Saying duck_type would be ambigious in this situation.

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2007-05-03 03:16

Message:
Would this do what you are looking for?

http://rubyforge.org/tracker/index.php?func=detail&aid=5064&group_id=797&atid=3152

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=10539&group_id=797


More information about the rspec-devel mailing list