look_like 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +99 -23
- data/lib/look_like.rb +1 -1
- data/lib/look_like/array-matcher.rb +0 -4
- data/lib/look_like/matchers/{formatted-amount.rb → amount.rb} +1 -1
- data/lib/look_like/matchers/formatted-number.rb +4 -2
- data/lib/look_like/nested-array-matcher.rb +1 -1
- data/lib/look_like/support.rb +12 -0
- data/lib/look_like/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 24455b0329770ab18e13367054b6636b24a821dd
|
|
4
|
+
data.tar.gz: 1677f5e906454dd63cdb82fe5bcf49db4aad23c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dce5a57a541b600e86a9086b487815230e5b89a3c13e3198f76435513452642ec3be06dceb32be288ec2fa73bb32363e4e222bd698c5a270b8b0e363c940aa3b
|
|
7
|
+
data.tar.gz: 3f654ac86eac4e9997170723969e6f4fbc13c42fd540287216d1fe9a3b41a318f59459050d83d58c1926913bae5069119bf6b0ea652f0ee4b8f76fb9fa296116
|
data/README.md
CHANGED
|
@@ -6,62 +6,138 @@
|
|
|
6
6
|
- These can reuse your code for regression tests.
|
|
7
7
|
- Meaningful assertion reports help in quick diagnosis of faults.
|
|
8
8
|
- For example you can write test for fresh deployments to make sure the currency and language are correct by domain/user.
|
|
9
|
+
- [Try online] (http://amoeba.social/lab/try-look-like/)
|
|
9
10
|
|
|
10
11
|
## Installation
|
|
11
12
|
|
|
12
|
-
Add this line to your application's Gemfile:
|
|
13
|
-
|
|
13
|
+
- Add this line to your application's Gemfile:
|
|
14
14
|
```ruby
|
|
15
15
|
gem 'look_like'
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
- To your spec_helper/test_helper or env.rb for cucumber, add following :
|
|
19
|
+
```ruby
|
|
20
|
+
require "look_like"
|
|
21
|
+
```
|
|
19
22
|
|
|
23
|
+
|
|
24
|
+
- And then execute:
|
|
20
25
|
```bash
|
|
21
26
|
$ bundle install
|
|
22
27
|
```
|
|
23
28
|
|
|
24
29
|
## Usage
|
|
25
30
|
```ruby
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
rows = [ ["one@two.xyz", "₹300,20", "yes"],
|
|
32
|
+
["two@three.com", "₹301,20", "no" ],
|
|
33
|
+
["one@two.xyz", "₹121,20", "" ]]
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
# expected "Sam" (one word),
|
|
32
|
-
# to look like "Sam Dam" (two words)
|
|
35
|
+
matchers = [["email", "₹amount", "yes/no*"]]
|
|
33
36
|
|
|
37
|
+
expect(rows).to look_like(matchers)
|
|
34
38
|
```
|
|
39
|
+
|
|
40
|
+
[Try matchers in browser here](http://amoeba.social/lab/try-look-like/)
|
|
35
41
|
## Custom Matchers
|
|
36
42
|
```ruby
|
|
37
43
|
|
|
38
44
|
LookLike::Matchers.define({
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
:name => :my_custom_matcher,
|
|
46
|
+
:desc => "my custom matcher",
|
|
47
|
+
:select => lambda{|expected|
|
|
48
|
+
# return true if this matcher must be used for given expectation.
|
|
49
|
+
},
|
|
50
|
+
:match => lambda{|actual, expected|
|
|
51
|
+
# return true if actual matches expected
|
|
52
|
+
}
|
|
53
|
+
})
|
|
44
54
|
```
|
|
55
|
+
[Examples for defining matchers] (https://github.com/nishants/look_like/tree/master/lib/look_like/matchers).
|
|
56
|
+
|
|
45
57
|
|
|
58
|
+
## Writing Wireframe Tests with Cucumber
|
|
59
|
+
- Suppose this is how an html table look like :
|
|
46
60
|
|
|
47
|
-
|
|
48
|
-
|
|
61
|
+
| Name | Email | Commission | Enrolled | HomePage |
|
|
62
|
+
|------------|---------------|------------|----------|-----------------------------------------------|
|
|
63
|
+
| User One | user1@abc.com | $5,008.00 | yes | https://www.facebook.com/profile.php?id=76273 |
|
|
64
|
+
| User Two | user2@abc.com | $493.00 | no | |
|
|
65
|
+
| User Three | user3@abc.com | $8.00 | yes | https://www.facebook.com/profile.php?id=76273 |
|
|
66
|
+
|
|
67
|
+
- In your feature file, define the table rows
|
|
49
68
|
```gherkin
|
|
50
69
|
Scenario: View employees detail table
|
|
51
70
|
Given I am an admin
|
|
52
71
|
Then I should see employees table like
|
|
53
|
-
|
|
|
54
|
-
|Magan |Sharma | $200,00 |a@b.com|
|
|
72
|
+
|name |email | $amount | yes/no | url* |
|
|
55
73
|
```
|
|
56
74
|
|
|
57
|
-
In your steps, get table rows as array of array
|
|
75
|
+
- In your steps, get table rows as array of array
|
|
58
76
|
```ruby
|
|
59
|
-
Then(/^I should see employees table like
|
|
60
|
-
|
|
61
|
-
expect(
|
|
77
|
+
Then(/^I should see employees table like$/) do |definition|
|
|
78
|
+
rows = homepage.open.employee_table_rows
|
|
79
|
+
expect(rows).to look_like(definition.rows)
|
|
62
80
|
end
|
|
63
81
|
```
|
|
64
82
|
|
|
83
|
+
## List of Matchers
|
|
84
|
+
- [**Email**] (http://amoeba.social/lab/try-look-like/#/Email)
|
|
85
|
+
```ruby
|
|
86
|
+
expect("one@two.xyz").to look_like("email")
|
|
87
|
+
expect("one@two.xyz").to look_like("a@b.com")
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- [**Amount and Currency**](http://amoeba.social/lab/try-look-like/#/Amount%20and%20Currency)
|
|
91
|
+
```ruby
|
|
92
|
+
expect("$53,23,1").to look_like("$amount")
|
|
93
|
+
expect("₹23,1.00").to look_like("₹amount")
|
|
94
|
+
|
|
95
|
+
expect("$53,23,1").to look_like("$12.21")
|
|
96
|
+
expect("₹23,1.00").to look_like("₹100.12")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
- [**Enums**](http://amoeba.social/lab/try-look-like/#/Enums)
|
|
100
|
+
```ruby
|
|
101
|
+
expect("one").to look_like("one/two/three")
|
|
102
|
+
expect("four").not_to look_like("one/two/three")
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
- [**Regex**](http://amoeba.social/lab/try-look-like/#/Regex)
|
|
106
|
+
```ruby
|
|
107
|
+
expect("i have test").to look_like("/test/")
|
|
108
|
+
expect("i have tess").not_to look_like("/test/")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- [**URL**](http://amoeba.social/lab/try-look-like/#/URL)
|
|
112
|
+
```ruby
|
|
113
|
+
expect("google.com").to look_like("http://google.com")
|
|
114
|
+
expect("http://google.com").to look_like("http://google.com")
|
|
115
|
+
expect("google-com").not_to look_like("http://google.com")
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
- [**Wildcard**](http://amoeba.social/lab/try-look-like/#/Wildcard)
|
|
119
|
+
```ruby
|
|
120
|
+
expect("").to look_like("email*")
|
|
121
|
+
expect("not.an.email").not_to look_like("email*")
|
|
122
|
+
expect("one@two.xyz").to look_like("email*")
|
|
123
|
+
|
|
124
|
+
expect("one@two.xyz").to look_like("a@b.com*")
|
|
125
|
+
|
|
126
|
+
expect("").to look_like("*")
|
|
127
|
+
expect("any-thing").to look_like("*")
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
- [**Numbers**](http://amoeba.social/lab/try-look-like/#/Numbers)
|
|
131
|
+
```ruby
|
|
132
|
+
expect("5000").to look_like("number")
|
|
133
|
+
expect("5,000").to look_like("number")
|
|
134
|
+
expect("5,43.11").to look_like("number")
|
|
135
|
+
|
|
136
|
+
expect("6993").to look_like("5000")
|
|
137
|
+
expect("5000").to look_like("5,000")
|
|
138
|
+
expect("$5000").not_to look_like("5000")
|
|
139
|
+
```
|
|
140
|
+
|
|
65
141
|
## Development
|
|
66
142
|
- After checking out the repo, run `bin/setup` to install dependencies.
|
|
67
143
|
- Then, run `rake spec` to run the tests.
|
|
@@ -70,7 +146,7 @@ end
|
|
|
70
146
|
- To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`
|
|
71
147
|
- 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).
|
|
72
148
|
- Build report : https://travis-ci.org/nishants/look_like
|
|
73
|
-
- Coverage
|
|
149
|
+
- Coverage report : https://coveralls.io/github/nishants/look_like
|
|
74
150
|
|
|
75
151
|
## Contributing
|
|
76
152
|
- Report bugs or suggest improvements at https://github.com/nishants/look_like/issues.
|
data/lib/look_like.rb
CHANGED
|
@@ -13,6 +13,6 @@ require "look_like/matchers/enum"
|
|
|
13
13
|
require "look_like/matchers/url"
|
|
14
14
|
require "look_like/matchers/regex"
|
|
15
15
|
require "look_like/matchers/formatted-number"
|
|
16
|
-
require "look_like/matchers/
|
|
16
|
+
require "look_like/matchers/amount"
|
|
17
17
|
require "look_like/matchers/number"
|
|
18
18
|
|
|
@@ -33,10 +33,6 @@ module LookLike
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def error(actual_array, expected_array)
|
|
36
|
-
array_error(actual_array, expected_array)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def array_error(actual_array, expected_array)
|
|
40
36
|
message = []
|
|
41
37
|
if (expected_array.length > actual_array.length)
|
|
42
38
|
message.push("Expected #{ expected_array.length } elements, but found #{actual_array.length}.")
|
|
@@ -3,7 +3,7 @@ LookLike::Matchers.define(
|
|
|
3
3
|
:name => :amount,
|
|
4
4
|
:desc => "amount",
|
|
5
5
|
:select => lambda{|expected|
|
|
6
|
-
expected.end_with?("amount") || LookLike::Support.amount?(expected)
|
|
6
|
+
expected.end_with?("amount") || LookLike::Support.amount?(expected) || LookLike::Support.amount_def?(expected)
|
|
7
7
|
},
|
|
8
8
|
:match => lambda{|actual, expected|
|
|
9
9
|
currency = LookLike::Support.currency_of(expected)
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
format = /^[\d
|
|
1
|
+
format = /^[\d,.]+\d$/
|
|
2
2
|
LookLike::Matchers.define(
|
|
3
3
|
{
|
|
4
4
|
:name => :fomatted_number,
|
|
5
5
|
:desc => "formatted number",
|
|
6
|
-
:select => lambda{|expected|
|
|
6
|
+
:select => lambda{|expected|
|
|
7
|
+
expected == "number" || format === expected
|
|
8
|
+
},
|
|
7
9
|
:match => lambda{|actual| format === actual }
|
|
8
10
|
})
|
|
@@ -17,7 +17,7 @@ module LookLike
|
|
|
17
17
|
message = []
|
|
18
18
|
expected_array = expected[0]
|
|
19
19
|
actual.each { |actual_array|
|
|
20
|
-
message.push(match_array(actual_array, expected_array) ? "✓" : "x [#{
|
|
20
|
+
message.push(match_array(actual_array, expected_array) ? "✓" : "x [#{super(actual_array, expected_array)}]")
|
|
21
21
|
}
|
|
22
22
|
"[#{message.join(", ")}]"
|
|
23
23
|
end
|
data/lib/look_like/support.rb
CHANGED
|
@@ -6,11 +6,19 @@ module LookLike
|
|
|
6
6
|
!!(string =~ /\A#{URI::regexp}\z/)
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
def self.amount_def?(string)
|
|
10
|
+
rounded = string.sub(".", ",").strip
|
|
11
|
+
/^\$[\s]*[\d,]+\d$/ === rounded
|
|
12
|
+
end
|
|
9
13
|
def self.amount?(string)
|
|
10
14
|
rounded = string.sub(".", ",").strip
|
|
11
15
|
/^\$[\s]*[\d,]+\d$/ === rounded
|
|
12
16
|
end
|
|
13
17
|
|
|
18
|
+
def self.normalize_currency(amount)
|
|
19
|
+
(amount.nil? || amount.empty?) ? "" : amount.sub(currency_of(amount), "$")
|
|
20
|
+
end
|
|
21
|
+
|
|
14
22
|
def self.enum?(string)
|
|
15
23
|
/^[^\/]+[\/][^\/]/ === string
|
|
16
24
|
end
|
|
@@ -34,5 +42,9 @@ module LookLike
|
|
|
34
42
|
string.include?("@") && !string.include?("/") && loose_url?(string)
|
|
35
43
|
end
|
|
36
44
|
|
|
45
|
+
def self.amount_def?(expected)
|
|
46
|
+
amount?(expected.sub(/^[^\d]+/, "$"))
|
|
47
|
+
end
|
|
48
|
+
|
|
37
49
|
end
|
|
38
50
|
end
|
data/lib/look_like/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: look_like
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- nishant
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-10-
|
|
11
|
+
date: 2016-10-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -74,10 +74,10 @@ files:
|
|
|
74
74
|
- lib/look_like/array-matcher.rb
|
|
75
75
|
- lib/look_like/matcher.rb
|
|
76
76
|
- lib/look_like/matchers.rb
|
|
77
|
+
- lib/look_like/matchers/amount.rb
|
|
77
78
|
- lib/look_like/matchers/any-value.rb
|
|
78
79
|
- lib/look_like/matchers/email.rb
|
|
79
80
|
- lib/look_like/matchers/enum.rb
|
|
80
|
-
- lib/look_like/matchers/formatted-amount.rb
|
|
81
81
|
- lib/look_like/matchers/formatted-number.rb
|
|
82
82
|
- lib/look_like/matchers/number.rb
|
|
83
83
|
- lib/look_like/matchers/regex.rb
|