How do I pass form values from POST controller specs?

aslak hellesoy
Fri, 18 Jan 2008 09:24:23 -0000

Hi there

I just started my first Merb app and I''m running into some weird
things in Specs. When I do:

  describe "create action" do
    it "should create a new project" do
      project_params = {:name => ''bekkunin''}
      Project.should_receive(:create).with(project_params)
      controller, action = post(''/projects'', :project =>
project_params)
    end
  end

Merb::Test::FakeRequest#with (and #new) invoke
Hash#environmentize_keys! on the hash I send in as the 2nd arg to
post, and this seems very odd to me. Why is it upcasing the keys in
the hash *I* send in from my spec? In my controller action, I try to
access params[:project], but it''s nil. I tried this instead to work
around it:

  describe "create action" do
    it "should create a new project" do
      project_params = {:name => ''bekkunin''}
      Project.should_receive(:create).with(project_params)
      req = fake_request
      req[:project] = project_params
      controller, action = post(''/projects'', :fake_request
=> req)
    end
  end

Now my action doesn''t even get called. the value of action is
''bad_request'', probably because the fake request I created
doesn''t
have all the right stuff.

I can''t for the life of me grok how I send in "form" values
to a POST
action from a spec and could use some help here. If someone can
explain to me the intended behaviour I can submit a patch. I did a
fresh checkout and ran rake specs. Then I got a lot of errors. Here is
the last one:

18)
NoMethodError in ''a merb mailer should be able to use a different
sendmail path''
undefined method `body='' for #<MailFactory:0x3347af8>
/Users/aslakhellesoy/scm/merb/lib/merb/mailer.rb:82:in `send''
/Users/aslakhellesoy/scm/merb/lib/merb/mailer.rb:82:in `initialize''
/Users/aslakhellesoy/scm/merb/lib/merb/mailer.rb:82:in `each''
/Users/aslakhellesoy/scm/merb/lib/merb/mailer.rb:82:in `initialize''
./spec/merb/mailer_spec.rb:22:in `new''
./spec/merb/mailer_spec.rb:22:in `setup_test_mailer''
./spec/merb/mailer_spec.rb:81:

Finished in 9.677867 seconds

821 examples, 18 failures, 2 pending

My environment:

* OS X Tiger
* ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-darwin8.11.1]
Gems:
abstract (1.0.0)
actionmailer (2.0.2)
actionpack (2.0.2)
activerecord (2.0.2)
activeresource (2.0.2)
activesupport (2.0.2, 2.0.1)
archive-tar-minitar (0.5.1)
builder (2.1.2)
cgi_multipart_eof_fix (2.5.0)
coderay (0.7.4.215)
color (1.4.0)
daemons (1.0.9)
diff-lcs (1.1.2)
directory_watcher (1.1.0)
erubis (2.4.1)
eventmachine (0.10.0)
fastthread (1.0.1)
fcgi (0.8.7)
flexmock (0.8.0)
gem_plugin (0.2.3)
god (0.6.0)
GraphvizR (0.5.1)
gratr (0.4.3)
haml (1.7.2)
heckle (1.4.1)
heel (0.6.0)
highline (1.4.0)
hoe (1.4.0, 1.3.0)
hpricot (0.6)
json (1.1.2)
json_pure (1.1.2)
launchy (0.3.1)
libxml-ruby (0.5.2.0)
liquid (1.7.0)
logging (0.5.3)
markaby (0.5)
memcache-client (1.5.0)
merb (0.5.2)
merb_activerecord (0.5)
meta_project (0.4.15)
mime-types (1.15)
mocha (0.5.5)
mongrel (1.1.3, 1.1.1)
mongrel_cluster (1.0.5)
needle (1.3.0)
net-sftp (1.1.0)
net-ssh (1.1.2)
newgem (0.16.1)
oniguruma (1.1.0)
open4 (0.9.6)
ParseTree (2.1.1, 2.0.2)
pdf-storycards (0.0.1)
pdf-writer (1.1.7, 1.1.4)
piston (1.3.3)
Platform (0.4.0)
plist (3.0.0)
rack (0.2.0)
rails (2.0.2)
rake (0.8.1)
rb-appscript (0.4.0)
rcov (0.8.1.2.0)
RedCloth (3.0.4)
rspec (1.1.1)
rubigen (1.1.1)
ruby-growl (1.0.1)
ruby2ruby (1.1.8, 1.1.7)
rubyforge (0.4.4)
rubygems-update (1.0.1)
RubyInline (3.6.6, 3.6.5)
rubyworks_app (0.0.1)
safariwatir (0.2.5)
sinatra (0.1.7)
sqlite3-ruby (1.2.1)
syntax (1.0.0)
textpow (0.10.0)
thin (0.5.0)
tidy (1.1.2)
transaction-simple (1.4.0)
tzinfo (0.3.5)
ultraviolet (0.10.1)
uuidtools (1.0.2)
vlad (1.1.0)
webby (0.6.0)
ZenTest (3.6.1)

Am I doing something obviously wrong?

Cheers,
Aslak