5

I am new to Ruby and have been asked to use it in our new project. We have also been asked to use Padrino (Sinatra) as backend/framework. For testing we have been asked to use Rspec. I have been hunting for tutorials for long that would guide in using Rspec for Ruby on Padrino. What I get is mostly with reference to RoR. But, I am in need of Ruby on Padrino.

Please guide me for the same with any starters/guides/references/discussions, etc.

Please correct me, if I am wrong anywhere. May be I haven't searched with the right combination of words/phrases for my issue.

I am using Ruby 1.9.3 and Padrino v.0.10.6.

Note : I have also referred the SO question, but it didn't help.

Community
  • 1
  • 1
Sandip Agarwal
  • 1,890
  • 5
  • 28
  • 42

1 Answers1

12

I never used Padrino, but it seems that it isn't much different from Sinatra.

I suggest reading Sinatra and RSpec resources. You can get started with this:

And by reading specs that were written by other people on GitHub. These are some of mine, but they are not the cleanest thing that exists.


EDIT: a short tutorial

Getting started with this framework is much quicker and easier than with Sinatra. :)

Install Padrino: gem install padrino

Create an application: padrino g project myapp -d datamapper -t rspec
The command speaks for itself. :)

Run the tests: rspec --color
No tests were found, obviously. Let's create one in spec/hello/hello_spec.rb:

require File.dirname(__FILE__) + "/../spec_helper.rb"

describe "get '/'" do
  it "should display hello world" do
    get '/'
    last_response.body.should == "Hello world!"
  end
end

Run the tests again.
They failed, because no route get '/' exists. Let's create it.

In app/controllers/hello.rb:

Myapp.controller do
  get '/' do
    "Hello world!"
  end
end

Run the test: it passes!

Check Padrino's documentation for more information and cool features, such as the controllers generator and the admin interface.

Good luck!

Samy Dindane
  • 17,900
  • 3
  • 40
  • 50