Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tutorials to Testing using RSPEC on PADRINO framework on RUBY

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.

like image 455
Sandip Agarwal Avatar asked May 14 '12 12:05

Sandip Agarwal


1 Answers

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:

  • How to use rspec in a Sinatra Application
  • Sinatra, RSpec and DataMapper: Configuring and using a database for tests

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!

like image 53
Samy Dindane Avatar answered Sep 28 '22 08:09

Samy Dindane