Forum: RSpec [Sinatra] "tried to create Proc object without a block"

D8b60a81acbdfa264f4fefa9ef511a62?d=identicon&s=25 jtanium (Guest)
on 2010-11-28 20:15
(Received via mailing list)
Hello all,

I'm a long time Ruby and Rails user, but new to RSpec; I've been using
Shoulda instead.

I picked up the book "Service-Oriented Design with Ruby and
Rails" (http://amzn.to/9sgx99) which uses RSpec throughout. Despite
being published only a few months ago, it's already out of date.

Here's the gist with the relevant files: https://gist.github.com/718122
(you can see where I commented out a few lines trying to get it to
work).

I'm guessing the book was written using RSpec 1, and some older
(unknown) version of Rack. I've got Rack-1.2.1 and RSpec-2.1.0
installed.

This is what I get when I run "rspec spec":

  1) service should return a user by name
     Failure/Error: get '/api/v1/users/jason'
     tried to create Proc object without a block
     # (__DELEGATE__):2:in `send'
     # (__DELEGATE__):2:in `get'
     # ./spec/service_spec.rb:23

I'm guessing the spec just needs a minor tweak or two to start
working, but I have no idea what that would be.

Thanks for any help you can provide,

Jason
D8b60a81acbdfa264f4fefa9ef511a62?d=identicon&s=25 Jason Edwards (Guest)
on 2010-11-29 11:05
(Received via mailing list)
I figured that problem out...  Another gem needed to be installed:
rack-test

Jason
Cb1a66fe3de1f2e393d4d44e1334592f?d=identicon&s=25 Ernst Arnold (ernst)
on 2010-12-03 23:55
I get the same error message as Jason. However installing rack-test did
not help in my case. (I am new to Ruby, and don't yet know how to use
the debugger)

Tried with rvm use 1.9.2 and rvm use 1.8.7

Generally I am a bit disappointed that the code from the book needed a
number of changes to get even this far.

Ernst
D8b60a81acbdfa264f4fefa9ef511a62?d=identicon&s=25 Jason Edwards (Guest)
on 2010-12-04 00:50
(Received via mailing list)
Yeah, that's a major pain...

I put my stuff up here: https://gist.github.com/720605

And later on I found:
https://github.com/pauldix/service-oriented-design-with-ruby

I tried to include comments about what I changed to get it to work.
When I found pauldix's, it looked like he had made pretty much all the
same changes I had.

If my Gist and the GitHub project don't help, post your code...

Jason
Cb1a66fe3de1f2e393d4d44e1334592f?d=identicon&s=25 Ernst Arnold (ernst)
on 2010-12-04 01:55
I adapted the first lines of service_spec.rb according to Jason's code:

require File.dirname(__FILE__) + '/../service'
require 'rspec'                               # was 'spec' (Jason)
#require 'spec/interop/test'                  # no idea what this was
require 'rack/test'
require 'test/unit'                           # gem install test-unit
require 'sinatra'
require 'json'

set :environment, :test
Test::Unit::TestCase.send :include, Rack::Test::Methods

RSpec.configure do |conf|                    #from Jason
  conf.include Rack::Test::Methods
end

Also needed to replace
JSON.parse(last_response.body)
with
JSON.parse(last_response.body)["user"]

At last
rspec  spec/service_spec.rb
passes

ruby service.rb -p 3000
seems to work but
telnet locahost 3000 never connects

Thank you for sharing your code.
Cb1a66fe3de1f2e393d4d44e1334592f?d=identicon&s=25 Ernst Arnold (ernst)
on 2010-12-04 12:25
Oops it connects. That was my firewall blocking 3000, sorry.
Cb1a66fe3de1f2e393d4d44e1334592f?d=identicon&s=25 Ernst Arnold (ernst)
on 2010-12-04 12:38
Next step, testing the client:
rspec spec/client_spec.rb

/home/ernsta/.rvm/gems/ruby-1.9.2-p0/gems/typhoeus-0.2.0/lib/typhoeus/multi.rb:21:
[BUG] Segmentation fault
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
76c208d1476fd6ba638c63aaac4e27cc?d=identicon&s=25 Paul D. (paul_d)
on 2010-12-05 22:04
Ok, I've updated the code examples in Chapter 1 to use the latest gem
versions. Also, I've included a gemfile so going forward new gem
versions shouldn't break anything. You'll just be able to bundle
install to get the right ones.

Code here:
https://github.com/pauldix/service-oriented-design...

README for chapter 1 code:
https://github.com/pauldix/service-oriented-design...

I'll be updating the other code examples more today and in the coming
week. Let me know if there are any issues.

Thanks,
Paul

jtanium wrote in post #964516:
> Hello all,
>
> I'm a long time Ruby and Rails user, but new to RSpec; I've been using
> Shoulda instead.
>
> I picked up the book "Service-Oriented Design with Ruby and
> Rails" (http://amzn.to/9sgx99) which uses RSpec throughout. Despite
> being published only a few months ago, it's already out of date.
>
> Here's the gist with the relevant files: https://gist.github.com/718122
> (you can see where I commented out a few lines trying to get it to
> work).
>
> I'm guessing the book was written using RSpec 1, and some older
> (unknown) version of Rack. I've got Rack-1.2.1 and RSpec-2.1.0
> installed.
>
> This is what I get when I run "rspec spec":
>
>   1) service should return a user by name
>      Failure/Error: get '/api/v1/users/jason'
>      tried to create Proc object without a block
>      # (__DELEGATE__):2:in `send'
>      # (__DELEGATE__):2:in `get'
>      # ./spec/service_spec.rb:23
>
> I'm guessing the spec just needs a minor tweak or two to start
> working, but I have no idea what that would be.
>
> Thanks for any help you can provide,
>
> Jason
This topic is locked and can not be replied to.