File tree 6 files changed +55
-51
lines changed
6 files changed +55
-51
lines changed Original file line number Diff line number Diff line change @@ -7,13 +7,14 @@ rspec-uuid
7
7
An RSpec matcher for UUIDs.
8
8
9
9
``` ruby
10
- require " rspec- uuid"
10
+ require " rspec/ uuid"
11
11
12
12
13
13
it { is_expected.to be_a_uuid }
14
14
15
15
# check the version
16
16
it { is_expected.to be_a_uuid(version: 4 ) }
17
+ it { is_expected.to be_a_uuid.of_version(4 ) }
17
18
18
19
# compose with other matchers
19
20
it { expect(data).to include (uuid: a_uuid) }
Original file line number Diff line number Diff line change 1
- require "rspec/expectations"
2
-
3
- RSpec ::Matchers . define :be_a_uuid do |version : nil |
4
- match do |actual |
5
- raise ArgumentError if @version && version
6
-
7
- return false unless actual . is_a? ( String )
8
-
9
- # https://www.uuidtools.com/what-is-uuid
10
- matches = actual . match /^\h {8}-\h {4}-(\h {4})-\h {4}-\h {12}$/
11
- return false unless matches
12
-
13
- version ||= @version
14
- if version
15
- # 1st nibble of 3rd section
16
- @actual_version = matches [ 1 ] . to_i ( 16 ) >> 12
17
-
18
- version == @actual_version
19
- else
20
- true
21
- end
22
- end
23
-
24
- chain :of_version do |version |
25
- @version = version
26
- end
27
-
28
- description do
29
- version ? "a UUID v#{ version } " : "a UUID"
30
- end
31
-
32
- failure_message do
33
- if @actual_version
34
- "expected #{ description } , found a UUID v#{ @actual_version } "
35
- else
36
- "expected #{ description } "
37
- end
38
- end
39
-
40
- failure_message_when_negated do
41
- "did not expect #{ description } "
42
- end
43
- end
44
-
45
- RSpec ::Matchers . alias_matcher :a_uuid , :be_a_uuid
1
+ require "rspec/uuid"
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ require "rspec/expectations"
2
+
3
+ RSpec ::Matchers . define :be_a_uuid do |version : nil |
4
+ match do |actual |
5
+ raise ArgumentError if @version && version
6
+
7
+ return false unless actual . is_a? ( String )
8
+
9
+ # https://www.uuidtools.com/what-is-uuid
10
+ matches = actual . match /^\h {8}-\h {4}-(\h {4})-\h {4}-\h {12}$/
11
+ return false unless matches
12
+
13
+ version ||= @version
14
+ if version
15
+ # 1st nibble of 3rd section
16
+ @actual_version = matches [ 1 ] . to_i ( 16 ) >> 12
17
+
18
+ version == @actual_version
19
+ else
20
+ true
21
+ end
22
+ end
23
+
24
+ chain :of_version do |version |
25
+ @version = version
26
+ end
27
+
28
+ description do
29
+ version ? "a UUID v#{ version } " : "a UUID"
30
+ end
31
+
32
+ failure_message do
33
+ if @actual_version
34
+ "expected #{ description } , found a UUID v#{ @actual_version } "
35
+ else
36
+ "expected #{ description } "
37
+ end
38
+ end
39
+
40
+ failure_message_when_negated do
41
+ "did not expect #{ description } "
42
+ end
43
+ end
44
+
45
+ RSpec ::Matchers . alias_matcher :a_uuid , :be_a_uuid
Original file line number Diff line number Diff line change
1
+ module RSpec
2
+ module UUID
3
+ VERSION = "0.4.0"
4
+ end
5
+ end
Original file line number Diff line number Diff line change 1
1
package_name = File . basename ( __FILE__ ) . split ( "." ) [ 0 ]
2
- require File . expand_path ( "lib/#{ package_name } /version" , __dir__ )
2
+ load Dir . glob ( "lib/** /version.rb" ) [ 0 ]
3
3
4
- package = RSpecUUID
4
+ package = RSpec :: UUID
5
5
6
6
7
7
Gem ::Specification . new do |s |
You can’t perform that action at this time.
0 commit comments