rspec-match_ruby

It is Ruby code matcher.

Gem Version Build Status

Installation

Add this line to your application's Gemfile:

gem 'rspec-match_ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rspec-match_ruby

Usage

require 'rspec/match_ruby'

RSpec.describe do
  specify do
    code1 = "      create_table :products, id: true, force: :cascade do |t|\n        t.string :name, null: false, limit: 4\n        t.text :description\n\n        t.timestamps\n      end\n    EOS\n\n    code2 = <<-EOS\n      create_table :products, force: :cascade, id: true do |t|\n        t.string :name, limit: 4, null: true\n        t.text :description\n        # Comment\n        t.timestamps\n      end\n    EOS\n\n    expect(code1).to match_ruby code2\n    #=> Failure/Error: expect(code1).to match_ruby code2\n    #     expected: \"create_table :products, force: :cascade, id: true do |t|\\nt.string :name, limit: 4, null: true\\nt.text :description\\n# Comment\\nt.timestamps\\nend\"\n    #          got: \"create_table :products, id: true, force: :cascade do |t|\\nt.string :name, null: false, limit: 4\\nt.text :description\\nt.timestamps\\nend\"\n    #\n    #     Diff:\n    #\n    #     @@ -1,7 +1,6 @@\n    #     -create_table :products, force: :cascade, id: true do |t|\n    #     -t.string :name, limit: 4, null: true\n    #     +create_table :products, id: true, force: :cascade do |t|\n    #     +t.string :name, null: false, limit: 4\n    #      t.text :description\n    #     -# Comment\n    #      t.timestamps\n    #      end\n    #\n    #     @@ -14,7 +14,7 @@\n    #         [:sym, :name],\n    #         [:hash,\n    #          [:pair, [:sym, :limit], [:int, 4]],\n    #     -    [:pair, [:sym, :null], [:true]]]],\n    #     +    [:pair, [:sym, :null], [:false]]]],\n    #        [:send, [:lvar, :t], :text, [:sym, :description]],\n    #        [:send, [:lvar, :t], :timestamps]]]\n  end\nend\n"