sweetie 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +30 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +16 -0
- data/Gemfile +3 -2
- data/README.md +224 -28
- data/Rakefile +3 -2
- data/lib/sweetie/bitbucket.rb +22 -197
- data/lib/sweetie/bitbucket_stati_helper.rb +247 -0
- data/lib/sweetie/conversion.rb +91 -62
- data/lib/sweetie/helper.rb +60 -51
- data/lib/sweetie/version.rb +2 -1
- data/lib/sweetie.rb +2 -2
- data/spec/fixtures/bitbucket/expected_repositories.txt +1 -0
- data/spec/fixtures/bitbucket/repositories.json +1 -0
- data/spec/fixtures/jekyll/_config.yml +4 -0
- data/spec/fixtures/jekyll/_config_repositories.yml +7 -0
- data/spec/fixtures/jekyll/_expected_config.yml +4 -0
- data/spec/{source → fixtures/jekyll}/site/404.html +0 -0
- data/spec/{source → fixtures/jekyll}/site/about.html +0 -0
- data/spec/{source → fixtures/jekyll}/site/archiv.html +0 -0
- data/spec/{source → fixtures/jekyll}/site/atom.xml +0 -0
- data/spec/{source → fixtures/jekyll}/site/colophon.html +0 -0
- data/spec/{source → fixtures/jekyll}/site/contact.html +0 -0
- data/spec/{source → fixtures/jekyll}/site/follow.html +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/2_avatars.gif +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/favicon.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/matthias_guenther.jpg +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/matthias_guenther_thumbnail_normal.jpg +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/matthias_guenther_thumbnail_small.jpg +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/closebox.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-caption-fill.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-caption-l.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-caption-r.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow1.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow2.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow3.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow4.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow5.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow6.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow7.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow8.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-1.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-10.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-11.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-12.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-2.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-3.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-4.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-5.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-6.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-7.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-8.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-9.png +0 -0
- data/spec/{source → fixtures/jekyll}/site/images/rails3.jpg +0 -0
- data/spec/{source → fixtures/jekyll}/site/index.html +0 -0
- data/spec/{source → fixtures/jekyll}/site/robots.txt +0 -0
- data/spec/{source → fixtures/jekyll}/site/sitemap.xml +0 -0
- data/spec/{source → fixtures/jekyll}/site/why-i-use-jekyll-for-blogging.html +0 -0
- data/spec/fixtures/middleman/build/2012-01-meetup/index.html +238 -0
- data/spec/fixtures/middleman/build/2012-03-meetup/index.html +217 -0
- data/spec/fixtures/middleman/build/2012-05-meetup/index.html +214 -0
- data/spec/fixtures/middleman/build/2012-07-meetup/index.html +210 -0
- data/spec/fixtures/middleman/build/2012-08-workshop/index.html +228 -0
- data/spec/fixtures/middleman/build/2012-09-meetup/index.html +231 -0
- data/spec/fixtures/middleman/build/2012-10-workshop/index.html +227 -0
- data/spec/fixtures/middleman/build/2012-11-meetup/index.html +229 -0
- data/spec/fixtures/middleman/build/2012-unusual-december-meetup/index.html +186 -0
- data/spec/fixtures/middleman/build/2013-01-meetup/index.html +226 -0
- data/spec/fixtures/middleman/build/404/index.html +157 -0
- data/spec/fixtures/middleman/build/CNAME +1 -0
- data/spec/fixtures/middleman/build/april-2014-meetup/index.html +221 -0
- data/spec/fixtures/middleman/build/april-2015-meetup/index.html +204 -0
- data/spec/fixtures/middleman/build/april-2017-meetup/index.html +210 -0
- data/spec/fixtures/middleman/build/assets/favicons/android-chrome-144x144.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/android-chrome-192x192.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/android-chrome-36x36.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/android-chrome-48x48.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/android-chrome-72x72.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/android-chrome-96x96.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-114x114.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-120x120.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-144x144.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-152x152.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-180x180.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-57x57.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-60x60.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-72x72.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-76x76.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-precomposed.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/browserconfig.xml +12 -0
- data/spec/fixtures/middleman/build/assets/favicons/favicon-16x16.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/favicon-32x32.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/favicon-96x96.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/favicon.ico +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/manifest.json +41 -0
- data/spec/fixtures/middleman/build/assets/favicons/mstile-144x144.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/mstile-150x150.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/mstile-310x150.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/mstile-310x310.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/mstile-70x70.png +0 -0
- data/spec/fixtures/middleman/build/assets/favicons/safari-pinned-tab.svg +450 -0
- data/spec/fixtures/middleman/build/assets/images/launch_co_logo.png +0 -0
- data/spec/fixtures/middleman/build/assets/images/vimfest.png +0 -0
- data/spec/fixtures/middleman/build/assets/javascripts/application.js +12 -0
- data/spec/fixtures/middleman/build/assets/javascripts/jquery.utils.js +12 -0
- data/spec/fixtures/middleman/build/assets/javascripts/lib/validate.js +1 -0
- data/spec/fixtures/middleman/build/assets/stylesheets/application.css +5 -0
- data/spec/fixtures/middleman/build/assets/stylesheets/vendor/bootstrap.css +5 -0
- data/spec/fixtures/middleman/build/august-2013-meetup/index.html +208 -0
- data/spec/fixtures/middleman/build/blog/index.html +500 -0
- data/spec/fixtures/middleman/build/book-club-about-the-viml-primer/index.html +182 -0
- data/spec/fixtures/middleman/build/contact/index.html +155 -0
- data/spec/fixtures/middleman/build/data/vimberlin-2013-09_ctags/index.html +98 -0
- data/spec/fixtures/middleman/build/data/vimberlin-2013-09_vimprofiling/index.html +157 -0
- data/spec/fixtures/middleman/build/data/vimberlin-2014-01_vim_writing/index.html +70 -0
- data/spec/fixtures/middleman/build/december-2015-meetup/index.html +199 -0
- data/spec/fixtures/middleman/build/december-2016-meetup/index.html +224 -0
- data/spec/fixtures/middleman/build/february-2013-vim-beer-lin/index.html +190 -0
- data/spec/fixtures/middleman/build/february-2015-meetup/index.html +233 -0
- data/spec/fixtures/middleman/build/february-2016-meetup/index.html +271 -0
- data/spec/fixtures/middleman/build/feed.xml +2106 -0
- data/spec/fixtures/middleman/build/fonts/FontAwesome.otf +0 -0
- data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.eot +0 -0
- data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.svg +655 -0
- data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.ttf +0 -0
- data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.woff +0 -0
- data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.woff2 +0 -0
- data/spec/fixtures/middleman/build/humans.txt +12 -0
- data/spec/fixtures/middleman/build/imprint/index.html +177 -0
- data/spec/fixtures/middleman/build/index.html +157 -0
- data/spec/fixtures/middleman/build/january-2014-meetup/index.html +257 -0
- data/spec/fixtures/middleman/build/january-2015-meetup/index.html +243 -0
- data/spec/fixtures/middleman/build/january-2016-meetup/index.html +202 -0
- data/spec/fixtures/middleman/build/january-2017-meetup/index.html +228 -0
- data/spec/fixtures/middleman/build/july-2015-meetup/index.html +207 -0
- data/spec/fixtures/middleman/build/june-2016-meetup/index.html +260 -0
- data/spec/fixtures/middleman/build/march-2-2017-meetup/index.html +201 -0
- data/spec/fixtures/middleman/build/march-2014-meetup/index.html +219 -0
- data/spec/fixtures/middleman/build/march-2016-meetup/index.html +221 -0
- data/spec/fixtures/middleman/build/march-2017-meetup/index.html +222 -0
- data/spec/fixtures/middleman/build/may-2013-meetup/index.html +234 -0
- data/spec/fixtures/middleman/build/may-2014-meetup/index.html +198 -0
- data/spec/fixtures/middleman/build/may-2015-meetup/index.html +202 -0
- data/spec/fixtures/middleman/build/may-2016-meetup/index.html +245 -0
- data/spec/fixtures/middleman/build/newsletter/index.html +171 -0
- data/spec/fixtures/middleman/build/november-2013-meetup/index.html +199 -0
- data/spec/fixtures/middleman/build/november-2015-meetup/index.html +402 -0
- data/spec/fixtures/middleman/build/november-2016-meetup/index.html +224 -0
- data/spec/fixtures/middleman/build/october-2013-meetup/index.html +210 -0
- data/spec/fixtures/middleman/build/october-2014-meetup/index.html +196 -0
- data/spec/fixtures/middleman/build/october-2016-meetup/index.html +222 -0
- data/spec/fixtures/middleman/build/robots.txt +6 -0
- data/spec/fixtures/middleman/build/september-2013-meetup/index.html +225 -0
- data/spec/fixtures/middleman/build/september-2014-meetup/index.html +211 -0
- data/spec/fixtures/middleman/build/sitemap.xml +297 -0
- data/spec/fixtures/middleman/build/vimfest-october-2015/index.html +303 -0
- data/spec/fixtures/middleman/config.rb +4 -0
- data/spec/fixtures/middleman/config_repositories.rb +7 -0
- data/spec/fixtures/middleman/expected_config.rb +4 -0
- data/spec/spec_helper.rb +2 -2
- data/spec/sweetie_bitbucket_spec.rb +26 -51
- data/spec/sweetie_bitbucket_stati_helper_spec.rb +124 -0
- data/spec/sweetie_conversion_spec.rb +105 -17
- data/spec/sweetie_helper_spec.rb +140 -0
- data/sweetie.gemspec +10 -9
- metadata +163 -56
- data/.travis.yml +0 -7
- data/spec/source/_config.yml +0 -18
- data/spec/source/bitbucket/user_repositories.json +0 -161
- data/spec/source/bitbucket/user_repositories_expectation.txt +0 -1
@@ -1,57 +1,32 @@
|
|
1
1
|
require 'sweetie/bitbucket'
|
2
|
+
require 'sweetie/bitbucket_stati_helper'
|
2
3
|
|
3
4
|
describe Sweetie::Bitbucket do
|
4
|
-
let(:current_dir) {File.dirname(__FILE__)}
|
5
|
-
let(:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should parse a timestamp" do
|
32
|
-
timestamp = %Q(2011-04-20 11:31:39)
|
33
|
-
expect(bitbucket.parse_timestamp(timestamp)).to eq "2011-04-20"
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should create a string representation of a repository" do
|
37
|
-
repository = {"pmwiki" => "2011-10-26"}
|
38
|
-
expect(bitbucket.entry_text(repository.keys.first, repository.values.first)).to eq "pmwiki: 2011-10-26"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should repositories changes write_repository_changes" do
|
42
|
-
hash = {"svn" => "2011-10-26", "pmwiki" => "2011-10-26"}
|
43
|
-
bitbucket.config = config
|
44
|
-
bitbucket.write_repository_changes(hash)
|
45
|
-
config_yml_content = File.open(config).read
|
46
|
-
expect(config_yml_content).to include "svn: 2011-10-26"
|
47
|
-
expect(config_yml_content).to include "pmwiki: 2011-10-26"
|
48
|
-
|
49
|
-
# remove variables from the text-file
|
50
|
-
text = config_yml_content.gsub!("svn: 2011-10-26\n", "")
|
51
|
-
text = config_yml_content.gsub!("pmwiki: 2011-10-26\n", "")
|
52
|
-
config_yml_content = File.open(config, "w")
|
53
|
-
config_yml_content.puts text
|
54
|
-
config_yml_content.close
|
5
|
+
let(:current_dir) { File.dirname(__FILE__) }
|
6
|
+
let(:repositories) { File.join(current_dir, 'fixtures', 'bitbucket', 'repositories.json') }
|
7
|
+
|
8
|
+
subject { Sweetie::Bitbucket.new }
|
9
|
+
|
10
|
+
it 'will update_stati' do
|
11
|
+
bitbucket_stati_helper = double('BitbucketStatiHelper')
|
12
|
+
|
13
|
+
expected_repositories = File.open(repositories)
|
14
|
+
expected_changesets = { 'pmwiki-linkicons-recipe' => '2017-02-26',
|
15
|
+
'pmwiki-dropcaps-recipe' => '2017-02-24',
|
16
|
+
'pmwiki-headlineimage-recipe' => '2017-02-25',
|
17
|
+
'pmwiki-syntaxlove-recipe' => '2017-02-26',
|
18
|
+
'pmwiki-twitter-recipe' => '2017-02-26',
|
19
|
+
'presentations' => '2017-01-15',
|
20
|
+
'vocabularly' => '2013-01-26',
|
21
|
+
'ruby-scripts' => '2014-05-25',
|
22
|
+
'rails-sample-app' => '2013-01-26' }
|
23
|
+
|
24
|
+
expect(bitbucket_stati_helper).to receive(:get_repositories) { expected_repositories }
|
25
|
+
expect(bitbucket_stati_helper).to receive(:get_repositories_changes).with(expected_repositories) { expected_changesets }
|
26
|
+
expect(bitbucket_stati_helper).to receive(:write_repository_changes).with(expected_changesets)
|
27
|
+
|
28
|
+
subject = Sweetie::Bitbucket.new(bitbucket_stati_helper)
|
29
|
+
subject.update_stati
|
55
30
|
end
|
56
31
|
end
|
57
32
|
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'sweetie/bitbucket_stati_helper'
|
2
|
+
|
3
|
+
describe Sweetie::BitbucketStatiHelper do
|
4
|
+
let(:current_dir) { File.dirname(__FILE__) }
|
5
|
+
let(:repositories) { File.join(current_dir, 'fixtures', 'bitbucket', 'repositories.json') }
|
6
|
+
|
7
|
+
let(:expected_repositories) { File.join(current_dir, 'fixtures', 'bitbucket', 'expected_repositories.txt') }
|
8
|
+
# let(:site_dir) { File.join(current_dir, 'fixtures', 'jekyll', 'site') }
|
9
|
+
# let(:svn_hash) { { svn: '2011-10-16' } }
|
10
|
+
|
11
|
+
subject { Sweetie::BitbucketStatiHelper.new }
|
12
|
+
|
13
|
+
it 'parses a json file' do
|
14
|
+
# gsub replace trailing newline at the end of the file
|
15
|
+
changeset_expectation = File.open(expected_repositories).read.delete("\n")
|
16
|
+
changeset = File.open(repositories).read
|
17
|
+
changeset = subject.parse_json(changeset).to_s
|
18
|
+
expect(changeset).to eq changeset_expectation
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'creates a string representation of a repository for middleman config' do
|
22
|
+
repository = { pmwiki: '2011-10-26' }
|
23
|
+
expect(subject.entry_text_middleman(repository.keys.first, repository.values.first)).to eq 'set :pmwiki, 2011-10-26'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'creates a string representation of a repository for jekyll config' do
|
27
|
+
repository = { pmwiki: '2011-10-26' }
|
28
|
+
expect(subject.entry_text_jekyll(repository.keys.first, repository.values.first)).to eq 'pmwiki: 2011-10-26'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'parses a timestamp' do
|
32
|
+
timestamp = '2011-04-20 11:31:39'
|
33
|
+
expect(subject.parse_timestamp(timestamp)).to eq '2011-04-20'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'gets the changesets of the repositories only with name' do
|
37
|
+
json_repositories = File.open(repositories).read
|
38
|
+
expected_names = ['pmwiki-linkicons-recipe',
|
39
|
+
'pmwiki-dropcaps-recipe',
|
40
|
+
'pmwiki-headlineimage-recipe',
|
41
|
+
'pmwiki-syntaxlove-recipe',
|
42
|
+
'pmwiki-twitter-recipe',
|
43
|
+
'presentations',
|
44
|
+
'vocabularly',
|
45
|
+
'ruby-scripts',
|
46
|
+
'rails-sample-app']
|
47
|
+
expect(subject.get_repositories_changes(json_repositories).keys).to eq expected_names
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'get the changesets of the repositories with name and date' do
|
51
|
+
json_repositories = File.open(repositories).read
|
52
|
+
expected_changesets = { 'pmwiki-linkicons-recipe' => '2017-02-26',
|
53
|
+
'pmwiki-dropcaps-recipe' => '2017-02-24',
|
54
|
+
'pmwiki-headlineimage-recipe' => '2017-02-25',
|
55
|
+
'pmwiki-syntaxlove-recipe' => '2017-02-26',
|
56
|
+
'pmwiki-twitter-recipe' => '2017-02-26',
|
57
|
+
'presentations' => '2017-01-15',
|
58
|
+
'vocabularly' => '2013-01-26',
|
59
|
+
'ruby-scripts' => '2014-05-25',
|
60
|
+
'rails-sample-app' => '2013-01-26' }
|
61
|
+
expect(subject.get_repositories_changes(json_repositories)).to eq expected_changesets
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'do not writes repository changes to config file for jekyll project if entries are not in there' do
|
65
|
+
hash = { svn: '2011-10-26', pmwiki: '2011-10-26' }
|
66
|
+
config = File.join(current_dir, 'fixtures', 'jekyll', '_config.yml')
|
67
|
+
|
68
|
+
subject.config = config
|
69
|
+
subject.write_repository_changes(hash)
|
70
|
+
config_yml_content = File.open(config).read
|
71
|
+
|
72
|
+
expect(config_yml_content).not_to include 'svn: 2011-10-26'
|
73
|
+
expect(config_yml_content).not_to include 'pmwiki: 2011-10-26'
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'writes repository changes to config file for jekyll project if entries are in config file' do
|
77
|
+
hash = { svn: '2017-10-26', pmwiki: '2017-10-26' }
|
78
|
+
config = File.join(current_dir, 'fixtures', 'jekyll', '_config_repositories.yml')
|
79
|
+
|
80
|
+
subject.config = config
|
81
|
+
subject.write_repository_changes(hash)
|
82
|
+
config_yml_content = File.open(config).read
|
83
|
+
|
84
|
+
expect(config_yml_content).to include 'svn: 2017-10-26'
|
85
|
+
expect(config_yml_content).to include 'pmwiki: 2017-10-26'
|
86
|
+
|
87
|
+
# remove variables from the text-file
|
88
|
+
text = config_yml_content.gsub('pmwiki: 2017-10-26', 'pmwiki: 2011-10-26').gsub('svn: 2017-10-26', 'svn: 2011-10-26')
|
89
|
+
config_yml_content = File.open(config, 'w')
|
90
|
+
config_yml_content.puts text
|
91
|
+
config_yml_content.close
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'do not writes repository changes to config file for middleman project if entries are not in there' do
|
95
|
+
hash = { svn: '2011-10-26', pmwiki: '2011-10-26' }
|
96
|
+
config = File.join(current_dir, 'fixtures', 'middleman', 'config.rb')
|
97
|
+
|
98
|
+
subject.config = config
|
99
|
+
subject.write_repository_changes(hash)
|
100
|
+
config_yml_content = File.open(config).read
|
101
|
+
|
102
|
+
expect(config_yml_content).not_to include 'set :svn, 2011-10-26'
|
103
|
+
expect(config_yml_content).not_to include 'set :pmwiki, 2011-10-26'
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'writes repository changes to config file for middleman project if entries are in config file' do
|
107
|
+
hash = { :svn => '2017-10-26', 'pmwiki-dropcaps-recipe' => '2017-10-26' }
|
108
|
+
config = File.join(current_dir, 'fixtures', 'middleman', 'config_repositories.rb')
|
109
|
+
|
110
|
+
subject.config = config
|
111
|
+
subject.write_repository_changes(hash)
|
112
|
+
config_yml_content = File.open(config).read
|
113
|
+
|
114
|
+
expect(config_yml_content).to include 'set :svn, 2017-10-26'
|
115
|
+
expect(config_yml_content).to include 'set :pmwiki_dropcaps_recipe, 2017-10-26'
|
116
|
+
|
117
|
+
# remove variables from the text-file
|
118
|
+
text = config_yml_content.gsub('set :pmwiki_dropcaps_recipe, 2017-10-26', 'set :pmwiki_dropcaps_recipe, 2011-10-26').gsub('set :svn, 2017-10-26', 'set :svn, 2011-10-26')
|
119
|
+
config_yml_content = File.open(config, 'w')
|
120
|
+
config_yml_content.puts text
|
121
|
+
config_yml_content.close
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
@@ -1,29 +1,117 @@
|
|
1
1
|
require 'sweetie/conversion'
|
2
2
|
|
3
3
|
describe Sweetie::Conversion do
|
4
|
-
let(:current_dir) {File.dirname(__FILE__)}
|
5
|
-
let(:about_page) {File.join(current_dir, 'source', 'site', 'about.html')}
|
6
|
-
let(:site_dir) {File.join(current_dir, 'source', 'site')}
|
7
|
-
let(:sweetie) {Sweetie::Conversion}
|
4
|
+
let(:current_dir) { File.dirname(__FILE__) }
|
8
5
|
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
describe 'Jekyll project' do
|
7
|
+
let(:site_dir) { File.join(current_dir, 'fixtures', 'jekyll', 'site') }
|
8
|
+
let(:about_page) { File.join(site_dir, 'about.html') }
|
9
|
+
let(:site_config) { File.join(current_dir, 'fixtures', 'jekyll', '_config.yml') }
|
10
|
+
let(:sweetie) { Sweetie::Conversion.new(site_dir, site_config) }
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
it 'should count links of about.html page' do
|
13
|
+
expect(sweetie.count_link_of_one_page(about_page)).to eq(11)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
it 'should count images of about.html page' do
|
17
|
+
expect(sweetie.count_images_of_one_page(about_page)).to eq 1
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should count all html pages' do
|
21
|
+
expect(sweetie.count_all_html_pages(site_dir)).to eq 8
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should count all links of all pages' do
|
25
|
+
expect(sweetie.count_all_links(site_dir)).to eq 54
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should count all images' do
|
29
|
+
expect(sweetie.count_all_images(site_dir)).to eq 1
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'creates the correct build-time' do
|
33
|
+
time = Time.now
|
34
|
+
expected_time = "#{time.month}-#{time.day}-#{time.year}"
|
35
|
+
allow(time).to receive(:now).and_return(time)
|
36
|
+
expect(sweetie.build_time).to eq expected_time
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'does create stati for jekyll project' do
|
40
|
+
config_yml_file = File.open(site_config, 'w')
|
41
|
+
default_text = <<TEXT
|
42
|
+
htmlpages:
|
43
|
+
images:
|
44
|
+
links:
|
45
|
+
|
46
|
+
TEXT
|
47
|
+
config_yml_file.write(default_text)
|
48
|
+
config_yml_file.close
|
49
|
+
|
50
|
+
sweetie.create_stati
|
51
|
+
|
52
|
+
config_yml_file = File.open(site_config).readlines
|
53
|
+
expected_config = File.open(File.join(current_dir, 'fixtures', 'jekyll', '_expected_config.yml')).readlines
|
54
|
+
|
55
|
+
result = true
|
56
|
+
config_yml_file.each do |e|
|
57
|
+
result = false unless expected_config.include? e
|
58
|
+
end
|
20
59
|
|
21
|
-
|
22
|
-
|
60
|
+
expect(result).to be_truthy
|
61
|
+
end
|
23
62
|
end
|
24
63
|
|
25
|
-
|
26
|
-
|
64
|
+
describe 'Middleman project' do
|
65
|
+
let(:build_dir) { File.join(current_dir, 'fixtures', 'middleman', 'build') }
|
66
|
+
let(:site_config) { File.join(current_dir, 'fixtures', 'middleman', 'config.rb') }
|
67
|
+
let(:index_page) { File.join(build_dir, 'index.html') }
|
68
|
+
let(:sweetie) { Sweetie::Conversion.new(build_dir, File.join(current_dir, 'fixtures', 'middleman', 'config.rb')) }
|
69
|
+
|
70
|
+
subject { sweetie }
|
71
|
+
|
72
|
+
it 'should count links of index-fixtues page' do
|
73
|
+
expect(subject.count_link_of_one_page(index_page)).to eq 13
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should count images of index-fixtures page' do
|
77
|
+
expect(subject.count_images_of_one_page(index_page)).to eq 2
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should count all html pages' do
|
81
|
+
expect(subject.count_all_html_pages(build_dir)).to eq 52
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should count all links of all pages' do
|
85
|
+
expect(subject.count_all_links(build_dir)).to eq 405
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should count all images' do
|
89
|
+
expect(subject.count_all_images(build_dir)).to eq 10
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'does create stati for middleman project' do
|
93
|
+
config_yml_file = File.open(site_config, 'w')
|
94
|
+
default_text = <<TEXT
|
95
|
+
set :htmlpages,
|
96
|
+
set :images,
|
97
|
+
set :links,
|
98
|
+
|
99
|
+
TEXT
|
100
|
+
config_yml_file.write(default_text)
|
101
|
+
config_yml_file.close
|
102
|
+
|
103
|
+
sweetie.create_stati
|
104
|
+
|
105
|
+
config_yml_file = File.open(site_config).readlines
|
106
|
+
expected_config = File.open(File.join(current_dir, 'fixtures', 'middleman', 'expected_config.rb')).readlines
|
107
|
+
|
108
|
+
result = true
|
109
|
+
config_yml_file.each do |e|
|
110
|
+
result = false if !expected_config.include?(e) || e.empty?
|
111
|
+
end
|
112
|
+
|
113
|
+
expect(result).to be_truthy
|
114
|
+
end
|
27
115
|
end
|
28
116
|
end
|
29
117
|
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'sweetie/helper'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'Sweetie Helper' do
|
6
|
+
let(:helper) { Class.new }
|
7
|
+
|
8
|
+
before { helper.extend Sweetie::Helper }
|
9
|
+
subject { helper }
|
10
|
+
|
11
|
+
describe '#perform_search_for_single_page' do
|
12
|
+
it 'search after all links for the file directory and return the number of found entries' do
|
13
|
+
file = double(File)
|
14
|
+
file_content = '<a href="/index.html">wikimatze</a>'
|
15
|
+
|
16
|
+
expect(File).to receive(:open).with(file).and_return(file_content)
|
17
|
+
|
18
|
+
expect(subject.perform_search_for_single_page('//a', [], file)).to eql 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#perform_global_search' do
|
23
|
+
it 'search after all links for the given directory and return the number of found entries' do
|
24
|
+
file = 'test.html'
|
25
|
+
expect(Dir).to receive(:glob).with('test/**/*').and_yield file
|
26
|
+
|
27
|
+
file_content = '<a href="/index.html">wikimatze</a>'
|
28
|
+
expect(File).to receive(:open).with(file).and_return(file_content)
|
29
|
+
|
30
|
+
expect(subject.perform_global_search('//a', [], 'test')).to eql 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#check_directory_and_config_file' do
|
35
|
+
let(:site_dir) { File.join(File.dirname(__FILE__), 'fixtures', 'jekyll', 'site') }
|
36
|
+
let(:about_page) { File.join(site_dir, 'about.html') }
|
37
|
+
|
38
|
+
it 'raise an error if dir folder does not exists' do
|
39
|
+
expect { subject.check_directory_and_config_file('not_here/', about_page) }.to \
|
40
|
+
raise_error.with_message("Can't find the _config.yml or the _site directory! Please create these files it!")
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'raise an error if config file does not exists' do
|
44
|
+
expect { subject.check_directory_and_config_file(site_dir, 'not_there.txt') }.to \
|
45
|
+
raise_error.with_message("Can't find the _config.yml or the _site directory! Please create these files it!")
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'raise no error if dir and config file exists' do
|
49
|
+
expect { subject.check_directory_and_config_file(site_dir, about_page) }.not_to \
|
50
|
+
raise_error.with_message("Can't find the _config.yml or the _site directory! Please create these files it!")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#traverse' do
|
55
|
+
it 'harvest all the information of html files for the given directory' do
|
56
|
+
file = 'test.html'
|
57
|
+
allow(file)
|
58
|
+
expect(Dir).to receive(:glob).with('test/**/*').and_yield file
|
59
|
+
|
60
|
+
file_content = '<a href="/index.html">wikimatze</a>'
|
61
|
+
expect(File).to receive(:open).with(file).and_return(file_content)
|
62
|
+
|
63
|
+
expected_result = ['wikimatze']
|
64
|
+
expect(subject.traverse('//a', [], 'test')).to eql expected_result
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'will not harvest information for text files only the given directory' do
|
68
|
+
file = 'test.txt'
|
69
|
+
allow(file)
|
70
|
+
expect(Dir).to receive(:glob).with('test/**/*').and_yield file
|
71
|
+
|
72
|
+
expect(File).to_not receive(:open).with(file)
|
73
|
+
expect(subject.traverse('//a', [], 'test')).to be_nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#write_config' do
|
78
|
+
it 'write results into file' do
|
79
|
+
file = double(File)
|
80
|
+
|
81
|
+
expect(File).to receive(:open).with(file, 'w').and_yield file
|
82
|
+
expect(file).to receive(:puts).with('Hello config')
|
83
|
+
expect(file).to receive(:close)
|
84
|
+
|
85
|
+
subject.write_config(file, 'Hello config')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#output_count' do
|
90
|
+
it 'returns the number of arguments in the given array' do
|
91
|
+
test_array = %w[1 2 3]
|
92
|
+
expect(subject.output_count(test_array)).to eql 3
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns the number of arguments in the given array and remove duplicates' do
|
96
|
+
test_aray = [1, 1, 2, 2, 3, 3]
|
97
|
+
expect(subject.output_count(test_aray)).to eql 3
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#harvest' do
|
102
|
+
it 'find all links' do
|
103
|
+
file = double(File)
|
104
|
+
file_content = <<-TEXT
|
105
|
+
<a href="/index.html">wikimatze</a>
|
106
|
+
<a href="http://0.0.0:4000/contact.html" title="contact me">contact me</a>
|
107
|
+
TEXT
|
108
|
+
expect(File).to receive(:open).with(file).and_return(file_content)
|
109
|
+
|
110
|
+
result = []
|
111
|
+
expected_result = ['wikimatze', 'contact me']
|
112
|
+
expect(subject.harvest('//a', file, result)).to eql expected_result
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'find all images' do
|
116
|
+
file = double(File)
|
117
|
+
file_content = <<-TEXT
|
118
|
+
<img src="/images/images-global/matthias_guenther_thumbnail_small.jpg" style="float:right;"/>
|
119
|
+
TEXT
|
120
|
+
|
121
|
+
expect(File).to receive(:open).with(file).and_return(file_content)
|
122
|
+
|
123
|
+
result = []
|
124
|
+
expected_result = ['<img src="/images/images-global/matthias_guenther_thumbnail_small.jpg" style="float:right;">']
|
125
|
+
expect(subject.harvest('//img', file, result)).to eql expected_result
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'find all html pages' do
|
129
|
+
file = double(File)
|
130
|
+
file_content = <<-TEXT
|
131
|
+
test
|
132
|
+
TEXT
|
133
|
+
|
134
|
+
expect(File).to receive(:open).with(file).and_return(file_content)
|
135
|
+
|
136
|
+
expect(subject.harvest('//html', file, []).count).to eql 1
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
data/sweetie.gemspec
CHANGED
@@ -1,28 +1,29 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
2
|
require 'sweetie/version'
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'sweetie'
|
6
6
|
s.version = Sweetie::VERSION
|
7
7
|
s.date = '2012-07-15'
|
8
|
+
s.licenses = ['MIT']
|
8
9
|
s.authors = ['Matthias Guenther']
|
9
10
|
s.email = 'matthias@wikimatze.de'
|
10
11
|
s.homepage = 'https://github.com/wikimatze/sweetie'
|
11
|
-
s.summary =
|
12
|
+
s.summary = 'Count links, images, number of html pages, and last-build time of a
|
12
13
|
jekyll project. In addition it can get last updates of all bitbucket
|
13
|
-
repositories of a user.
|
14
|
+
repositories of a user.'
|
14
15
|
|
15
|
-
s.description =
|
16
|
+
s.description = 'Sweetie counts the links, images, number of html pages, and last-build
|
16
17
|
time of a jekyll project. In addition it can get the last changes of all
|
17
|
-
bitbuckets repositories of a user.
|
18
|
+
bitbuckets repositories of a user.'
|
18
19
|
s.files = `git ls-files`.split("\n")
|
19
|
-
s.test_files = `git ls-files -- {test,spec
|
20
|
+
s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
20
21
|
|
21
22
|
s.extra_rdoc_files = ['README.md']
|
22
23
|
|
23
|
-
s.add_runtime_dependency 'nokogiri', '~> 1.
|
24
|
-
s.add_runtime_dependency 'json', '~>
|
25
|
-
s.add_development_dependency 'rake', '~>
|
24
|
+
s.add_runtime_dependency 'nokogiri', '~> 1.12'
|
25
|
+
s.add_runtime_dependency 'json', '~> 2.3'
|
26
|
+
s.add_development_dependency 'rake', '~> 12.3'
|
26
27
|
s.add_development_dependency 'rspec', '~> 3.3'
|
27
28
|
end
|
28
29
|
|