sweetie 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +30 -0
  3. data/.gitignore +3 -0
  4. data/.rubocop.yml +16 -0
  5. data/Gemfile +3 -2
  6. data/README.md +224 -28
  7. data/Rakefile +3 -2
  8. data/lib/sweetie/bitbucket.rb +22 -197
  9. data/lib/sweetie/bitbucket_stati_helper.rb +247 -0
  10. data/lib/sweetie/conversion.rb +91 -62
  11. data/lib/sweetie/helper.rb +60 -51
  12. data/lib/sweetie/version.rb +2 -1
  13. data/lib/sweetie.rb +2 -2
  14. data/spec/fixtures/bitbucket/expected_repositories.txt +1 -0
  15. data/spec/fixtures/bitbucket/repositories.json +1 -0
  16. data/spec/fixtures/jekyll/_config.yml +4 -0
  17. data/spec/fixtures/jekyll/_config_repositories.yml +7 -0
  18. data/spec/fixtures/jekyll/_expected_config.yml +4 -0
  19. data/spec/{source → fixtures/jekyll}/site/404.html +0 -0
  20. data/spec/{source → fixtures/jekyll}/site/about.html +0 -0
  21. data/spec/{source → fixtures/jekyll}/site/archiv.html +0 -0
  22. data/spec/{source → fixtures/jekyll}/site/atom.xml +0 -0
  23. data/spec/{source → fixtures/jekyll}/site/colophon.html +0 -0
  24. data/spec/{source → fixtures/jekyll}/site/contact.html +0 -0
  25. data/spec/{source → fixtures/jekyll}/site/follow.html +0 -0
  26. data/spec/{source → fixtures/jekyll}/site/images/2_avatars.gif +0 -0
  27. data/spec/{source → fixtures/jekyll}/site/images/favicon.png +0 -0
  28. data/spec/{source → fixtures/jekyll}/site/images/images-global/matthias_guenther.jpg +0 -0
  29. data/spec/{source → fixtures/jekyll}/site/images/images-global/matthias_guenther_thumbnail_normal.jpg +0 -0
  30. data/spec/{source → fixtures/jekyll}/site/images/images-global/matthias_guenther_thumbnail_small.jpg +0 -0
  31. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/closebox.png +0 -0
  32. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-caption-fill.png +0 -0
  33. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-caption-l.png +0 -0
  34. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-caption-r.png +0 -0
  35. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow1.png +0 -0
  36. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow2.png +0 -0
  37. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow3.png +0 -0
  38. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow4.png +0 -0
  39. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow5.png +0 -0
  40. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow6.png +0 -0
  41. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow7.png +0 -0
  42. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-shadow8.png +0 -0
  43. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-1.png +0 -0
  44. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-10.png +0 -0
  45. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-11.png +0 -0
  46. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-12.png +0 -0
  47. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-2.png +0 -0
  48. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-3.png +0 -0
  49. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-4.png +0 -0
  50. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-5.png +0 -0
  51. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-6.png +0 -0
  52. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-7.png +0 -0
  53. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-8.png +0 -0
  54. data/spec/{source → fixtures/jekyll}/site/images/images-global/zoom/zoom-spin-9.png +0 -0
  55. data/spec/{source → fixtures/jekyll}/site/images/rails3.jpg +0 -0
  56. data/spec/{source → fixtures/jekyll}/site/index.html +0 -0
  57. data/spec/{source → fixtures/jekyll}/site/robots.txt +0 -0
  58. data/spec/{source → fixtures/jekyll}/site/sitemap.xml +0 -0
  59. data/spec/{source → fixtures/jekyll}/site/why-i-use-jekyll-for-blogging.html +0 -0
  60. data/spec/fixtures/middleman/build/2012-01-meetup/index.html +238 -0
  61. data/spec/fixtures/middleman/build/2012-03-meetup/index.html +217 -0
  62. data/spec/fixtures/middleman/build/2012-05-meetup/index.html +214 -0
  63. data/spec/fixtures/middleman/build/2012-07-meetup/index.html +210 -0
  64. data/spec/fixtures/middleman/build/2012-08-workshop/index.html +228 -0
  65. data/spec/fixtures/middleman/build/2012-09-meetup/index.html +231 -0
  66. data/spec/fixtures/middleman/build/2012-10-workshop/index.html +227 -0
  67. data/spec/fixtures/middleman/build/2012-11-meetup/index.html +229 -0
  68. data/spec/fixtures/middleman/build/2012-unusual-december-meetup/index.html +186 -0
  69. data/spec/fixtures/middleman/build/2013-01-meetup/index.html +226 -0
  70. data/spec/fixtures/middleman/build/404/index.html +157 -0
  71. data/spec/fixtures/middleman/build/CNAME +1 -0
  72. data/spec/fixtures/middleman/build/april-2014-meetup/index.html +221 -0
  73. data/spec/fixtures/middleman/build/april-2015-meetup/index.html +204 -0
  74. data/spec/fixtures/middleman/build/april-2017-meetup/index.html +210 -0
  75. data/spec/fixtures/middleman/build/assets/favicons/android-chrome-144x144.png +0 -0
  76. data/spec/fixtures/middleman/build/assets/favicons/android-chrome-192x192.png +0 -0
  77. data/spec/fixtures/middleman/build/assets/favicons/android-chrome-36x36.png +0 -0
  78. data/spec/fixtures/middleman/build/assets/favicons/android-chrome-48x48.png +0 -0
  79. data/spec/fixtures/middleman/build/assets/favicons/android-chrome-72x72.png +0 -0
  80. data/spec/fixtures/middleman/build/assets/favicons/android-chrome-96x96.png +0 -0
  81. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-114x114.png +0 -0
  82. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-120x120.png +0 -0
  83. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-144x144.png +0 -0
  84. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-152x152.png +0 -0
  85. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-180x180.png +0 -0
  86. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-57x57.png +0 -0
  87. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-60x60.png +0 -0
  88. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-72x72.png +0 -0
  89. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-76x76.png +0 -0
  90. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon-precomposed.png +0 -0
  91. data/spec/fixtures/middleman/build/assets/favicons/apple-touch-icon.png +0 -0
  92. data/spec/fixtures/middleman/build/assets/favicons/browserconfig.xml +12 -0
  93. data/spec/fixtures/middleman/build/assets/favicons/favicon-16x16.png +0 -0
  94. data/spec/fixtures/middleman/build/assets/favicons/favicon-32x32.png +0 -0
  95. data/spec/fixtures/middleman/build/assets/favicons/favicon-96x96.png +0 -0
  96. data/spec/fixtures/middleman/build/assets/favicons/favicon.ico +0 -0
  97. data/spec/fixtures/middleman/build/assets/favicons/manifest.json +41 -0
  98. data/spec/fixtures/middleman/build/assets/favicons/mstile-144x144.png +0 -0
  99. data/spec/fixtures/middleman/build/assets/favicons/mstile-150x150.png +0 -0
  100. data/spec/fixtures/middleman/build/assets/favicons/mstile-310x150.png +0 -0
  101. data/spec/fixtures/middleman/build/assets/favicons/mstile-310x310.png +0 -0
  102. data/spec/fixtures/middleman/build/assets/favicons/mstile-70x70.png +0 -0
  103. data/spec/fixtures/middleman/build/assets/favicons/safari-pinned-tab.svg +450 -0
  104. data/spec/fixtures/middleman/build/assets/images/launch_co_logo.png +0 -0
  105. data/spec/fixtures/middleman/build/assets/images/vimfest.png +0 -0
  106. data/spec/fixtures/middleman/build/assets/javascripts/application.js +12 -0
  107. data/spec/fixtures/middleman/build/assets/javascripts/jquery.utils.js +12 -0
  108. data/spec/fixtures/middleman/build/assets/javascripts/lib/validate.js +1 -0
  109. data/spec/fixtures/middleman/build/assets/stylesheets/application.css +5 -0
  110. data/spec/fixtures/middleman/build/assets/stylesheets/vendor/bootstrap.css +5 -0
  111. data/spec/fixtures/middleman/build/august-2013-meetup/index.html +208 -0
  112. data/spec/fixtures/middleman/build/blog/index.html +500 -0
  113. data/spec/fixtures/middleman/build/book-club-about-the-viml-primer/index.html +182 -0
  114. data/spec/fixtures/middleman/build/contact/index.html +155 -0
  115. data/spec/fixtures/middleman/build/data/vimberlin-2013-09_ctags/index.html +98 -0
  116. data/spec/fixtures/middleman/build/data/vimberlin-2013-09_vimprofiling/index.html +157 -0
  117. data/spec/fixtures/middleman/build/data/vimberlin-2014-01_vim_writing/index.html +70 -0
  118. data/spec/fixtures/middleman/build/december-2015-meetup/index.html +199 -0
  119. data/spec/fixtures/middleman/build/december-2016-meetup/index.html +224 -0
  120. data/spec/fixtures/middleman/build/february-2013-vim-beer-lin/index.html +190 -0
  121. data/spec/fixtures/middleman/build/february-2015-meetup/index.html +233 -0
  122. data/spec/fixtures/middleman/build/february-2016-meetup/index.html +271 -0
  123. data/spec/fixtures/middleman/build/feed.xml +2106 -0
  124. data/spec/fixtures/middleman/build/fonts/FontAwesome.otf +0 -0
  125. data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.eot +0 -0
  126. data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.svg +655 -0
  127. data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.ttf +0 -0
  128. data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.woff +0 -0
  129. data/spec/fixtures/middleman/build/fonts/fontawesome-webfont.woff2 +0 -0
  130. data/spec/fixtures/middleman/build/humans.txt +12 -0
  131. data/spec/fixtures/middleman/build/imprint/index.html +177 -0
  132. data/spec/fixtures/middleman/build/index.html +157 -0
  133. data/spec/fixtures/middleman/build/january-2014-meetup/index.html +257 -0
  134. data/spec/fixtures/middleman/build/january-2015-meetup/index.html +243 -0
  135. data/spec/fixtures/middleman/build/january-2016-meetup/index.html +202 -0
  136. data/spec/fixtures/middleman/build/january-2017-meetup/index.html +228 -0
  137. data/spec/fixtures/middleman/build/july-2015-meetup/index.html +207 -0
  138. data/spec/fixtures/middleman/build/june-2016-meetup/index.html +260 -0
  139. data/spec/fixtures/middleman/build/march-2-2017-meetup/index.html +201 -0
  140. data/spec/fixtures/middleman/build/march-2014-meetup/index.html +219 -0
  141. data/spec/fixtures/middleman/build/march-2016-meetup/index.html +221 -0
  142. data/spec/fixtures/middleman/build/march-2017-meetup/index.html +222 -0
  143. data/spec/fixtures/middleman/build/may-2013-meetup/index.html +234 -0
  144. data/spec/fixtures/middleman/build/may-2014-meetup/index.html +198 -0
  145. data/spec/fixtures/middleman/build/may-2015-meetup/index.html +202 -0
  146. data/spec/fixtures/middleman/build/may-2016-meetup/index.html +245 -0
  147. data/spec/fixtures/middleman/build/newsletter/index.html +171 -0
  148. data/spec/fixtures/middleman/build/november-2013-meetup/index.html +199 -0
  149. data/spec/fixtures/middleman/build/november-2015-meetup/index.html +402 -0
  150. data/spec/fixtures/middleman/build/november-2016-meetup/index.html +224 -0
  151. data/spec/fixtures/middleman/build/october-2013-meetup/index.html +210 -0
  152. data/spec/fixtures/middleman/build/october-2014-meetup/index.html +196 -0
  153. data/spec/fixtures/middleman/build/october-2016-meetup/index.html +222 -0
  154. data/spec/fixtures/middleman/build/robots.txt +6 -0
  155. data/spec/fixtures/middleman/build/september-2013-meetup/index.html +225 -0
  156. data/spec/fixtures/middleman/build/september-2014-meetup/index.html +211 -0
  157. data/spec/fixtures/middleman/build/sitemap.xml +297 -0
  158. data/spec/fixtures/middleman/build/vimfest-october-2015/index.html +303 -0
  159. data/spec/fixtures/middleman/config.rb +4 -0
  160. data/spec/fixtures/middleman/config_repositories.rb +7 -0
  161. data/spec/fixtures/middleman/expected_config.rb +4 -0
  162. data/spec/spec_helper.rb +2 -2
  163. data/spec/sweetie_bitbucket_spec.rb +26 -51
  164. data/spec/sweetie_bitbucket_stati_helper_spec.rb +124 -0
  165. data/spec/sweetie_conversion_spec.rb +105 -17
  166. data/spec/sweetie_helper_spec.rb +140 -0
  167. data/sweetie.gemspec +10 -9
  168. metadata +163 -56
  169. data/.travis.yml +0 -7
  170. data/spec/source/_config.yml +0 -18
  171. data/spec/source/bitbucket/user_repositories.json +0 -161
  172. 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(:user_repositories) {File.join(current_dir, 'source', 'bitbucket', 'user_repositories.json')}
6
- let(:user_repositories_expectation) {File.join(current_dir, 'source', 'bitbucket', 'user_repositories_expectation.txt')}
7
- let(:site_dir) {File.join(current_dir, 'source', 'site')}
8
- let(:config) {File.join(current_dir, "source", "_config.yml")}
9
- let(:svn_hash) {{"svn" => "2011-10-16"}}
10
-
11
- let(:bitbucket) {Sweetie::Bitbucket}
12
-
13
- it "should parse a json file" do
14
- changeset = File.open(user_repositories).read
15
- # gsub replace trailing newline at the end of the file
16
- changeset_expectation = File.open(user_repositories_expectation).read.gsub("\n", "")
17
- changeset = bitbucket.parse_json(changeset).to_s
18
- expect(changeset).to eq changeset_expectation
19
- end
20
-
21
- it "should get the names of the repositories" do
22
- json_repositories = File.open(user_repositories).read
23
- names = %w(pmwiki-headlineimage-recipe
24
- pmwiki-linkicons-recipe
25
- pmwiki-dropcaps-recipe
26
- pmwiki-syntaxlove-recipe
27
- pmwiki-twitter-recipe)
28
- expect(bitbucket.get_repositories_changes(json_repositories).keys).to eq names
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
- it "should count links of about.html page" do
10
- expect(sweetie.count_link_of_one_page(about_page)).to eq(11)
11
- end
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
- it "should count images of about.html page" do
14
- expect(sweetie.count_images_of_one_page(about_page)).to eq 1
15
- end
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
- it "should count all html pages" do
18
- expect(sweetie.count_all_html_pages(site_dir)).to eq 8
19
- end
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
- it "should count all links of all pages" do
22
- expect(sweetie.count_all_links(site_dir)).to eq 54
60
+ expect(result).to be_truthy
61
+ end
23
62
  end
24
63
 
25
- it "should count all images" do
26
- expect(sweetie.count_all_images(site_dir)).to eq 1
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
- $:.push File.expand_path("../lib", __FILE__)
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 = %q{Count links, images, number of html pages, and last-build time of a
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 = %q{Sweetie counts the links, images, number of html pages, and last-build
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,features}/*`.split("\n")
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.6'
24
- s.add_runtime_dependency 'json', '~> 1.8'
25
- s.add_development_dependency 'rake', '~> 10.2'
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