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

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” (Amazon.com) 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

I figured that problem out… Another gem needed to be installed:
rack-test

Jason

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

Yeah, that’s a major pain…

I put my stuff up here: Service Oriented Design with Ruby and Rails (examples that actually work) · GitHub

And later on I found:

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

Oops it connects. That was my firewall blocking 3000, sorry.

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]

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.

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:

README for chapter 1 code:

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” (Amazon.com) 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