jekyll_plugin_support 3.0.0 → 3.1.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.
@@ -1,4 +1,3 @@
1
- # require 'jekyll_draft'
2
1
  require 'securerandom'
3
2
 
4
3
  # @author Copyright 2020 Michael Slinn
@@ -15,17 +14,18 @@ module JekyllAllCollections
15
14
  # @return [String]
16
15
  def render_impl
17
16
  parse_arguments # Defines instance variables like @sort_by
18
- sort_lambda = init_sort_by @sort_by, @sort_by_param
19
- @heading = @helper.parameter_specified?('heading') || default_head(@sort_by)
17
+ sort_lambda = init_sort_by @sort_by
20
18
  generate_output sort_lambda
21
19
  rescue StandardError => e
22
- JekyllSupport.error_short_trace @logger, e
23
- # JekyllSupport.warn_short_trace @logger, e
20
+ ::JekyllSupport.error_short_trace @logger, e
21
+ # ::JekyllSupport.warn_short_trace @logger, e
24
22
  end
25
23
 
26
- # Descending sort keys reverse the order of comparison
27
- # Example return values:
28
- # "->(a, b) { [a.last_modified] <=> [b.last_modified] }"
24
+ # Descending sort keys are preceded by a minus sign, and reverse the order of comparison
25
+ # @param criteria String Examples: 'date', '-date', 'last_modified', '-last_modified',
26
+ # ['date', 'last_modified], ['-date', '-last_modified'], ['date', '-last_modified']
27
+ # @return values:
28
+ # "->(a, b) { [a.last_modified] <=> [b.last_modified] }" (ascending)
29
29
  # "->(a, b) { [b.last_modified] <=> [a.last_modified] }" (descending)
30
30
  # "->(a, b) { [a.last_modified, a.date] <=> [b.last_modified, b.date] }" (descending last_modified, ascending date)
31
31
  # "->(a, b) { [a.last_modified, b.date] <=> [b.last_modified, a.date] }" (ascending last_modified, descending date)
@@ -76,43 +76,45 @@ module JekyllAllCollections
76
76
  warn_short_trace e.red
77
77
  end
78
78
 
79
- def last_modified_value(apage)
80
- @logger.debug do
81
- " apage.last_modified='#{apage.last_modified}'; " \
82
- "apage.last_modified_at='#{apage.last_modified_at}'; " \
83
- "@date_column='#{@date_column}'"
79
+ def date_value(apage, field_name)
80
+ if %i[last_modified last_modified_at].include? field_name
81
+ apage.field(:last_modified_at, use_default: false) ||
82
+ apage.field(:last_modified, use_default: false) ||
83
+ Date.today
84
+ else
85
+ apage.date || Time.now
84
86
  end
85
- last_modified = if @date_column == 'last_modified' && apage.respond_to?(:last_modified)
86
- apage.last_modified
87
- elsif apage.respond_to? :last_modified_at
88
- apage.last_modified_at
89
- else
90
- apage.date
91
- end
92
- last_modified ||= apage.date || Date.today
93
- last_modified
94
87
  end
95
88
 
96
89
  def generate_output(sort_lambda)
97
- id = @id.to_s.strip.empty? ? '' : " id='#{@id}'"
90
+ id = @id.to_s.strip.empty? ? '' : " id=\"#{@id}\""
98
91
  heading = @heading.strip.to_s.empty? ? '' : "<h2#{id}>#{@heading}</h2>"
99
- data = case @data_selector
100
- when 'all_collections'
101
- @site.all_collections
102
- when 'all_documents'
103
- @site.all_documents
104
- when 'everything'
105
- @site.everything
106
- else
107
- raise AllCollectionsError, "Invalid value for @data_selector (#{data_selector})"
108
- end
109
- collection = data.sort(&sort_lambda)
110
- posts = collection.map do |x|
111
- last_modified = last_modified_value x
112
- date = last_modified.strftime '%Y-%m-%d'
113
- draft = x.draft ? DRAFT_HTML : ''
114
- href = "<a href='#{x.href}'>#{x.title}</a>"
115
- @logger.debug { " date='#{date}' #{x.title}\n" }
92
+ apages = case @data_selector
93
+ when 'all_collections'
94
+ @site.all_collections
95
+ when 'all_documents'
96
+ @site.all_documents
97
+ when 'everything'
98
+ @site.everything
99
+ else
100
+ raise AllCollectionsError, "Invalid value for @data_selector (#{data_selector})"
101
+ end
102
+ filtered_apages = @collection_name.nil? ? apages : apages.select { |apage| apage.collection_name == @collection_name }
103
+ sorted_apages = filtered_apages.sort(&sort_lambda)
104
+ posts = sorted_apages.map do |apage|
105
+ date_column = @date_column.to_s == 'last_modified' ? :last_modified : :date
106
+ d = date_value(apage, date_column)
107
+ if d.respond_to?(:strftime)
108
+ date = d.strftime '%Y-%m-%d'
109
+ else
110
+ @logger.error do
111
+ "date_value returned a #{d.class} instead of a class with a strftime method like Date and Time; date_column=#{date_column}"
112
+ end
113
+ end
114
+ draft = apage.draft ? DRAFT_HTML : ''
115
+ title = apage.title || apage.href
116
+ href = "<a href='#{apage.href}'>#{title}</a>"
117
+ @logger.debug { " date='#{date}' #{title}\n" }
116
118
  " <span>#{date}</span><span>#{href}#{draft}</span>"
117
119
  end
118
120
  <<~END_TEXT
@@ -121,35 +123,50 @@ module JekyllAllCollections
121
123
  #{posts.join "\n"}
122
124
  </div>
123
125
  END_TEXT
124
- rescue ArgumentError => e
125
- warn_short_trace e
126
+ rescue NoMethodError || ArgumentError => e
127
+ ::JekyllSupport.error_short_trace @logger, e
126
128
  end
127
129
 
128
130
  # See https://stackoverflow.com/a/75377832/553865
129
- def init_sort_by(sort_by, sort_by_param)
131
+ def init_sort_by(sort_by)
130
132
  sort_lambda_string = AllCollectionsTag.create_lambda_string sort_by
131
133
 
132
134
  @logger.debug do
133
- "#{@page['path']} sort_by_param=#{sort_by_param} " \
134
- "sort_lambda_string = #{sort_lambda_string}\n"
135
+ "#{@page['path']} sort_lambda_string = #{sort_lambda_string}\n"
135
136
  end
136
137
 
137
138
  evaluate sort_lambda_string
138
139
  end
139
140
 
141
+ # @return String defining the parsed sort_by expression
140
142
  def parse_arguments
143
+ @collection_name = @helper.parameter_specified?('collection_name')
141
144
  @data_selector = @helper.parameter_specified?('data_selector') || 'all_collections'
142
145
  abort "Invalid data_selector #{@data_selector}" unless %w[all_collections all_documents everything].include? @data_selector
146
+ if (@data_selector != 'all_collections') && @collection_name
147
+ @logger.warn do
148
+ "collection_name was specified as '#{@collection_name}', but data_selector is #{@data_selector},
149
+ which is less effcient than specifying all_collections."
150
+ end
151
+ end
152
+
153
+ sort_by_param = @helper.parameter_specified? 'sort_by' # Might specify multiple sort fields
143
154
 
144
- @date_column = @helper.parameter_specified?('date_column') || 'date'
155
+ # Default to displaying last modified field unless a sort field is specified
156
+ @date_column = @helper.parameter_specified?('date_column') || 'last_modified'
145
157
  unless %w[date last_modified].include?(@date_column)
146
158
  raise AllCollectionsError "The date_column attribute must either have value 'date' or 'last_modified', " \
147
- "but '#{@date_column}' was specified"
159
+ "but '#{@date_column}' was specified instead."
148
160
  end
161
+ @date_column ||= (sort_by_param.include?('last_modified') ? 'last_modified' : 'date') # display the sort date by default
149
162
 
150
163
  @id = @helper.parameter_specified?('id') || SecureRandom.hex(10)
151
- @sort_by_param = @helper.parameter_specified? 'sort_by'
152
- @sort_by = (@sort_by_param&.delete(' ')&.split(',') if @sort_by_param != false) || ['-date']
164
+
165
+ @sort_by = (sort_by_param&.delete(' ')&.split(',') if sort_by_param != false) || ['-date']
166
+
167
+ @heading = @helper.parameter_specified?('heading') || default_head(@sort_by)
168
+
169
+ @sort_by
153
170
  end
154
171
 
155
172
  ::JekyllSupport::JekyllPluginHelper.register(self, PLUGIN_NAME)
@@ -1,6 +1,7 @@
1
1
  # Monkey patch StandardError so a new method called shorten_backtrace is added.
2
2
  class StandardError
3
- def shorten_backtrace(backtrace_element_count = 3)
3
+ def shorten_backtrace(backtrace_element_count = 5)
4
+ set_backtrace backtrace[0..backtrace_element_count]
4
5
  # self.backtrace = backtrace[0..backtrace_element_count].map do |x|
5
6
  # raise JekyllPluginSupportError, "backtrace contains a #{x.class} with value '#{x}'." unless x.instance_of? String
6
7
 
@@ -14,7 +15,7 @@ module JekyllSupport
14
15
 
15
16
  def self.error_short_trace(logger, error)
16
17
  error.set_backtrace error.backtrace[0..DISPLAYED_CALLS]
17
- logger.error { error }
18
+ logger.error { error.full_message } # Are error and logger.error defined?
18
19
  error
19
20
  end
20
21
 
@@ -1,3 +1,3 @@
1
1
  module JekyllPluginSupportVersion
2
- VERSION = '3.0.0'.freeze unless defined?(VERSION)
2
+ VERSION = '3.1.1'.freeze unless defined?(VERSION)
3
3
  end
@@ -28,6 +28,12 @@ module JekyllSupport
28
28
  end
29
29
  end
30
30
 
31
+ module ToString
32
+ def to_s
33
+ "#{self}.class.name"
34
+ end
35
+ end
36
+
31
37
  module NoArgParsing
32
38
  attr_accessor :no_arg_parsing
33
39
 
@@ -37,17 +43,21 @@ end
37
43
  module JekyllSupport
38
44
  class JekyllTag
39
45
  include JekyllSupportError
46
+ include ToString
40
47
  end
41
48
 
42
49
  class JekyllTagNoArgParsing
43
50
  include JekyllSupportError
51
+ include ToString
44
52
  end
45
53
 
46
54
  class JekyllBlock
47
55
  include JekyllSupportError
56
+ include ToString
48
57
  end
49
58
 
50
59
  class JekyllBlockNoArgParsing
51
60
  include JekyllSupportError
61
+ include ToString
52
62
  end
53
63
  end
@@ -1,112 +1,184 @@
1
- require 'spec_helper'
2
- require_relative '../../lib/jekyll_all_collections'
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/hooks/a_page'
3
3
 
4
- class APageStub
5
- attr_reader :date, :last_modified, :label
4
+ class NullBinding < BasicObject
5
+ include ::Kernel
6
6
 
7
- def initialize(date, last_modified, label = '')
8
- @date = Date.parse date
9
- @last_modified = Date.parse last_modified
10
- @label = label
11
- end
7
+ # Avoid error message "warning: undefining `object_id' may cause serious problems"
8
+ # https://stackoverflow.com/a/17791631/553865
9
+ (
10
+ ::Kernel.instance_methods(false) +
11
+ ::Kernel.private_instance_methods(false) -
12
+ [:binding]
13
+ ).each { |x| undef_method(x) unless x == :object_id }
12
14
 
13
- def to_s
14
- @label
15
+ def min_binding
16
+ binding
15
17
  end
16
18
  end
17
19
 
18
- def show(lambda_string, result, expected)
19
- p "For lambda_string: #{lambda_string}"
20
- p " result: #{result.map(&:label).join(', ')} <==> expected: #{expected.map(&:label).join(', ')}"
20
+ def show_dates(label, array)
21
+ puts " #{label} actual: #{array.map(&:title).join(', ')} <==> expected: #{expected.map(&:title).join(', ')}"
22
+ end
23
+
24
+ def show(label, lambda_string, actual, expected)
25
+ puts "#{label} - For lambda_string: #{lambda_string}"
26
+ puts " actual: #{actual.map(&:title).join(', ')}"
27
+ puts "expected: #{expected.map(&:title).join(', ')}"
28
+ actual_array = actual.map do |x|
29
+ [
30
+ (x.date.strftime '%Y-%m-%d' + '/' + x.title), (x.last_modified.strftime '%Y-%m-%d' + '/' + x.title)
31
+ ].join('/')
32
+ end
33
+ expected_array = expected.map do |x|
34
+ [
35
+ (x.date.strftime '%Y-%m-%d' + '/' + x.title), (x.last_modified.strftime '%Y-%m-%d' + '/' + x.title)
36
+ ].join('/')
37
+ end
38
+ puts ' actual date/last_modified: ' + actual_array.join(', ')
39
+ puts 'expected date/last_modified: ' + expected_array.join(', ')
21
40
  end
22
41
 
42
+ logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
43
+
23
44
  # See https://stackoverflow.com/a/75388137/553865
24
- RSpec.describe(AllCollectionsTag::AllCollectionsTag) do
25
- let(:o1) { APageStub.new('2020-01-01', '2020-01-01', 'a_A') }
26
- let(:o2) { APageStub.new('2021-01-01', '2020-01-01', 'b_A') }
27
- let(:o3) { APageStub.new('2021-01-01', '2023-01-01', 'b_B') }
28
- let(:o4) { APageStub.new('2022-01-01', '2023-01-01', 'c_B') }
45
+ RSpec.describe(JekyllSupport) do
46
+ let(:o1) do
47
+ described_class.apage_from(
48
+ collection_name: '_posts',
49
+ date: '2020-01-20',
50
+ last_modified: '2020-01-20',
51
+ logger: logger,
52
+ title: 'a_A (o1)'
53
+ )
54
+ end
55
+ let(:o2) do
56
+ described_class.apage_from(
57
+ collection_name: '_posts',
58
+ date: '2021-01-21',
59
+ last_modified: '2021-01-21',
60
+ logger: logger,
61
+ title: 'b_B (o2)'
62
+ )
63
+ end
64
+ let(:o3) do
65
+ described_class.apage_from(
66
+ collection_name: '_posts',
67
+ date: '2021-01-21',
68
+ last_modified: '2022-01-22',
69
+ logger: logger,
70
+ title: 'b_C (o3)'
71
+ )
72
+ end
73
+ let(:o4) do
74
+ described_class.apage_from(
75
+ collection_name: '_posts',
76
+ date: '2022-01-22',
77
+ last_modified: '2022-01-22',
78
+ logger: logger,
79
+ title: 'c_C (o4)'
80
+ )
81
+ end
29
82
  let(:objs) { [o1, o2, o3, o4] }
30
83
 
31
- it 'defines sort_by lambda with last_modified' do
84
+ it '(1) defines sort_by lambda with last_modified (ascending)' do
32
85
  sort_lambda = ->(a, b) { [a.last_modified] <=> [b.last_modified] }
33
- result = objs.sort(&sort_lambda)
34
- expect(result).to eq([o1, o2, o3, o4])
86
+ actual = objs.sort(&sort_lambda)
87
+ expected = [o1, o2, o3, o4]
88
+ show('(1)', '[a.last_modified] <=> [b.last_modified]', actual, expected)
89
+ expect(actual).to eq(expected)
35
90
  end
36
91
 
37
- it 'makes sort_by lambdas from stringified date' do
38
- sort_lambda = eval '->(a, b) { a.last_modified <=> b.last_modified }',
39
- NullBinding.new.min_binding, __FILE__, __LINE__ - 1
40
- result = objs.sort(&sort_lambda)
41
- expect(result).to eq([o1, o2, o3, o4])
92
+ it '(2) makes sort_by lambdas from stringified comparison of last_modified (ascending)' do
93
+ sort_lambda_string = '->(a, b) { a.last_modified <=> b.last_modified }'
94
+ sort_lambda = eval sort_lambda_string, NullBinding.new.min_binding, __FILE__, __LINE__ - 1
95
+ actual = objs.sort(&sort_lambda)
96
+ expected = [o1, o2, o3, o4]
97
+ show('(2)', sort_lambda_string, actual, expected)
98
+ expect(actual).to eq(expected)
42
99
  end
43
100
 
44
- it 'makes sort_by lambdas from stringified array of last_modified' do
45
- sort_lambda = eval '->(a, b) { [a.last_modified] <=> [b.last_modified] }',
46
- NullBinding.new.min_binding, __FILE__, __LINE__ - 1
47
- result = objs.sort(&sort_lambda)
48
- expect(result).to eq([o1, o2, o3, o4])
101
+ it '(3) makes sort_by lambda from stringified array of last_modified (ascending)' do
102
+ sort_lambda_string = '->(a, b) { [a.last_modified] <=> [b.last_modified] }'
103
+ sort_lambda = eval sort_lambda_string, NullBinding.new.min_binding, __FILE__, __LINE__ - 1
104
+ actual = objs.sort(&sort_lambda)
105
+ expected = [o1, o2, o3, o4]
106
+ show('(3)', sort_lambda_string, actual, expected)
107
+ expect(actual).to eq(expected)
49
108
  end
50
109
 
51
- it 'makes sort_by lambdas with descending keys from stringified array of last_modified' do
52
- sort_lambda = eval '->(a, b) { [b.last_modified] <=> [a.last_modified] }',
53
- NullBinding.new.min_binding, __FILE__, __LINE__ - 1
54
- result = objs.sort(&sort_lambda)
55
- expected = [o3, o4, o1, o2]
56
- expect(result).to eq(expected)
110
+ it '(4) makes sort_by lambda with last_modified (descending) from stringified array' do
111
+ sort_lambda_string = '->(a, b) { [b.last_modified] <=> [a.last_modified] }'
112
+ sort_lambda = eval sort_lambda_string, NullBinding.new.min_binding, __FILE__, __LINE__ - 1
113
+ actual = objs.sort(&sort_lambda)
114
+ expected = [o4, o3, o2, o1]
115
+ show('(4)', sort_lambda_string, actual, expected)
116
+ expect([o3, o4]).to include(actual[0]) # The sort might yield o3 or o4 in this position
117
+ expect([o3, o4]).to include(actual[1]) # The sort might yield o3 or o4 in this position
118
+ expect(o2).to eq(actual[2])
119
+ expect(o1).to eq(actual[3])
57
120
  end
58
121
 
59
- it 'create_lambda with 1 date key, descending' do
60
- lambda_string = described_class.create_lambda_string('-last_modified')
61
- sort_lambda = described_class.evaluate(lambda_string)
62
- result = objs.sort(&sort_lambda)
63
- expected = [o3, o4, o1, o2]
64
- # show(lambda_string, result, expected)
65
- expect(result).to eq(expected)
122
+ it '(5) create_lambda with date (descending)' do
123
+ lambda_string = JekyllAllCollections::AllCollectionsTag.create_lambda_string('-last_modified')
124
+ expect(lambda_string).to eq('->(a, b) { [b.last_modified] <=> [a.last_modified] }')
125
+ sort_lambda = self.eval lambda_string, binding
126
+ actual = objs.sort(&sort_lambda)
127
+ expected = [o4, o3, o2, o1]
128
+ show('(5)', lambda_string, actual, expected)
129
+ expect([o3, o4]).to include(actual[0]) # The sort might yield o3 or o4 in this position
130
+ expect([o3, o4]).to include(actual[1]) # The sort might yield o3 or o4 in this position
131
+ expect(o2).to eq(actual[2])
132
+ expect(o1).to eq(actual[3])
66
133
  end
67
134
 
68
- it 'create_lambda with 1 date key, ascending' do
69
- lambda_string = described_class.create_lambda_string('date')
70
- sort_lambda = described_class.evaluate(lambda_string)
71
- result = objs.sort(&sort_lambda)
135
+ it '(6) create_lambda with date (ascending)' do
136
+ lambda_string = JekyllAllCollections::AllCollectionsTag.create_lambda_string('date')
137
+ expect(lambda_string).to eq('->(a, b) { [a.date] <=> [b.date] }')
138
+ sort_lambda = self.eval lambda_string, binding
139
+ actual = objs.sort(&sort_lambda)
72
140
  expected = [o1, o2, o3, o4]
73
- # show(lambda_string, result, expected)
74
- expect(result).to eq(expected)
141
+ show('(1)', lambda_string, actual, expected)
142
+ expect(actual).to eq(expected)
75
143
  end
76
144
 
77
- it 'create_lambda with 2 date keys, both ascending' do
78
- lambda_string = described_class.create_lambda_string(%w[date last_modified])
79
- sort_lambda = described_class.evaluate(lambda_string)
80
- result = objs.sort(&sort_lambda)
145
+ it '(7) create_lambda with date (ascending) and last_modified (ascending)' do
146
+ lambda_string = JekyllAllCollections::AllCollectionsTag.create_lambda_string(%w[date last_modified])
147
+ expect(lambda_string).to eq('->(a, b) { [a.date, a.last_modified] <=> [b.date, b.last_modified] }')
148
+ sort_lambda = self.eval lambda_string, binding
149
+ actual = objs.sort(&sort_lambda)
81
150
  expected = [o1, o2, o3, o4]
82
- # show(lambda_string, result, expected)
83
- expect(result).to eq(expected)
151
+ show('(7)', lambda_string, actual, expected)
152
+ expect(actual).to eq(expected)
84
153
  end
85
154
 
86
- it 'create_lambda with 2 date keys, both descending' do
87
- lambda_string = described_class.create_lambda_string(['-date', '-last_modified'])
88
- sort_lambda = described_class.evaluate(lambda_string)
89
- result = objs.sort(&sort_lambda)
155
+ it '(8) create_lambda with date (descending) and last_modified (descending)' do
156
+ lambda_string = JekyllAllCollections::AllCollectionsTag.create_lambda_string(['-date', '-last_modified'])
157
+ expect(lambda_string).to eq('->(a, b) { [b.date, b.last_modified] <=> [a.date, a.last_modified] }')
158
+ sort_lambda = self.eval lambda_string, binding
159
+ actual = objs.sort(&sort_lambda)
90
160
  expected = [o4, o3, o2, o1]
91
- # show(lambda_string, result, expected)
92
- expect(result).to eq(expected)
161
+ show('(8)', lambda_string, actual, expected)
162
+ expect(actual).to eq(expected)
93
163
  end
94
164
 
95
- it 'create_lambda with 2 date keys, first descending and second ascending' do
96
- lambda_string = described_class.create_lambda_string(['-date', 'last_modified'])
97
- sort_lambda = described_class.evaluate(lambda_string)
98
- result = objs.sort(&sort_lambda)
165
+ it '(9) create_lambda with date (descending) and last_modified (ascending)' do
166
+ lambda_string = JekyllAllCollections::AllCollectionsTag.create_lambda_string(['-date', 'last_modified'])
167
+ expect(lambda_string).to eq('->(a, b) { [b.date, a.last_modified] <=> [a.date, b.last_modified] }')
168
+ sort_lambda = self.eval lambda_string, binding
169
+ actual = objs.sort(&sort_lambda)
99
170
  expected = [o4, o2, o3, o1]
100
- # show(lambda_string, result, expected)
101
- expect(result).to eq(expected)
171
+ show('(9)', lambda_string, actual, expected)
172
+ expect(actual).to eq(expected)
102
173
  end
103
174
 
104
- it 'create_lambda with 2 date keys, first ascending and second descending' do
105
- lambda_string = described_class.create_lambda_string(['date', '-last_modified'])
106
- sort_lambda = described_class.evaluate(lambda_string)
107
- result = objs.sort(&sort_lambda)
175
+ it '(10) create_lambda with date (ascending) and last_modified (descending)' do
176
+ lambda_string = JekyllAllCollections::AllCollectionsTag.create_lambda_string(['date', '-last_modified'])
177
+ expect(lambda_string).to eq('->(a, b) { [a.date, b.last_modified] <=> [b.date, a.last_modified] }')
178
+ sort_lambda = self.eval lambda_string, binding
179
+ actual = objs.sort(&sort_lambda)
108
180
  expected = [o1, o3, o2, o4]
109
- # show(lambda_string, result, expected)
110
- expect(result).to eq(expected)
181
+ show('(10)', lambda_string, actual, expected)
182
+ expect(actual).to eq(expected)
111
183
  end
112
184
  end
@@ -1,5 +1,7 @@
1
+ require 'spec_helper'
1
2
  require_relative '../lib/error/jekyll_custom_error'
2
3
  require_relative '../lib/jekyll_plugin_support/jekyll_plugin_support_class'
4
+ require_relative '../lib/helper/jekyll_plugin_helper'
3
5
 
4
6
  class Dummy
5
7
  def just_for_testing; end
@@ -14,14 +16,14 @@ class CustomErrorSpec
14
16
 
15
17
  puts "AnError is a #{AnError.class}; StandardError is a #{StandardError.class}"
16
18
  begin
17
- raise AnError, 'Oops'
19
+ raise AnError, 'This error is expected'
18
20
  rescue AnError => e
19
21
  puts "Caught AnError: #{e.message}"
20
22
  rescue ::JekyllSupport::CustomError => e
21
23
  puts "Caught CustomError: #{e.message}"
22
24
  end
23
25
 
24
- RSpec.describe JekyllSupport::JekyllPluginHelper do
26
+ RSpec.describe ::JekyllSupport::JekyllPluginHelper do
25
27
  it 'generates messages' do
26
28
  msg = described_class.generate_message(Dummy, tag_name, '0.1.0')
27
29
  puts msg
@@ -1,4 +1,6 @@
1
+ require 'jekyll'
1
2
  require 'jekyll_plugin_logger'
3
+ require 'spec_helper'
2
4
  # require 'rspec/match_ignoring_whitespace'
3
5
  require_relative '../lib/jekyll_plugin_support'
4
6
  require_relative '../lib/jekyll_plugin_support/jekyll_plugin_support_spec_support'
@@ -1,4 +1,5 @@
1
1
  require 'jekyll_plugin_logger'
2
+ require 'spec_helper'
2
3
  # require 'rspec/match_ignoring_whitespace'
3
4
  require_relative '../lib/jekyll_plugin_support'
4
5
  require_relative '../lib/jekyll_plugin_support/jekyll_plugin_support_spec_support'
data/spec/spec_helper.rb CHANGED
@@ -4,9 +4,19 @@ require_relative '../lib/jekyll_plugin_support'
4
4
  Jekyll.logger.log_level = :info
5
5
 
6
6
  RSpec.configure do |config|
7
- config.filter_run_when_matching focus: true
8
- # config.order = 'random'
9
-
10
7
  # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
11
8
  config.example_status_persistence_file_path = 'spec/status_persistence.txt'
9
+
10
+ # See https://rspec.info/features/3-12/rspec-core/filtering/filter-run-when-matching/
11
+ # and https://github.com/rspec/rspec/issues/221
12
+ config.filter_run_when_matching :focus
13
+
14
+ # Other values: :progress, :html, :json, CustomFormatterClass
15
+ config.formatter = :documentation
16
+
17
+ # See https://rspec.info/features/3-12/rspec-core/command-line/order/
18
+ config.order = :defined
19
+
20
+ # See https://www.rubydoc.info/github/rspec/rspec-core/RSpec%2FCore%2FConfiguration:pending_failure_output
21
+ config.pending_failure_output = :skip
12
22
  end
@@ -1,3 +1,9 @@
1
- example_id | status | run_time |
2
- ----------------------------------------------- | ------ | --------------- |
3
- ./spec/jekyll_block_plugin_support_spec.rb[1:1] | passed | 0.00062 seconds |
1
+ example_id | status | run_time |
2
+ ------------------------------------------------ | ------ | --------------- |
3
+ ./spec/custom_error_spec.rb[1:1] | failed | 0.00772 seconds |
4
+ ./spec/custom_error_spec.rb[2:1] | passed | 0.0011 seconds |
5
+ ./spec/jekyll_plugin_helper_options_spec.rb[1:1] | failed | 0.00005 seconds |
6
+ ./spec/jekyll_plugin_helper_options_spec.rb[1:2] | failed | 0.00003 seconds |
7
+ ./spec/jekyll_plugin_helper_options_spec.rb[1:3] | failed | 0.00003 seconds |
8
+ ./spec/jekyll_plugin_helper_options_spec.rb[1:4] | failed | 0.00003 seconds |
9
+ ./spec/liquid_variable_parsing_spec.rb[1:1] | failed | 0.00003 seconds |
@@ -9,6 +9,15 @@ module TestModule
9
9
  end
10
10
  end
11
11
 
12
+ RSpec.describe(TestModule) do
13
+ extend described_class
14
+
15
+ it 'Invokes a_method from module' do
16
+ result = self.class.a_method
17
+ expect(result).to eq('a_method says Hi!')
18
+ end
19
+ end
20
+
12
21
  class TestClass
13
22
  extend TestModule # Defines class methods
14
23
 
@@ -19,15 +28,6 @@ class TestClass
19
28
  end
20
29
  end
21
30
 
22
- RSpec.describe(TestModule) do
23
- extend described_class
24
-
25
- it 'Invokes a_method from module' do
26
- result = self.class.a_method
27
- expect(result).to eq('a_method says Hi!')
28
- end
29
- end
30
-
31
31
  RSpec.describe(TestClass) do
32
32
  let(:o1) { described_class.new('value1', 'value2') }
33
33
 
metadata CHANGED
@@ -1,15 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_plugin_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-03-06 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: bigdecimal
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: facets
15
28
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +107,6 @@ dependencies:
94
107
  - - ">="
95
108
  - !ruby/object:Gem::Version
96
109
  version: '0'
97
- description:
98
110
  email:
99
111
  - mslinn@mslinn.com
100
112
  executables: []
@@ -169,8 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
181
  - !ruby/object:Gem::Version
170
182
  version: '0'
171
183
  requirements: []
172
- rubygems_version: 3.5.22
173
- signing_key:
184
+ rubygems_version: 3.7.2
174
185
  specification_version: 4
175
186
  summary: Provides a framework for writing and testing Jekyll plugins
176
187
  test_files: