InfoQ

News

Rails BDD with Macros, I18n,... with Remarkable

Posted by Sebastien Auvray on May 04, 2009

Community
Ruby
Topics
Ruby on Rails
Tags
Rails ,
RSpec ,
TDD ,
BDD

There are many ways to develop, test and integrate your Rails application: from TDD with the basic Test::Unit or ZenTest, to BDD with RSpec, Shoulda or Cucumber. It's also possible to write  custom RSpec matchers.

It can be difficult to find the right tool and find out their best practices. Remarkable tries to unify the syntax and adds some more flavors to make Rails BDD painless.

Remarkable is a framework using its own DSL. Remarkable extends RSpec by providing macros and I18n support. It comes with an exhaustive collection of RSpec matchers covering all ActiveRecord validations with all options (:through, :source, :source_type, :class_name, :foreign_key, ...). It also has a collection of matchers for ActionController.

You can use either RSpec or Shoulda-like syntax (from the project website):

    1) it { should validate_numericality_of(:age).greater_than(18).only_integer }

    2) it { should validate_numericality_of(:age, :greater_than => 18, :only_integer => true) }


    3) should_validate_numericality_of :age, :greater_than => 18, :only_integer => true

    4) should_validate_numericality_of :age do |m|
         m.only_integer
         m.greater_than 18
         # Or: m.greater_than = 18

       end

At the end, you will be able to write easily your model specifications: 

  describe Post do
    should_belong_to :user
    should_have_many :comments
    should_have_and_belong_to_many :tags


    should_validate_presence_of :body
    should_validate_presence_of :title
    should_validate_uniqueness_of :title, :allow_blank => true
  end

Remarkable 3.0.10 is available and quite an active project; Next releases should come up with more Rails matchers such as ActionView supports.

No comments

Watch Thread Reply

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.