look_like matcher Build Status Coverage Status Gem Version

  • This gem is a collection of rspec matchers, for writing wireframe tests.
  • Such tests search for visual clues for detecting presence of a bug.
  • Useful for writing sanity tests in higher environments, e.g. testing your fresh deploy to production.
  • These can reuse your code for regression tests.
  • Meaningful assertion reports help in quick diagnosis of faults.
  • For example you can write test for fresh deployments to make sure the currency and language are correct by domain/user.
  • Try online

Installation

  • Add this line to your application's Gemfile:

    gem 'look_like'
    
  • To your spec_helper/test_helper or env.rb for cucumber, add following :

    require "look_like"
    
  • And then execute:

    $ bundle install
    

Usage

actual   = [["[email protected]"  ,  "₹300,20", "yes"],
            ["[email protected]",  "₹301,20", "no" ],
            ["[email protected]"  ,  "₹121,20", ""   ]]

expected = [["email", "₹amount", "yes/no*"]]

expect(actual).to look_like(expected)  

Try online here

Custom Matchers


LookLike::Matchers.define({
  :name     => :my_custom_matcher,
  :desc     => "my custom matcher",
  :select   => lambda{|expected|
     # return true if this matcher must be used for given expectation.
  },
  :match    => lambda{|actual, expected|
     # return true if actual matches expected
  } 
})

Examples for defining matchers.

Writing Wireframe Tests with Cucumber

  • Suppose this is how an html table look like :
Name Email Commission Enrolled HomePage
User One [email protected] $5,008.00 yes https://www.facebook.com/profile.php?id=76273
User Two [email protected] $493.00 no
User Three [email protected] $8.00 yes https://www.facebook.com/profile.php?id=76273
  • In your feature file, define the table rows

    Scenario: View employees detail table
    Given I am an admin
    Then  I should see employees table like
        |name      |email     |  $amount  | yes/no | url* |
    
  • In your steps, get table rows as array of array

    Then(/^I should see employees table like$/) do |definition|
    rows = homepage.open.employee_table_rows
    expect(rows).to look_like(definition.rows)
    end
    

List of Matchers

expect("$53,23,1").to look_like("$12.21") expect("₹23,1.00").to look_like("₹100.12")


- [**Enums**](http://amoeba.social/lab/try-look-like/#/Enums)
```ruby
expect("one").to look_like("one/two/three")
expect("four").not_to look_like("one/two/three")
  • Regex

    expect("i have  test").to look_like("/test/")
    expect("i have  tess").not_to look_like("/test/")
    
  • URL

    expect("google.com").to look_like("http://google.com")
    expect("http://google.com").to look_like("http://google.com")
    expect("google-com").not_to look_like("http://google.com")
    
  • Wildcard

    expect("").to look_like("email*")
    expect("not.an.email").not_to look_like("email*")
    expect("[email protected]").to look_like("email*")
    

expect("[email protected]").to look_like("[email protected]*")

expect("").to look_like("") expect("any-thing").to look_like("")


- [**Numbers**](http://amoeba.social/lab/try-look-like/#/Numbers)
```ruby
expect("5000").to look_like("number")
expect("5,000").to look_like("number")
expect("5,43.11").to look_like("number")

expect("6993").to look_like("5000")
expect("5000").to look_like("5,000")
expect("$5000").not_to look_like("5000")
  • Date and Time ```ruby expect("12/13/2014").to look_like("date") expect("12/13/2014").to look_like("DD/MM/YYYY") expect("06/21/1987").to look_like("12/13/2014")

expect("1994-11-05T08:15:30-05:00").to look_like("timestamp") expect("2014-12-31 T 11:59:13").to look_like("YYYY-MM-DD T HH:MM:SS") expect("2014-12-31 T 11:59:13").to look_like("YYYY-MM-DD T hh:mm:ss") expect("1994-11-05T08:15:30-05:00").to look_like("1994-11-05T08:15:30-05:00")


- [**Arrays**](http://amoeba.social/lab/try-look-like/index.html#/Arrays)
```ruby
actual   = ["[email protected]",  "₹300,20", ""]
expected = ["email"      , "₹amount" , "*"]
expect(actual).to look_like(expected)

expect(actual).to look_like(expected)



## Development
- After checking out the repo, run `bin/setup` to install dependencies. 
- Then, run `rake spec` to run the tests. 
- You can also run `bin/console` for an interactive prompt that will allow you to experiment.
- To install this gem locally, run `bundle exec rake install`. 
- To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`
- Release task  will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
- Build report : https://travis-ci.org/nishants/look_like
- Coverage report : https://coveralls.io/github/nishants/look_like

## Contributing
- Report bugs or suggest improvements at https://github.com/nishants/look_like/issues.
- Pull requests are highly welcome at at https://github.com/nishants/look_like. 

## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).