nanoc-spec 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f909ce885ffe4562d8ecb52f757c4b6d99dd42547c6b890f6c3778ab08dc6f26
4
+ data.tar.gz: 43d0076bf889953457b8ede4a53657698c96bd92f672c4f1d26b03bf1d02e0de
5
+ SHA512:
6
+ metadata.gz: 952919fa35ba23aeca9eed60aedf47b9b3b862765f3548d2745969f5277ebcc230d77f4e4f5123566096acfa6628b428fc28f2f35df75cd23981ccad414c192f
7
+ data.tar.gz: dbbf3c6f832d11c84f6c9a4f975521de27982e8455e9a435ad22aed83ae7b87d78781ffbc17e11adcb0b53b80a6612d8d6c78ce015e7547615ae8d80f1eea054
data/NEWS.md ADDED
@@ -0,0 +1,5 @@
1
+ # nanoc-spec news
2
+
3
+ ## 0.0.1 (2019-11-16)
4
+
5
+ Initial release.
@@ -0,0 +1,17 @@
1
+ # nanoc-spec
2
+
3
+ This provides `Nanoc::Spec`, which contains a bunch of functionality that facilitates writing tests for [Nanoc](https://nanoc.ws).
4
+
5
+ ## Installation
6
+
7
+ Add `nanoc-spec` to the `nanoc` group of your Gemfile:
8
+
9
+ ```ruby
10
+ group :nanoc do
11
+ gem 'nanoc-spec'
12
+ end
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Don’t — for now.
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nanoc/spec'
@@ -0,0 +1,246 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Spec
5
+ end
6
+ end
7
+
8
+ require 'nanoc/spec/version'
9
+
10
+ module Nanoc
11
+ module Spec
12
+ module Helper
13
+ def chdir(dir)
14
+ here = Dir.getwd
15
+ Dir.chdir(dir)
16
+ yield
17
+ ensure
18
+ Dir.chdir(here)
19
+ end
20
+
21
+ def command?(cmd)
22
+ TTY::Which.exist?(cmd)
23
+ end
24
+
25
+ def skip_unless_have_command(cmd)
26
+ skip "Could not find external command \"#{cmd}\"" unless command?(cmd)
27
+ end
28
+
29
+ def skip_unless_gem_available(gem)
30
+ require gem
31
+ rescue LoadError
32
+ skip "Could not load gem \"#{gem}\""
33
+ end
34
+
35
+ def sleep_until(max: 3.0)
36
+ start = Time.now
37
+ loop do
38
+ diff = (Time.now - start).to_f
39
+ if diff > max
40
+ raise "Waited for #{diff}s for condition to become true, but it never did"
41
+ end
42
+
43
+ break if yield
44
+
45
+ sleep 0.1
46
+ end
47
+ end
48
+ end
49
+
50
+ class HelperContext
51
+ # @return [Nanoc::Core::DependencyTracker]
52
+ attr_reader :dependency_tracker
53
+
54
+ attr_reader :erbout
55
+
56
+ # @param [Module] mod The helper module to create a context for
57
+ def initialize(mod)
58
+ @mod = mod
59
+
60
+ @erbout = +''
61
+ @action_sequence = {}
62
+ @config = Nanoc::Core::Configuration.new(dir: Dir.getwd).with_defaults
63
+ @reps = Nanoc::Core::ItemRepRepo.new
64
+ @items = Nanoc::Core::ItemCollection.new(@config)
65
+ @layouts = Nanoc::Core::LayoutCollection.new(@config)
66
+ @dependency_tracker = Nanoc::Core::DependencyTracker.new(Object.new)
67
+ @compiled_content_store = Nanoc::Core::CompiledContentStore.new
68
+ @action_provider = new_action_provider
69
+ end
70
+
71
+ # Creates a new item and adds it to the site’s collection of items.
72
+ #
73
+ # @param [String] content The uncompiled item content
74
+ #
75
+ # @param [Hash] attributes A hash containing this item's attributes
76
+ #
77
+ # @param [Nanoc::Core::Identifier, String] identifier This item's identifier
78
+ #
79
+ # @return [Nanoc::Core::CompilationItemView] A view for the newly created item
80
+ def create_item(content, attributes, identifier)
81
+ item = Nanoc::Core::Item.new(content, attributes, identifier)
82
+ @items = @items.add(item)
83
+ self
84
+ end
85
+
86
+ # Creates a new layout and adds it to the site’s collection of layouts.
87
+ #
88
+ # @param [String] content The raw layout content
89
+ #
90
+ # @param [Hash] attributes A hash containing this layout's attributes
91
+ #
92
+ # @param [Nanoc::Core::Identifier, String] identifier This layout's identifier
93
+ #
94
+ # @return [Nanoc::Core::CompilationItemView] A view for the newly created layout
95
+ def create_layout(content, attributes, identifier)
96
+ layout = Nanoc::Core::Layout.new(content, attributes, identifier)
97
+ @layouts = @layouts.add(layout)
98
+ self
99
+ end
100
+
101
+ # Creates a new representation for the given item.
102
+ #
103
+ # @param [Nanoc::Core::CompilationItemView] item The item to create a represetation for
104
+ #
105
+ # @param [String] path The path of the `:last` snapshot of this item representation
106
+ # @param [Symbol] rep The rep name to create
107
+ def create_rep(item, path, rep = :default)
108
+ rep = Nanoc::Core::ItemRep.new(item._unwrap, rep)
109
+ rep.paths[:last] = [path]
110
+ @reps << rep
111
+ self
112
+ end
113
+
114
+ # @return [Object] An object that includes the helper functions
115
+ def helper
116
+ mod = @mod
117
+ klass = Class.new(Nanoc::Core::Context) { include mod }
118
+ klass.new(assigns)
119
+ end
120
+
121
+ def item=(item)
122
+ @item = item ? item._unwrap : nil
123
+ end
124
+
125
+ def item_rep=(item_rep)
126
+ @item_rep = item_rep ? item_rep._unwrap : nil
127
+ end
128
+
129
+ # @return [Nanoc::Core::MutableConfigView]
130
+ def config
131
+ assigns[:config]
132
+ end
133
+
134
+ # @return [Nanoc::Core::CompilationItemView, nil]
135
+ def item
136
+ assigns[:item]
137
+ end
138
+
139
+ # @return [Nanoc::Core::BasicItemRepView, nil]
140
+ def item_rep
141
+ assigns[:item_rep]
142
+ end
143
+
144
+ # @return [Nanoc::Core::ItemCollectionWithRepsView]
145
+ def items
146
+ assigns[:items]
147
+ end
148
+
149
+ # @return [Nanoc::Core::LayoutCollectionView]
150
+ def layouts
151
+ assigns[:layouts]
152
+ end
153
+
154
+ def action_sequence_for(obj)
155
+ @action_sequence.fetch(obj, [])
156
+ end
157
+
158
+ def update_action_sequence(obj, memory)
159
+ @action_sequence[obj] = memory
160
+ end
161
+
162
+ def compiled_content_store
163
+ view_context.compiled_content_store
164
+ end
165
+
166
+ private
167
+
168
+ def view_context
169
+ compilation_context =
170
+ Nanoc::Core::CompilationContext.new(
171
+ action_provider: @action_provider,
172
+ reps: @reps,
173
+ site: site,
174
+ compiled_content_cache: Nanoc::Core::CompiledContentCache.new(config: @config),
175
+ compiled_content_store: @compiled_content_store,
176
+ )
177
+
178
+ Nanoc::Core::ViewContextForCompilation.new(
179
+ reps: @reps,
180
+ items: @items,
181
+ dependency_tracker: @dependency_tracker,
182
+ compilation_context: compilation_context,
183
+ compiled_content_store: @compiled_content_store,
184
+ )
185
+ end
186
+
187
+ def new_action_provider
188
+ Class.new(Nanoc::Core::ActionProvider) do
189
+ def self.for(_context)
190
+ raise NotImplementedError
191
+ end
192
+
193
+ def initialize(context)
194
+ @context = context
195
+ end
196
+
197
+ def rep_names_for(_item)
198
+ [:default]
199
+ end
200
+
201
+ def action_sequence_for(obj)
202
+ @context.action_sequence_for(obj)
203
+ end
204
+
205
+ def snapshots_defs_for(_rep)
206
+ [Nanoc::Core::SnapshotDef.new(:last, binary: false)]
207
+ end
208
+ end.new(self)
209
+ end
210
+
211
+ def new_compiler_for(site)
212
+ Nanoc::Core::CompilerLoader.new.load(site, action_provider: @action_provider)
213
+ end
214
+
215
+ def site
216
+ @_site ||=
217
+ Nanoc::Core::Site.new(
218
+ config: @config,
219
+ code_snippets: [],
220
+ data_source: Nanoc::Core::InMemoryDataSource.new(@items, @layouts),
221
+ )
222
+ end
223
+
224
+ def assigns
225
+ {
226
+ config: Nanoc::Core::MutableConfigView.new(@config, view_context),
227
+ item_rep: @item_rep ? Nanoc::Core::CompilationItemRepView.new(@item_rep, view_context) : nil,
228
+ item: @item ? Nanoc::Core::CompilationItemView.new(@item, view_context) : nil,
229
+ items: Nanoc::Core::ItemCollectionWithRepsView.new(@items, view_context),
230
+ layouts: Nanoc::Core::LayoutCollectionView.new(@layouts, view_context),
231
+ _erbout: @erbout,
232
+ }
233
+ end
234
+ end
235
+
236
+ module HelperHelper
237
+ def ctx
238
+ @_ctx ||= HelperContext.new(described_class)
239
+ end
240
+
241
+ def helper
242
+ @_helper ||= ctx.helper
243
+ end
244
+ end
245
+ end
246
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Spec
5
+ VERSION = '0.0.1'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanoc-spec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Denis Defreyne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nanoc-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.11'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.11.13
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.11'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 4.11.13
33
+ description: Provides Nanoc::Spec, containing functionality for writing tests for
34
+ Nanoc
35
+ email: denis+rubygems@denis.ws
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - NEWS.md
41
+ - README.md
42
+ - lib/nanoc-spec.rb
43
+ - lib/nanoc/spec.rb
44
+ - lib/nanoc/spec/version.rb
45
+ homepage: https://nanoc.ws/
46
+ licenses:
47
+ - MIT
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.4'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.0.6
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Testing functionality for Nanoc
68
+ test_files: []