<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
<blockquote
cite="mid765a2c230702192014j7a365acfg3563a61301413815@mail.gmail.com"
type="cite">
<pre wrap="">
So, I still say my app code and my reduction look conceptually the
same, but I'm stumped as to why they don't behave the same way
</pre>
</blockquote>
David seems to have picked that up. Ignore my blatherings about
HashArgConstraint (though the rest is valid).<br>
<br>
Here's another twist under Rails 1.2.2 (which may not be supported but
works fine for what I am doing so far). <br>
<br>
Basically, a different <u>expectation</u> seems to be set up depending
on whether the argument to get/post is a variable or not. That cannot
be right. What am I missing?<br>
<br>
<tt>require File.dirname(__FILE__) + '/../spec_helper'<br>
<br>
class TestController < ActionController::Base<br>
def index() self.amethod(params) end<br>
end<br>
<br>
context 'a test controller' do<br>
controller_name :test<br>
<br>
setup do<br>
@plist = { "id" => "1", "param2" => "bar" }<br>
controller.should_receive(:amethod).with(@plist).and_return(true)<br>
end<br>
<br>
specify "should pass a hash to #with (1)" do<br>
get :index, "id" => "1", "param2" => "bar"<br>
end<br>
specify "should pass a hash to #with (2)" do<br>
get :index, { "id" => "1", "param2" => "bar" }<br>
end<br>
specify "should pass a hash to #with (3)" do<br>
get :index, @plist<br>
end<br>
end<br>
<br>
</tt><tt>$ spec -cfs spec/controllers/test_controller_spec.rb <br>
/usr/bin/spec:17:Warning: require_gem is obsolete. Use gem instead.<br>
/home/jjw/rails/playground/config/boot.rb:29:Warning: require_gem is
obsolete. Use gem instead.<br>
<br>
a test controller<br>
- should pass a hash to #with (1) (FAILED - 1)<br>
- should pass a hash to #with (2) (FAILED - 2)<br>
- should pass a hash to #with (3) (FAILED - 3)<br>
<br>
1)<br>
'a test controller should pass a hash to #with (1)' FAILED <b>(ignore
the failure, look at the expectation)</b><br>
#<TestController:0xb70a1df8> expected :amethod with (["param2",
"bar"], ["id", "1"]) but received it with ({"action"=>"index",
"id"=>"1", "param2"=>"bar", "controller"=>"test"})<br>
(eval):3:in `amethod'<br>
./spec/controllers/test_controller_spec.rb:4:in `index'<br>
/usr/local/lib/site_ruby/1.8/benchmark.rb:300:in `measure'<br>
./spec/controllers/test_controller_spec.rb:13:<br>
<br>
2)<br>
'a test controller should pass a hash to #with (2)' FAILED </tt><tt><b>(ignore
the failure, look at the expectation)</b></tt><br>
<tt>#<TestController:0xb7093820> expected :amethod with
(["param2", "bar"], ["id", "1"]) but received it with
({"action"=>"index", "id"=>"1", "param2"=>"bar",
"controller"=>"test"})<br>
(eval):3:in `amethod'<br>
./spec/controllers/test_controller_spec.rb:4:in `index'<br>
/usr/local/lib/site_ruby/1.8/benchmark.rb:300:in `measure'<br>
./spec/controllers/test_controller_spec.rb:18:<br>
<br>
3)<br>
'a test controller should pass a hash to #with (3)' FAILED </tt><tt><b>(ignore
the failure, look at the expectation)</b></tt><br>
<tt>#<TestController:0xb708cf34> expected :amethod with (<b>[:only_path,
true]</b>, ["param2", "bar"], ["id", "1"], <b>[:action, :index]</b>)
but received it with ({"action"=>"index", "id"=>"1",
"param2"=>"bar", "controller"=>"test"})<br>
(eval):3:in `amethod'<br>
./spec/controllers/test_controller_spec.rb:4:in `index'<br>
/usr/local/lib/site_ruby/1.8/benchmark.rb:300:in `measure'<br>
./spec/controllers/test_controller_spec.rb:23:<br>
<br>
Finished in 0.022612 seconds<br>
<br>
3 specifications, 3 failures<br>
<br>
<br>
</tt>Where the heck did the :only_path stuff come from in the
expectation for case 3?? They weren't there in
ArgumentExpectation#initialize.<br>
<br>
As expected, creating the 'right' expectation (<tt>@plist = { "id"
=> "1","param2" => "bar", "action" => "index", "controller"
=> "test" } ) </tt>allows the spec to pass in cases 1 & 2, but
#3 still fails.<br>
<br>
rgds from "Confused of Hampshire".<br>
<br>
<br>
<tt><br>
</tt>
</body>
</html>