InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

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

Posted by Sebastien Auvray on May 04, 2009

Sections
Development
Topics
Ruby ,
Ruby on Rails
Tags
TDD ,
RSpec ,
Rails ,
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

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.

Beauty Is in the Eye of the Beholder

Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.

Architecting Visa for Massive Scale and Continuous Innovation

John Davies examines Visa’s architecture and shows how enterprises have architected complex integrations incorporating Hadoop, memcached, Ruby on Rails, and others to deliver innovative solutions.