tarka_matchers 0.0.53 → 0.0.54

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f94ee7c5c4c8cdcd352e709eceb8c04255ba3b2e
4
- data.tar.gz: fc1bd0779f56e6533d9041afc97a04ba894b84d4
3
+ metadata.gz: 70047a83a548ae7bd61dbd9d87de255dff51f825
4
+ data.tar.gz: 1b1c202a40f6bf8c4108bf579f2ce0c9b0d05483
5
5
  SHA512:
6
- metadata.gz: 78e09d10294d6d0246ca329c175216bc2c36b959e14c3cad418df1e9434749f40e4e960dc546bff206bd1629f2961f292c67d88fa90a6b94aa575f01a80b2a7b
7
- data.tar.gz: aea692bd67bdcd52e582bfdbad2689913c2b5dca320e6069ff93dee2207731ff6e447696160d36507a83d25471d0e3d1bb187b541d83d06663dbbdb6568161e7
6
+ metadata.gz: 27031c8ee5173fe8697dacc17e38a8b909d237f18634f3d60a194addb727e759e1af105542e709e50db33b34e7740cf9cf7e57c8d0d42314516a88edba9d305b
7
+ data.tar.gz: cc4b0e6e0de7ad61db3e2d1971b3ad15314668362608f363b5a55074af74b467865d6abd9b782996abd4bc073934f6213822947c0f31ab0f218b90158b399812
@@ -0,0 +1,2 @@
1
+ require 'tarka_matchers/formatters/difference'
2
+ require 'tarka_matchers/formatters/selected'
@@ -5,6 +5,8 @@ module TarkaMatchers
5
5
  include Styles
6
6
 
7
7
  def self.difference expected, actual
8
+ expected = expected.to_s
9
+ actual = actual.to_s
8
10
  expected_line = "#{GREEN_F}Expected: #{BLACK_ON_GREEN}#{expected}#{RESET}"
9
11
  expected_length = expected.length
10
12
  actual_length = actual.length
@@ -32,7 +34,6 @@ module TarkaMatchers
32
34
  actual_line << "#{BLACK_ON_GREEN}#{a}"
33
35
  end
34
36
  end
35
-
36
37
  identical = ((correct.to_f/longest_length) * 100).round 3
37
38
  "\n\n#{expected_line}#{actual_line}#{RESET}#{RED_F} - #{identical}% identical#{RESET}"
38
39
  end
@@ -4,13 +4,16 @@ module TarkaMatchers
4
4
  class Selected
5
5
  include Styles
6
6
  def self.selected original, selected
7
- indexes = []
8
- selected.each_slice(2){ |si,ei| indexes << (si..ei).to_a }
7
+ indexes, actual_boundaries = [], []
8
+ selected.each_slice(2) do |si,ei|
9
+ indexes << (si..ei).to_a
10
+ actual_boundaries << [si,ei]
11
+ end
9
12
  indexes.flatten!
13
+ actual_boundaries.flatten!
10
14
 
11
15
  original_line = "#{GREEN_F}Original: #{BLACK_ON_GREEN}#{original}#{RESET}"
12
16
  selected_line = "\n#{RESET}#{RED_F}Selected: "
13
-
14
17
  selects = 0
15
18
  original.split('').each_with_index do |v,i|
16
19
  if indexes.include? i
@@ -22,7 +25,7 @@ module TarkaMatchers
22
25
  end
23
26
 
24
27
  matched = ((selects.to_f/original.length) * 100).round 3
25
- "\n\n#{original_line}#{selected_line}#{RESET}#{RED_F} - #{matched}% matched#{RESET}"
28
+ "\n\n#{original_line}#{selected_line}#{RESET}#{RED_F} - #{matched}% matched.\n#{RED_F}Bounds: #{actual_boundaries}\n#{WHITE_F}Formatter: #{self.name}#{RESET}"
26
29
  end
27
30
  end
28
31
  end
@@ -3,6 +3,7 @@ module TarkaMatchers
3
3
  module Styles
4
4
  RED_F = "\e[31m"
5
5
  YELLOW_F = "\e[33m"
6
+ WHITE_F = "\e[37m"
6
7
  GREEN_F = "\e[32m"
7
8
  L_GREEN_F = "\e[92m"
8
9
  RESET = "\e[0m"
@@ -4,15 +4,6 @@ module TarkaMatchers
4
4
  module Common
5
5
  SGR = /\\e\[(?:10[0-7]|0{1,2}\d|0{0,1}\d\d|\d)m/
6
6
  NEWLINE = /\\n/
7
- def keep_sgrs
8
- @keep_sgrs = true
9
- self
10
- end
11
-
12
- def keep_newlines
13
- @keep_newlines = true
14
- self
15
- end
16
7
 
17
8
  def clean! string
18
9
  string.gsub!(SGR,'') unless @keep_sgrs
@@ -0,0 +1,71 @@
1
+ require 'tarka_matchers/formatters'
2
+ module TarkaMatchers
3
+ module Helpers
4
+ module Utility
5
+ attr_reader :description, :failure_message, :failure_message_when_negated
6
+
7
+ def difference expected=@expected, actual=@actual
8
+ TarkaMatchers::Formatters::Difference.difference(expected,actual)
9
+ end
10
+
11
+ def selected expected=@expected, actual=@actual
12
+ TarkaMatchers::Formatters::Selected.selected(expected,actual)
13
+ end
14
+
15
+ def pass_default message='pass'
16
+ @description = message
17
+ negated_default
18
+ fail_default
19
+ end
20
+
21
+ def negated_default message=nil
22
+ @failure_message_when_negated = message || "did #{@description}"
23
+ end
24
+
25
+ def fail_default option=nil
26
+ append, message = nil
27
+
28
+ if option == nil
29
+ append = difference
30
+ elsif option.is_a? String
31
+ message = option
32
+ elsif option.is_a? Hash
33
+ k = option.first[0]
34
+ v = option.first[1]
35
+ case k
36
+ when :append
37
+ if v.is_a? String
38
+ append = v
39
+ elsif v.is_a? Symbol
40
+ case v
41
+ when :difference
42
+ append = difference
43
+ when :selected
44
+ append = selected
45
+ end
46
+ else
47
+ append = difference
48
+ end
49
+ when :just
50
+ message = v
51
+ end
52
+ end
53
+
54
+ @failure_message = message || "failed to #{@description}#{append}"
55
+ end
56
+
57
+ def pass_with_message message=nil
58
+ @description = message if message
59
+ true
60
+ end
61
+
62
+ def fail_with_message message=nil
63
+ @failure_message = message if message
64
+ false
65
+ end
66
+
67
+ alias_method :pass, :pass_with_message
68
+ alias_method :fail, :fail_with_message
69
+ end
70
+ end
71
+ end
@@ -1,4 +1,5 @@
1
1
  require 'tarka_matchers/helpers/expectation/result'
2
+ require 'tarka_matchers/helpers/utility'
2
3
  require 'tarka_matchers/formatters/difference'
3
4
  module TarkaMatchers
4
5
  module Matchers
@@ -7,7 +8,8 @@ module TarkaMatchers
7
8
  HaveAnInstanceVariableOf.new instance_name
8
9
  end
9
10
 
10
- class HaveAnInstanceVariableOf
11
+ class HaveAnInstanceVariableOf
12
+ include TarkaMatchers::Helpers::Utility
11
13
  def initialize instance_name
12
14
  @instance_name = instance_name
13
15
  end
@@ -19,20 +21,12 @@ module TarkaMatchers
19
21
 
20
22
  def matches? actual
21
23
  @actual = actual.instance_variable_get(@instance_name)
24
+ pass_default "contain an instance variable called, '#{@instance_name}', that equals '#{@expected}'."
25
+ negated_default
26
+ fail_default append: "#{TarkaMatchers::Formatters::Difference.difference(@expected,@actual)}"
27
+ fail_with_message "failed to contain an instance variable called '#{@instance_name}'. It does not exist inside the class." unless actual.instance_variable_defined?(@instance_name)
22
28
  @actual == @expected
23
29
  end
24
-
25
- def description
26
- "contain an instance variable called, '#{@instance_name}', that equals '#{@expected}'."
27
- end
28
-
29
- def failure_message
30
- "failed to #{description}\n#{TarkaMatchers::Formatters::Difference.difference(@expected,@actual)}"
31
- end
32
-
33
- def failure_message_when_negated
34
- "did #{description}"
35
- end
36
30
  end
37
31
  end
38
32
  end
@@ -1,4 +1,5 @@
1
1
  require 'tarka_matchers/helpers/string/sgr/styled_capture'
2
+ require 'tarka_matchers/helpers/utility'
2
3
  require 'tarka_matchers/formatters/selected'
3
4
  module TarkaMatchers
4
5
  module Matchers
@@ -8,9 +9,10 @@ module TarkaMatchers
8
9
  end
9
10
 
10
11
  class MatchSections
11
- attr_reader :failure_message,:description
12
+ include TarkaMatchers::Helpers::Utility
12
13
  def initialize expected
13
14
  @expected = expected
15
+ @li = @expected.length
14
16
  end
15
17
 
16
18
  def when_used_on string
@@ -25,53 +27,60 @@ module TarkaMatchers
25
27
 
26
28
  if integers || strings
27
29
  @matches = indexes = Helpers::SGR::StyledCapture.indexes_of(@string, @actual)
28
- pass_with_message
29
- fail_with_message
30
+ pass_default "contain the pattern, '#{@actual}' at positions #{indexes_list}"
31
+ fail_default "The string, '#{@string}', does not contain the pattern, '#{@actual}':#{selected(@string, @matches.map{ |v| [v[0], v[2]] }.flatten)}"
32
+
30
33
  if indexes.empty?
31
34
  fail_with_message
32
35
  else
33
36
  if strings
34
37
  extracts = @matches.map{ |v| v[1] }.flatten
35
- pass_with_message
38
+ if @expected == extracts
39
+ pass_with_message "contain the pattern, '#{@actual}' and match: #{extracts_list}"
40
+ else
41
+ fail
42
+ end
36
43
  else
37
44
  indexes = @matches.map{ |v| [v[0], v[2]] }.flatten
38
45
  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}'."
46
+ 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
47
  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}'."
48
+ 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}':#{selected(@string, @matches.map{ |v| [v[0], v[2]] }.flatten)}"
42
49
  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}'."
50
+ 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}':#{selected(@string, @matches.map{ |v| [v[0], v[2]] }.flatten)}"
44
51
  elsif @expected == indexes
45
- pass_with_message
46
- else
47
- fail_with_message
52
+ pass_with_message "contain the pattern, '#{@actual}' at positions #{indexes_list}"
53
+ elsif @expected != indexes
54
+ fail
48
55
  end
49
56
  end
50
57
  end
51
58
  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."
59
+ 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
60
  end
54
61
  end
55
62
 
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
63
  def indexes_list
67
64
  list = ''
68
- li = @expected.length
69
65
  @expected.each_with_index do |v,i|
70
66
  if i.even?
71
67
  divider = ' to '
72
- elsif i == li - 3
68
+ elsif i == @li - 3
69
+ divider = ' and '
70
+ elsif i != @li - 1
71
+ divider = ','
72
+ end
73
+ list << "'#{v}'#{divider}"
74
+ end
75
+ list
76
+ end
77
+
78
+ def extracts_list
79
+ list = ''
80
+ @expected.each_with_index do |v,i|
81
+ if i == @li - 2
73
82
  divider = ' and '
74
- elsif i != li - 1
83
+ elsif i != @li - 1
75
84
  divider = ','
76
85
  end
77
86
  list << "'#{v}'#{divider}"
File without changes
@@ -0,0 +1 @@
1
+ require 'tarka_matchers/helpers/utility'
@@ -1,3 +1,3 @@
1
1
  module TarkaMatchers
2
- VERSION = '0.0.53'
2
+ VERSION = '0.0.54'
3
3
  end
@@ -30,6 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'awesome_print'
31
31
  spec.add_development_dependency 'the_great_escape'
32
32
  spec.add_development_dependency 'rake', '~> 10.0'
33
- spec.add_development_dependency 'rspec-given'
34
33
  spec.add_development_dependency 'faker'
35
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tarka_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.53
4
+ version: 0.0.54
5
5
  platform: ruby
6
6
  authors:
7
7
  - jaytarka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-01 00:00:00.000000000 Z
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
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
97
  - !ruby/object:Gem::Dependency
112
98
  name: faker
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -146,6 +132,7 @@ files:
146
132
  - lib/tarka_matchers/commands/calibrate.rb
147
133
  - lib/tarka_matchers/commands/install.rb
148
134
  - lib/tarka_matchers/expectation_matchers.rb
135
+ - lib/tarka_matchers/formatters.rb
149
136
  - lib/tarka_matchers/formatters/difference.rb
150
137
  - lib/tarka_matchers/formatters/selected.rb
151
138
  - lib/tarka_matchers/formatters/styles.rb
@@ -156,6 +143,7 @@ files:
156
143
  - lib/tarka_matchers/helpers/string/sgr/sgr_codes.rb
157
144
  - lib/tarka_matchers/helpers/string/sgr/sgr_sequences/xterm.txt
158
145
  - lib/tarka_matchers/helpers/string/sgr/styled_capture.rb
146
+ - lib/tarka_matchers/helpers/utility.rb
159
147
  - lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb
160
148
  - lib/tarka_matchers/matchers/expectation/fail.rb
161
149
  - lib/tarka_matchers/matchers/expectation/have_a_description_of.rb
@@ -166,10 +154,12 @@ files:
166
154
  - lib/tarka_matchers/matchers/rails/action_dispatch/be_named_as.rb
167
155
  - lib/tarka_matchers/matchers/regex/match_sections.rb
168
156
  - lib/tarka_matchers/matchers/string/sgr/be_red.rb
157
+ - lib/tarka_matchers/matchers/string/t_equal.rb
169
158
  - lib/tarka_matchers/rails_matchers.rb
170
159
  - lib/tarka_matchers/regex_matchers.rb
171
160
  - lib/tarka_matchers/ruby_matchers.rb
172
161
  - lib/tarka_matchers/sgr_matchers.rb
162
+ - lib/tarka_matchers/utility.rb
173
163
  - lib/tarka_matchers/version.rb
174
164
  - tarka_matchers.gemspec
175
165
  homepage: https://github.com/jaytarka/tarka_matchers