jekyll-joule 0.0.1 → 0.0.3
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 +4 -4
- data/README.md +33 -2
- data/Rakefile +1 -1
- data/docs/introduction.md +9 -0
- data/docs/setup.md +111 -0
- data/examples/Gemfile +11 -0
- data/examples/Rakefile +10 -0
- data/examples/test/helper.rb +109 -0
- data/examples/test/source/joule.md +3 -0
- data/examples/test/test_example.rb +23 -0
- data/jekyll-joule.gemspec +2 -0
- data/lib/jekyll/extensions/nokogiri_element.rb +13 -0
- data/lib/jekyll/joule/page.rb +32 -0
- data/lib/jekyll/joule/site.rb +22 -8
- data/lib/jekyll/joule/version.rb +1 -1
- data/lib/jekyll/joule.rb +1 -0
- metadata +38 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4e2101503338f46fba3f5d6350affa42d1e5ef1
|
4
|
+
data.tar.gz: 8e7a846a2fd33971fc698b000f62a2363cc6c486
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '02328add785b1185da1b1380a1b9f0891626fbce6b0b8b540142d022645c4624d747cf9759340aa0e5a3fddf3834a3dd596d3a0a12dc78828ee1ddeaa786a1d6'
|
7
|
+
data.tar.gz: 9b2eb2342c9bf9b6b715bbbd5e784ce32c7c35dcc059885b42e12e3b5aedde64746ec42d1ccf295790fb6085c2b0066c178499c08558395c5a8cba9cc78cb7dc
|
data/README.md
CHANGED
@@ -1,3 +1,34 @@
|
|
1
|
-
# Joule
|
1
|
+
# Joule 🔸 [](https://travis-ci.org/helpscout/jekyll-joule) [](https://badge.fury.io/rb/jekyll-joule)
|
2
2
|
|
3
|
-
|
3
|
+
Joule is a Jekyll utility helper designed to make it (way) easier to write unit tests.
|
4
|
+
|
5
|
+
So far, Joule has only been tested with [minitest](https://github.com/seattlerb/minitest). However, you **should** be able to use it with other testing frameworks.
|
6
|
+
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'jekyll-joule'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
```
|
18
|
+
bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
```
|
23
|
+
gem install jekyll-joule
|
24
|
+
```
|
25
|
+
|
26
|
+
|
27
|
+
## Documentation
|
28
|
+
|
29
|
+
**[View the docs](https://github.com/helpscout/jekyll-joule/blob/master/docs/introduction.md)** to get started with Joule!
|
30
|
+
|
31
|
+
|
32
|
+
## Examples
|
33
|
+
|
34
|
+
**[View the example](https://github.com/helpscout/jekyll-joule/tree/master/examples)** Jekyll setup + Joule test files.
|
data/Rakefile
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Introduction
|
2
|
+
|
3
|
+
Joule is a Jekyll utility helper designed to make it (way) easier to write unit tests.
|
4
|
+
|
5
|
+
So far, Joule has only been tested with [minitest](https://github.com/seattlerb/minitest). However, you **should** be able to use it with other testing frameworks.
|
6
|
+
|
7
|
+
There is a _slight_ bit of setup required to get Jekyll setup for testing.
|
8
|
+
|
9
|
+
Check out our **[Setup](./setup.md)** documentation to get started!
|
data/docs/setup.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# Setup
|
2
|
+
|
3
|
+
The are a couple of things you need to do to get started with writing Jekyll tests.
|
4
|
+
|
5
|
+
The following steps are based on Jekyll's own [test setup](https://github.com/jekyll/jekyll/tree/master/test). However, they've been simplified to make it easier to follow 😘.
|
6
|
+
|
7
|
+
> ## TLDR
|
8
|
+
> You can find all of the setup code in our [examples](https://github.com/helpscout/jekyll-joule/tree/master/examples).
|
9
|
+
|
10
|
+
## Add test dependencies
|
11
|
+
|
12
|
+
Add a `Gemfile` to your Jekyll project's root directory, if you don't already have one.
|
13
|
+
|
14
|
+
```shell
|
15
|
+
my-jekyll/
|
16
|
+
├── ...
|
17
|
+
└── Gemfile
|
18
|
+
```
|
19
|
+
|
20
|
+
In that Gemfile, add the following Gem dependencies (if you don't have them already):
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
source 'https://rubygems.org'
|
24
|
+
group :test do
|
25
|
+
gem "minitest", "~> 5.8"
|
26
|
+
gem "minitest-profile"
|
27
|
+
gem "minitest-reporters"
|
28
|
+
gem "rake", "~> 10.0"
|
29
|
+
gem "rspec-mocks"
|
30
|
+
gem "shoulda"
|
31
|
+
gem "jekyll-joule"
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
This allow [Bundler](http://bundler.io/) to install and use these various Gems to power your Jekyll tests.
|
36
|
+
|
37
|
+
|
38
|
+
## Add a Rakefile
|
39
|
+
|
40
|
+
We're going to be using the following command to run our tests:
|
41
|
+
|
42
|
+
`bundle exec rake test`
|
43
|
+
|
44
|
+
In order to get this working, we need to create a `Rakefile` and add a `test` task.
|
45
|
+
|
46
|
+
Create an add a `Rakefile` (no extensions) to your Jekyll project's root directory.
|
47
|
+
|
48
|
+
```shell
|
49
|
+
my-jekyll/
|
50
|
+
├── ...
|
51
|
+
├── Gemfile
|
52
|
+
└── Rakefile
|
53
|
+
```
|
54
|
+
|
55
|
+
In that `Rakefile`, add the following:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
require 'rake'
|
59
|
+
require 'rake/testtask'
|
60
|
+
|
61
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), *%w[lib]))
|
62
|
+
|
63
|
+
Rake::TestTask.new(:test) do |test|
|
64
|
+
test.libs << 'lib' << 'test'
|
65
|
+
test.pattern = 'test/**/test_*.rb'
|
66
|
+
test.verbose = true
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
This tells `Rake` that for our `test` task, execute any `.rb` file in our `test/` directory that has a file name starting with `test_`.
|
71
|
+
|
72
|
+
|
73
|
+
## Add a test directory
|
74
|
+
|
75
|
+
In your Jekyll project's root folder, add a new `test/` directory
|
76
|
+
|
77
|
+
```shell
|
78
|
+
my-jekyll/
|
79
|
+
├── ...
|
80
|
+
├── test/
|
81
|
+
├── Gemfile
|
82
|
+
└── Rakefile
|
83
|
+
```
|
84
|
+
|
85
|
+
This is where you'll be adding all of your tests 😎.
|
86
|
+
|
87
|
+
|
88
|
+
## Add a test helper file
|
89
|
+
|
90
|
+
(Almost there, I promise). In your `test/` directory, add a new file called `helper.rb`:
|
91
|
+
|
92
|
+
```shell
|
93
|
+
my-jekyll/
|
94
|
+
├── ...
|
95
|
+
├── test/
|
96
|
+
│ └── helper.rb
|
97
|
+
├── Gemfile
|
98
|
+
└── Rakefile
|
99
|
+
```
|
100
|
+
|
101
|
+
There's a **bunch** of stuff you need to add to your `helper.rb`. The easiest thing you can do is copy everything from our [example `helper.rb` file](https://github.com/helpscout/jekyll-joule/blob/master/examples/test/helper.rb), and paste it into your `helper.rb` file ✌️.
|
102
|
+
|
103
|
+
That's it! Your Jekyll site is setup for testing 🎉
|
104
|
+
|
105
|
+
To confirm, run the following command:
|
106
|
+
|
107
|
+
`bundle exec rake test`
|
108
|
+
|
109
|
+
As long as you don't see a bunch of errors in your Terminal (😱), then you're good!
|
110
|
+
|
111
|
+
Next, let's start **[writing some tests!](./writing-tests.md)**!
|
data/examples/Gemfile
ADDED
data/examples/Rakefile
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'minitest/reporters'
|
4
|
+
require 'minitest/profile'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'rspec/mocks'
|
7
|
+
require 'jekyll'
|
8
|
+
require 'jekyll/joule'
|
9
|
+
require 'shoulda'
|
10
|
+
|
11
|
+
Jekyll.logger = Logger.new(StringIO.new)
|
12
|
+
|
13
|
+
include Jekyll
|
14
|
+
|
15
|
+
# Report with color.
|
16
|
+
Minitest::Reporters.use! [
|
17
|
+
Minitest::Reporters::SpecReporter.new(
|
18
|
+
:color => true
|
19
|
+
)
|
20
|
+
]
|
21
|
+
|
22
|
+
class JekyllUnitTest < Minitest::Test
|
23
|
+
include ::RSpec::Mocks::ExampleMethods
|
24
|
+
|
25
|
+
def setup
|
26
|
+
@site = Site.new(site_configuration)
|
27
|
+
@site.read
|
28
|
+
@site.generate
|
29
|
+
@site.render
|
30
|
+
|
31
|
+
@joule = Jekyll::Joule::Site.new(@site)
|
32
|
+
end
|
33
|
+
|
34
|
+
def mocks_expect(*args)
|
35
|
+
RSpec::Mocks::ExampleMethods::ExpectHost.instance_method(:expect).\
|
36
|
+
bind(self).call(*args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def before_setup
|
40
|
+
::RSpec::Mocks.setup
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
def after_teardown
|
45
|
+
super
|
46
|
+
::RSpec::Mocks.verify
|
47
|
+
ensure
|
48
|
+
::RSpec::Mocks.teardown
|
49
|
+
end
|
50
|
+
|
51
|
+
def fixture_site(overrides = {})
|
52
|
+
Jekyll::Site.new(site_configuration(overrides))
|
53
|
+
end
|
54
|
+
|
55
|
+
def build_configs(overrides, base_hash = Jekyll::Configuration::DEFAULTS)
|
56
|
+
Utils.deep_merge_hashes(base_hash, overrides)
|
57
|
+
.fix_common_issues.backwards_compatibilize.add_default_collections
|
58
|
+
end
|
59
|
+
|
60
|
+
def site_configuration(overrides = {})
|
61
|
+
full_overrides = build_configs(overrides, build_configs({
|
62
|
+
"destination" => dest_dir,
|
63
|
+
"incremental" => false
|
64
|
+
}))
|
65
|
+
build_configs({
|
66
|
+
"source" => source_dir
|
67
|
+
}, full_overrides)
|
68
|
+
end
|
69
|
+
|
70
|
+
def dest_dir(*subdirs)
|
71
|
+
root_dir('dest', *subdirs)
|
72
|
+
end
|
73
|
+
|
74
|
+
def source_dir(*subdirs)
|
75
|
+
root_dir('source', *subdirs)
|
76
|
+
end
|
77
|
+
|
78
|
+
def clear_dest
|
79
|
+
FileUtils.rm_rf(dest_dir)
|
80
|
+
FileUtils.rm_rf(source_dir('.jekyll-metadata'))
|
81
|
+
end
|
82
|
+
|
83
|
+
def root_dir(*subdirs)
|
84
|
+
File.join(File.dirname(__FILE__), *subdirs)
|
85
|
+
end
|
86
|
+
|
87
|
+
def directory_with_contents(path)
|
88
|
+
FileUtils.rm_rf(path)
|
89
|
+
FileUtils.mkdir(path)
|
90
|
+
File.open("#{path}/index.html", "w"){ |f| f.write("I was previously generated.") }
|
91
|
+
end
|
92
|
+
|
93
|
+
def with_env(key, value)
|
94
|
+
old_value = ENV[key]
|
95
|
+
ENV[key] = value
|
96
|
+
yield
|
97
|
+
ENV[key] = old_value
|
98
|
+
end
|
99
|
+
|
100
|
+
def capture_output
|
101
|
+
stderr = StringIO.new
|
102
|
+
Jekyll.logger = Logger.new stderr
|
103
|
+
yield
|
104
|
+
stderr.rewind
|
105
|
+
return stderr.string.to_s
|
106
|
+
end
|
107
|
+
alias_method :capture_stdout, :capture_output
|
108
|
+
alias_method :capture_stderr, :capture_output
|
109
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class ExampleTest < JekyllUnitTest
|
4
|
+
should "render a div" do
|
5
|
+
# 1. Write your markup
|
6
|
+
html = %Q[
|
7
|
+
<div class="aww">
|
8
|
+
Yiss
|
9
|
+
</div>
|
10
|
+
]
|
11
|
+
|
12
|
+
# 2. Pass it into Joule for rendering
|
13
|
+
@joule.render(html)
|
14
|
+
|
15
|
+
# 3. Find your HTML element(s)
|
16
|
+
el = @joule.find(".hello")
|
17
|
+
|
18
|
+
# 4. Write tests
|
19
|
+
assert(el)
|
20
|
+
assert(el.text.include?("Hello"))
|
21
|
+
assert(el["class"].include?("hello"))
|
22
|
+
end
|
23
|
+
end
|
data/jekyll-joule.gemspec
CHANGED
@@ -31,4 +31,6 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency "rspec-mocks"
|
32
32
|
spec.add_development_dependency "shoulda"
|
33
33
|
spec.add_development_dependency "kramdown"
|
34
|
+
spec.add_development_dependency "jekyll-jolt"
|
35
|
+
spec.add_development_dependency "jekyll-spark"
|
34
36
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Joule
|
5
|
+
class Page < Jekyll::Page
|
6
|
+
WHITESPACE_REGEXP = %r!^\s*!m
|
7
|
+
|
8
|
+
def unindent(content)
|
9
|
+
content.gsub!(/\A^\s*\n/, "")
|
10
|
+
if content =~ WHITESPACE_REGEXP
|
11
|
+
indentation = Regexp.last_match(0).length
|
12
|
+
content.gsub!(/^\ {#{indentation}}/, "")
|
13
|
+
end
|
14
|
+
|
15
|
+
return content
|
16
|
+
end
|
17
|
+
|
18
|
+
def reparse(content = "")
|
19
|
+
content = unindent(content)
|
20
|
+
if content =~ Jekyll::Document::YAML_FRONT_MATTER_REGEXP
|
21
|
+
self.content = %Q[\n#{$POSTMATCH.strip}\n]
|
22
|
+
self.data = SafeYAML.load(Regexp.last_match(1))
|
23
|
+
else
|
24
|
+
self.content = content
|
25
|
+
self.data = Hash.new
|
26
|
+
end
|
27
|
+
|
28
|
+
return self.content
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/jekyll/joule/site.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "jekyll"
|
2
|
+
require "jekyll/joule/page"
|
2
3
|
require "nokogiri"
|
3
4
|
|
4
5
|
module Jekyll
|
@@ -8,23 +9,36 @@ module Jekyll
|
|
8
9
|
|
9
10
|
def initialize(site)
|
10
11
|
@site = site
|
11
|
-
@
|
12
|
+
@data = false
|
12
13
|
@html = ""
|
13
14
|
@fixture_id = "joule-fixture"
|
15
|
+
@test_page_name = "test_joule.md"
|
16
|
+
|
17
|
+
return self
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_page
|
21
|
+
@site.pages.find {|p| p.name === @test_page_name}
|
22
|
+
end
|
23
|
+
|
24
|
+
def reset_page
|
25
|
+
@site.pages.delete_if {|p| p.name === @test_page_name}
|
14
26
|
end
|
15
27
|
|
16
28
|
def generate(page)
|
17
|
-
|
29
|
+
reset_page
|
30
|
+
@site.pages.push(page)
|
18
31
|
@site.render
|
19
32
|
|
20
|
-
return
|
33
|
+
return get_page
|
21
34
|
end
|
22
35
|
|
23
36
|
def render(content)
|
24
|
-
page = @site.
|
25
|
-
page.content
|
26
|
-
|
27
|
-
@
|
37
|
+
page = Jekyll::Joule::Page.new(@site, @site.source, "/", @test_page_name)
|
38
|
+
page.reparse(content)
|
39
|
+
page.content = %Q[<div id="#{@fixture_id}">#{page.content}</div>]
|
40
|
+
@data = generate(page)
|
41
|
+
@html = Nokogiri::HTML(@data["content"]).css(%Q[##{@fixture_id}])[0]
|
28
42
|
|
29
43
|
return self
|
30
44
|
end
|
@@ -38,7 +52,7 @@ module Jekyll
|
|
38
52
|
end
|
39
53
|
|
40
54
|
def find(selector)
|
41
|
-
find_all(selector)
|
55
|
+
find_all(selector).first
|
42
56
|
end
|
43
57
|
end
|
44
58
|
end
|
data/lib/jekyll/joule/version.rb
CHANGED
data/lib/jekyll/joule.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-joule
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ItsJonQ
|
@@ -150,6 +150,34 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: jekyll-jolt
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: jekyll-spark
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
153
181
|
description:
|
154
182
|
email:
|
155
183
|
- itsjonq@gmail.com
|
@@ -163,9 +191,18 @@ files:
|
|
163
191
|
- LICENSE.txt
|
164
192
|
- README.md
|
165
193
|
- Rakefile
|
194
|
+
- docs/introduction.md
|
195
|
+
- docs/setup.md
|
196
|
+
- examples/Gemfile
|
197
|
+
- examples/Rakefile
|
198
|
+
- examples/test/helper.rb
|
199
|
+
- examples/test/source/joule.md
|
200
|
+
- examples/test/test_example.rb
|
166
201
|
- jekyll-joule.gemspec
|
167
202
|
- lib/jekyll-joule.rb
|
203
|
+
- lib/jekyll/extensions/nokogiri_element.rb
|
168
204
|
- lib/jekyll/joule.rb
|
205
|
+
- lib/jekyll/joule/page.rb
|
169
206
|
- lib/jekyll/joule/site.rb
|
170
207
|
- lib/jekyll/joule/version.rb
|
171
208
|
homepage: https://github.com/helpscout/jekyll-joule
|