tarka_matchers 0.0.53

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.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +4 -0
  6. data/README.md +39 -0
  7. data/Rakefile +2 -0
  8. data/bin/console +7 -0
  9. data/bin/setup +5 -0
  10. data/bin/tarka_matchers +14 -0
  11. data/lib/tarka_matchers/action_dispatch_matchers.rb +5 -0
  12. data/lib/tarka_matchers/class_matchers.rb +5 -0
  13. data/lib/tarka_matchers/commands/calibrate.rb +57 -0
  14. data/lib/tarka_matchers/commands/install.rb +50 -0
  15. data/lib/tarka_matchers/expectation_matchers.rb +10 -0
  16. data/lib/tarka_matchers/formatters/difference.rb +41 -0
  17. data/lib/tarka_matchers/formatters/selected.rb +29 -0
  18. data/lib/tarka_matchers/formatters/styles.rb +15 -0
  19. data/lib/tarka_matchers/helpers/expectation/common.rb +25 -0
  20. data/lib/tarka_matchers/helpers/expectation/expect_capture.rb +53 -0
  21. data/lib/tarka_matchers/helpers/expectation/result.rb +16 -0
  22. data/lib/tarka_matchers/helpers/rails/action_dispatch/route_populator.rb +28 -0
  23. data/lib/tarka_matchers/helpers/string/sgr/sgr_codes.rb +127 -0
  24. data/lib/tarka_matchers/helpers/string/sgr/sgr_sequences/xterm.txt +108 -0
  25. data/lib/tarka_matchers/helpers/string/sgr/styled_capture.rb +28 -0
  26. data/lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb +39 -0
  27. data/lib/tarka_matchers/matchers/expectation/fail.rb +35 -0
  28. data/lib/tarka_matchers/matchers/expectation/have_a_description_of.rb +43 -0
  29. data/lib/tarka_matchers/matchers/expectation/have_a_failure_message_of.rb +41 -0
  30. data/lib/tarka_matchers/matchers/expectation/have_a_failure_message_when_negated_of.rb +41 -0
  31. data/lib/tarka_matchers/matchers/expectation/pass.rb +35 -0
  32. data/lib/tarka_matchers/matchers/expectation/support_block_expectations.rb +45 -0
  33. data/lib/tarka_matchers/matchers/rails/action_dispatch/be_named_as.rb +19 -0
  34. data/lib/tarka_matchers/matchers/regex/match_sections.rb +84 -0
  35. data/lib/tarka_matchers/matchers/string/sgr/be_red.rb +15 -0
  36. data/lib/tarka_matchers/rails_matchers.rb +1 -0
  37. data/lib/tarka_matchers/regex_matchers.rb +5 -0
  38. data/lib/tarka_matchers/ruby_matchers.rb +3 -0
  39. data/lib/tarka_matchers/sgr_matchers.rb +5 -0
  40. data/lib/tarka_matchers/version.rb +3 -0
  41. data/lib/tarka_matchers.rb +3 -0
  42. data/tarka_matchers.gemspec +35 -0
  43. metadata +200 -0
@@ -0,0 +1,35 @@
1
+ require 'tarka_matchers/helpers/expectation/result'
2
+ module TarkaMatchers
3
+ module Matchers
4
+ module Expectation
5
+ def pass
6
+ Pass.new
7
+ end
8
+
9
+ class Pass
10
+ def supports_block_expectations?; true; end
11
+
12
+ def matches? expectation
13
+ @actual = TarkaMatchers::Helpers::Expectation::Result.pass?{ expectation.call }
14
+ @actual == true
15
+ end
16
+
17
+ def description
18
+ "pass."
19
+ end
20
+
21
+ def report
22
+ "Spec result: #{@actual}"
23
+ end
24
+
25
+ def failure_message
26
+ "#{description} #{report}"
27
+ end
28
+
29
+ def failure_message_when_negated
30
+ "#{description} #{report}"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,45 @@
1
+ require 'tarka_matchers/helpers/expectation/expect_capture'
2
+ module TarkaMatchers
3
+ module Matchers
4
+ module Expectation
5
+ def support_block_expectations
6
+ SupportBlockExpectations.new
7
+ end
8
+
9
+ class SupportBlockExpectations
10
+ def supports_block_expectations?
11
+ true
12
+ end
13
+
14
+ def matches? actual
15
+ @actual_matcher = TarkaMatchers::Helpers::Expectation::ExpectCapture.capture(actual)[1]
16
+ @exist = true
17
+ begin
18
+ @actual = @actual_matcher.supports_block_expectations?
19
+ rescue NoMethodError
20
+ @exist = false
21
+ end
22
+ @actual == true
23
+ end
24
+
25
+ def description
26
+ "utilize a matcher, '#{@actual_matcher.class}', that supports block expectations."
27
+ end
28
+
29
+ def report
30
+ message = "Expected the matcher, '#{@actual_matcher.class}', to contain the method supports_block_expectations? method and for it to return 'true'. "
31
+ @exist ? message << "Instead it returned '#{@actual}'." : message << "The supports_block_expectations? method does not exist inside the matcher. (Hint: check spelling)"
32
+ message
33
+ end
34
+
35
+ def failure_message
36
+ "failed to #{description} #{report}"
37
+ end
38
+
39
+ def failure_message_when_negated
40
+ "#{description} #{report}"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,19 @@
1
+ module TarkaMatchers
2
+ module Matchers
3
+ module ActionDispatch
4
+ def be_named_as expected
5
+ BeNamedAs.new expected
6
+ end
7
+
8
+ class BeNamedAs
9
+ def initialize expected
10
+ @expected = expected
11
+ end
12
+
13
+ def description
14
+ "be named as #{@expected}"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,84 @@
1
+ require 'tarka_matchers/helpers/string/sgr/styled_capture'
2
+ require 'tarka_matchers/formatters/selected'
3
+ module TarkaMatchers
4
+ module Matchers
5
+ module Regex
6
+ def match_sections *expected
7
+ MatchSections.new expected
8
+ end
9
+
10
+ class MatchSections
11
+ attr_reader :failure_message,:description
12
+ def initialize expected
13
+ @expected = expected
14
+ end
15
+
16
+ def when_used_on string
17
+ @string = string
18
+ self
19
+ end
20
+
21
+ def matches? actual
22
+ @actual = actual
23
+ integers = @expected.all?{ |v| v.is_a?(Integer) }
24
+ strings = @expected.all?{ |v| v.is_a?(String) }
25
+
26
+ if integers || strings
27
+ @matches = indexes = Helpers::SGR::StyledCapture.indexes_of(@string, @actual)
28
+ pass_with_message
29
+ fail_with_message
30
+ if indexes.empty?
31
+ fail_with_message
32
+ else
33
+ if strings
34
+ extracts = @matches.map{ |v| v[1] }.flatten
35
+ pass_with_message
36
+ else
37
+ indexes = @matches.map{ |v| [v[0], v[2]] }.flatten
38
+ if @expected.count.odd?
39
+ fail_with_message "The indexes provided, '#{@expected}', are of an odd number. Please provide the start and end index pairs of all sections of '#{@string}' that should be selected by '#{@actual}'."
40
+ elsif @expected.count < indexes.count
41
+ fail_with_message "The index pairs provided, '#{@expected}', are less than the number of matches found in the string. Please provide the start and end index pairs of all sections of '#{@string}' that should be selected by '#{@actual}'."
42
+ elsif @expected.count > indexes.count
43
+ fail_with_message "The index pairs provided, '#{@expected}', are more than the number of matches found in the string. Please provide the start and end index pairs of all sections of '#{@string}' that should be selected by '#{@actual}'."
44
+ elsif @expected == indexes
45
+ pass_with_message
46
+ else
47
+ fail_with_message
48
+ end
49
+ end
50
+ end
51
+ else
52
+ fail_with_message "Provided a wrongly formatted argument to 'match_sections'. 'match_sections' expects an argument sequence consisting exclusively of either the start and end indexes of all expected sections of the provided string selected by the match, or an example of the actual text that is selected."
53
+ end
54
+ end
55
+
56
+ def pass_with_message message="contain the pattern, '#{@actual}' at positions #{indexes_list}."
57
+ @description = message
58
+ true
59
+ end
60
+
61
+ def fail_with_message message="The string, '#{@string}', does not contain the pattern, '#{@actual}':#{TarkaMatchers::Formatters::Selected.selected(@string, @matches.map{ |v| [v[0], v[2]] }.flatten)}"
62
+ @failure_message = message
63
+ false
64
+ end
65
+
66
+ def indexes_list
67
+ list = ''
68
+ li = @expected.length
69
+ @expected.each_with_index do |v,i|
70
+ if i.even?
71
+ divider = ' to '
72
+ elsif i == li - 3
73
+ divider = ' and '
74
+ elsif i != li - 1
75
+ divider = ','
76
+ end
77
+ list << "'#{v}'#{divider}"
78
+ end
79
+ list
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,15 @@
1
+ module TarkaMatchers
2
+ module Matchers
3
+ module SGR
4
+ def be_red
5
+ BeNamedAs.new
6
+ end
7
+
8
+ class Red
9
+ def description
10
+ "be named as #{@expected}"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1 @@
1
+ require 'tarka_matchers/action_dispatch_matchers'
@@ -0,0 +1,5 @@
1
+ require 'tarka_matchers/matchers/regex/match_sections'
2
+
3
+ class Object
4
+ include TarkaMatchers::Matchers::Regex
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'tarka_matchers/expectation_matchers'
2
+ require 'tarka_matchers/class_matchers'
3
+ require 'tarka_matchers/regex_matchers'
@@ -0,0 +1,5 @@
1
+ require 'tarka_matchers/matchers/string/sgr/be_red'
2
+
3
+ class Object
4
+ include TarkaMatchers::Matchers::SGR
5
+ end
@@ -0,0 +1,3 @@
1
+ module TarkaMatchers
2
+ VERSION = '0.0.53'
3
+ end
@@ -0,0 +1,3 @@
1
+ require "tarka_matchers/version"
2
+ require "tarka_matchers/ruby_matchers"
3
+ require "tarka_matchers/rails_matchers"
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tarka_matchers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tarka_matchers"
8
+ spec.version = TarkaMatchers::VERSION
9
+ spec.authors = ["jaytarka"]
10
+ spec.email = ["jaytarka@hotmail.com"]
11
+
12
+ if spec.respond_to?(:metadata)
13
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
14
+ end
15
+
16
+ spec.summary = 'A set of rspec matchers'
17
+ spec.description = 'A (very) small set of rspec matchers that make it easier to write one-liner isolated routing specs. I hope to add many more routes in the future.'
18
+ spec.homepage = 'https://github.com/jaytarka/tarka_matchers'
19
+ spec.license = 'MIT'
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject{ |f| f.match(%r{^(spec)/}) }
22
+ spec.bindir = 'bin'
23
+ spec.executables = ['tarka_matchers']
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_dependency 'pry'
27
+ spec.add_dependency 'ruby-terminfo'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.8'
30
+ spec.add_development_dependency 'awesome_print'
31
+ spec.add_development_dependency 'the_great_escape'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rspec-given'
34
+ spec.add_development_dependency 'faker'
35
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tarka_matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.53
5
+ platform: ruby
6
+ authors:
7
+ - jaytarka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-terminfo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: awesome_print
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: the_great_escape
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-given
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: faker
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: A (very) small set of rspec matchers that make it easier to write one-liner
126
+ isolated routing specs. I hope to add many more routes in the future.
127
+ email:
128
+ - jaytarka@hotmail.com
129
+ executables:
130
+ - tarka_matchers
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - ".rspec"
136
+ - ".travis.yml"
137
+ - Gemfile
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - bin/tarka_matchers
143
+ - lib/tarka_matchers.rb
144
+ - lib/tarka_matchers/action_dispatch_matchers.rb
145
+ - lib/tarka_matchers/class_matchers.rb
146
+ - lib/tarka_matchers/commands/calibrate.rb
147
+ - lib/tarka_matchers/commands/install.rb
148
+ - lib/tarka_matchers/expectation_matchers.rb
149
+ - lib/tarka_matchers/formatters/difference.rb
150
+ - lib/tarka_matchers/formatters/selected.rb
151
+ - lib/tarka_matchers/formatters/styles.rb
152
+ - lib/tarka_matchers/helpers/expectation/common.rb
153
+ - lib/tarka_matchers/helpers/expectation/expect_capture.rb
154
+ - lib/tarka_matchers/helpers/expectation/result.rb
155
+ - lib/tarka_matchers/helpers/rails/action_dispatch/route_populator.rb
156
+ - lib/tarka_matchers/helpers/string/sgr/sgr_codes.rb
157
+ - lib/tarka_matchers/helpers/string/sgr/sgr_sequences/xterm.txt
158
+ - lib/tarka_matchers/helpers/string/sgr/styled_capture.rb
159
+ - lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb
160
+ - lib/tarka_matchers/matchers/expectation/fail.rb
161
+ - lib/tarka_matchers/matchers/expectation/have_a_description_of.rb
162
+ - lib/tarka_matchers/matchers/expectation/have_a_failure_message_of.rb
163
+ - lib/tarka_matchers/matchers/expectation/have_a_failure_message_when_negated_of.rb
164
+ - lib/tarka_matchers/matchers/expectation/pass.rb
165
+ - lib/tarka_matchers/matchers/expectation/support_block_expectations.rb
166
+ - lib/tarka_matchers/matchers/rails/action_dispatch/be_named_as.rb
167
+ - lib/tarka_matchers/matchers/regex/match_sections.rb
168
+ - lib/tarka_matchers/matchers/string/sgr/be_red.rb
169
+ - lib/tarka_matchers/rails_matchers.rb
170
+ - lib/tarka_matchers/regex_matchers.rb
171
+ - lib/tarka_matchers/ruby_matchers.rb
172
+ - lib/tarka_matchers/sgr_matchers.rb
173
+ - lib/tarka_matchers/version.rb
174
+ - tarka_matchers.gemspec
175
+ homepage: https://github.com/jaytarka/tarka_matchers
176
+ licenses:
177
+ - MIT
178
+ metadata:
179
+ allowed_push_host: https://rubygems.org
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 2.4.6
197
+ signing_key:
198
+ specification_version: 4
199
+ summary: A set of rspec matchers
200
+ test_files: []