nesta 0.12.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +21 -0
  3. data/.gitignore +1 -0
  4. data/.gitmodules +0 -6
  5. data/CHANGES +99 -0
  6. data/Gemfile.lock +43 -39
  7. data/LICENSE +1 -1
  8. data/README.md +9 -14
  9. data/RELEASING.md +9 -7
  10. data/Rakefile +2 -2
  11. data/bin/nesta +5 -2
  12. data/config/deploy.rb.sample +1 -1
  13. data/lib/nesta/app.rb +1 -2
  14. data/lib/nesta/commands/build.rb +38 -0
  15. data/lib/nesta/commands/demo/content.rb +8 -10
  16. data/lib/nesta/commands/edit.rb +2 -6
  17. data/lib/nesta/commands/new.rb +11 -12
  18. data/lib/nesta/commands/plugin/create.rb +7 -9
  19. data/lib/nesta/commands/template.rb +20 -0
  20. data/lib/nesta/commands/theme/create.rb +8 -8
  21. data/lib/nesta/commands/theme/enable.rb +3 -5
  22. data/lib/nesta/commands/theme/install.rb +6 -10
  23. data/lib/nesta/commands.rb +9 -0
  24. data/lib/nesta/config.rb +49 -75
  25. data/lib/nesta/config_file.rb +29 -0
  26. data/lib/nesta/helpers.rb +0 -5
  27. data/lib/nesta/models.rb +33 -34
  28. data/lib/nesta/navigation.rb +0 -5
  29. data/lib/nesta/overrides.rb +32 -43
  30. data/lib/nesta/plugin.rb +0 -16
  31. data/lib/nesta/static/assets.rb +50 -0
  32. data/lib/nesta/static/html_file.rb +26 -0
  33. data/lib/nesta/static/site.rb +104 -0
  34. data/lib/nesta/system_command.rb +15 -0
  35. data/lib/nesta/version.rb +1 -1
  36. data/lib/nesta.rb +7 -4
  37. data/nesta.gemspec +5 -5
  38. data/templates/config/config.yml +28 -2
  39. data/templates/themes/README.md +1 -1
  40. data/templates/themes/views/master.sass +1 -1
  41. data/test/integration/atom_feed_test.rb +1 -1
  42. data/test/integration/commands/build_test.rb +53 -0
  43. data/test/integration/commands/demo/content_test.rb +8 -6
  44. data/test/integration/commands/edit_test.rb +4 -4
  45. data/test/integration/commands/new_test.rb +22 -51
  46. data/test/integration/commands/plugin/create_test.rb +7 -4
  47. data/test/integration/commands/theme/create_test.rb +8 -2
  48. data/test/integration/commands/theme/enable_test.rb +7 -1
  49. data/test/integration/commands/theme/install_test.rb +13 -9
  50. data/test/integration/overrides_test.rb +1 -1
  51. data/test/integration/sitemap_test.rb +1 -1
  52. data/test/support/temporary_files.rb +1 -1
  53. data/test/support/test_configuration.rb +2 -4
  54. data/test/unit/config_test.rb +25 -94
  55. data/test/unit/static/assets_test.rb +56 -0
  56. data/test/unit/static/html_file_test.rb +41 -0
  57. data/test/unit/static/site_test.rb +104 -0
  58. data/test/unit/system_command_test.rb +20 -0
  59. data/views/atom.haml +2 -2
  60. data/views/comments.haml +2 -2
  61. data/views/footer.haml +1 -1
  62. data/views/header.haml +2 -3
  63. data/views/layout.haml +2 -2
  64. data/views/master.sass +1 -1
  65. data/views/mixins.sass +2 -2
  66. data/views/normalize.scss +0 -1
  67. data/views/sitemap.haml +1 -1
  68. metadata +44 -31
  69. data/.hound.yml +0 -2
  70. data/.rspec +0 -1
  71. data/.travis.yml +0 -11
  72. data/lib/nesta/commands/command.rb +0 -57
  73. data/test/support/silence_commands_during_tests.rb +0 -5
  74. data/test/unit/commands_test.rb +0 -23
@@ -0,0 +1,104 @@
1
+ require 'rake'
2
+
3
+ require_relative './html_file'
4
+
5
+ module Nesta
6
+ module Static
7
+ class Site
8
+ def initialize(build_dir, domain, logger = nil)
9
+ @build_dir = build_dir
10
+ @domain = domain
11
+ @logger = logger
12
+ @app = Nesta::App.new
13
+ set_app_root
14
+ end
15
+
16
+ def render_pages
17
+ Nesta::Page.find_all.each do |page|
18
+ target = HtmlFile.new(@build_dir, page).filename
19
+ source = page.filename
20
+ task = Rake::FileTask.define_task(target => source) do
21
+ save_markup(target, render(page.abspath, target, source))
22
+ end
23
+ task.invoke
24
+ end
25
+ end
26
+
27
+ def render_not_found
28
+ path_info = '/404'
29
+ source = 'no-such-file.md'
30
+ target = File.join(@build_dir, '404.html')
31
+ markup = render(path_info, target, source, expected_code: 404)
32
+ save_markup(target, markup)
33
+ end
34
+
35
+ def render_atom_feed
36
+ filename = 'articles.xml'
37
+ path_info = "/#{filename}"
38
+ description = 'Atom feed'
39
+ target = File.join(@build_dir, filename)
40
+ markup = render(path_info, target, description)
41
+ save_markup(target, markup)
42
+ end
43
+
44
+ def render_sitemap
45
+ filename = File.join(@build_dir, 'sitemap.xml')
46
+ save_markup(filename, render('/sitemap.xml', filename, 'site'))
47
+ end
48
+
49
+ def render_templated_assets
50
+ Nesta::Config.build.fetch('templated_assets', []).each do |path|
51
+ filename = File.join(@build_dir, path)
52
+ save_markup(filename, render(path, filename, path))
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def log(message)
59
+ @logger.call(message) if @logger
60
+ end
61
+
62
+ def set_app_root
63
+ root = ::File.expand_path('.')
64
+ ['Gemfile', ].each do |expected|
65
+ if ! File.exist?(File.join(root, 'config', 'config.yml'))
66
+ message = "is this a Nesta site? (expected './#{expected}')"
67
+ raise RuntimeError, message
68
+ end
69
+ end
70
+ Nesta::App.root = root
71
+ end
72
+
73
+ def rack_environment(abspath)
74
+ {
75
+ 'REQUEST_METHOD' => 'GET',
76
+ 'SCRIPT_NAME' => '',
77
+ 'PATH_INFO' => abspath,
78
+ 'QUERY_STRING' => '',
79
+ 'SERVER_NAME' => @domain,
80
+ 'SERVER_PROTOCOL' => 'https',
81
+ 'rack.url_scheme' => 'https',
82
+ 'rack.input' => StringIO.new,
83
+ 'rack.errors' => STDERR
84
+ }
85
+ end
86
+
87
+ def render(abspath, filename, description, expected_code: 200)
88
+ http_code, headers, body = @app.call(rack_environment(abspath))
89
+ if http_code != expected_code
90
+ raise RuntimeError, "Can't render #{filename} from #{description}"
91
+ end
92
+ body.join
93
+ end
94
+
95
+ def save_markup(filename, content)
96
+ FileUtils.mkdir_p(File.dirname(filename))
97
+ if (! File.exist?(filename)) || (open(filename, 'r').read != content)
98
+ open(filename, 'w') { |output| output.write(content) }
99
+ log("Rendered #{filename}")
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,15 @@
1
+ module Nesta
2
+ class SystemCommand
3
+ def run(*args)
4
+ system(*args)
5
+ if ! $?.success?
6
+ message = if $?.exitstatus == 127
7
+ "#{args[0]} not found"
8
+ else
9
+ "'#{args.join(' ')}' failed with status #{$?.exitstatus}"
10
+ end
11
+ Nesta.fail_with(message)
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/nesta/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nesta
2
- VERSION = '0.12.0'
2
+ VERSION = '0.14.0'
3
3
  end
data/lib/nesta.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  module Nesta
2
2
  def self.deprecated(name, message)
3
- if Nesta::App.environment != :test
4
- $stderr.puts "DEPRECATION WARNING: #{name} is deprecated; #{message}"
5
- end
3
+ $stderr.puts "DEPRECATION WARNING: #{name} is deprecated; #{message}"
4
+ end
5
+
6
+ def self.fail_with(message)
7
+ $stderr.puts "Error: #{message}"
8
+ exit 1
6
9
  end
7
10
  end
8
11
 
9
- require 'nesta/plugin'
12
+ require File.expand_path('nesta/plugin', File.dirname(__FILE__))
data/nesta.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Graham Ashton"]
10
10
  s.email = ["graham@effectif.com"]
11
- s.homepage = "http://nestacms.com"
11
+ s.homepage = "https://nestacms.com"
12
12
  s.summary = %q{Ruby CMS, written in Sinatra}
13
13
  s.description = <<-EOF
14
14
  Nesta is a lightweight Content Management System, written in Ruby using
@@ -29,12 +29,13 @@ EOF
29
29
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
30
30
  s.require_paths = ["lib"]
31
31
 
32
- s.add_dependency('haml', '>= 3.1')
32
+ s.add_dependency('haml', '>= 3.1', '< 6.0')
33
33
  s.add_dependency('haml-contrib', '>= 1.0')
34
- s.add_dependency('rack', '~> 2.0')
34
+ s.add_dependency('rack', '~> 2')
35
+ s.add_dependency('rake')
35
36
  s.add_dependency('rdiscount', '~> 2.1')
36
37
  s.add_dependency('RedCloth', '~> 4.2')
37
- s.add_dependency('sassc', '>= 2.2')
38
+ s.add_dependency('sass-embedded', '~> 1.58')
38
39
  s.add_dependency('sinatra', '~> 2.0')
39
40
  s.add_dependency('tilt', '~> 2.0')
40
41
 
@@ -46,5 +47,4 @@ EOF
46
47
  s.add_development_dependency('capybara', '~> 2.0')
47
48
  s.add_development_dependency('minitest', '~> 5.0')
48
49
  s.add_development_dependency('minitest-reporters')
49
- s.add_development_dependency('rake')
50
50
  end
@@ -12,7 +12,7 @@ subtitle: "(change this text in config/config.yml)"
12
12
  #
13
13
  # author:
14
14
  # name: Your Name
15
- # uri: http://yourhomepage.com
15
+ # uri: https://yourdomain.com
16
16
  # email: you@yourdomain.com
17
17
 
18
18
  # You can stick with the default look and feel, or use a theme. Themes are
@@ -21,7 +21,7 @@ subtitle: "(change this text in config/config.yml)"
21
21
  #
22
22
  # theme: name-of-theme
23
23
 
24
- # If you want to use the Disqus service (http://disqus.com) to display
24
+ # If you want to use the Disqus service (https://disqus.com) to display
25
25
  # comments on your site, register a Disqus account and then specify your
26
26
  # site's short name here. A comment form will automatically be added to
27
27
  # the bottom of your pages.
@@ -65,3 +65,29 @@ content: content
65
65
  # production:
66
66
  # content: /var/apps/nesta/shared/content
67
67
  # google_analytics_code: "UA-???????-?"
68
+
69
+ # The following settings control the behaviour of the `nesta build`
70
+ # command, which is used to generate a "static" version of your site.
71
+ # It's optional, but allows you to deploy your site on hosting providers
72
+ # that serve pre-prepared HTML and CSS files (instead of generating them
73
+ # in real-time with a web server).
74
+ #
75
+ # You can either set the `domain` key here, or specify it on the command
76
+ # line with the `--domain` switch. Nesta needs to know your site's
77
+ # domain name so that it can generate the correct URLs in sitemap.xml,
78
+ # and in your Atom feed.
79
+ #
80
+ # The templated_assets setting is a list of the things that Nesta
81
+ # generates for you, other from all the page in your content directory.
82
+ # The example below is for a site that has two stylesheets, both of
83
+ # which are converted from .sass or .scss files in your ./views folder.
84
+ #
85
+ # If you're not using Sass and are just editing CSS files directly, you
86
+ # can keep them in your ./public folder and Nesta's build command will
87
+ # find them automatically.
88
+ #
89
+ # build:
90
+ # domain: yourdomain.com
91
+ # templated_assets:
92
+ # - /css/master.css
93
+ # - /css/local.css
@@ -4,4 +4,4 @@
4
4
  <%= @name %> is a theme for Nesta, a [Ruby CMS](nesta), designed by
5
5
  <insert your name here>.
6
6
 
7
- [nesta]: http://nestacms.com
7
+ [nesta]: https://nestacms.com
@@ -1,3 +1,3 @@
1
1
  // Master Sass stylesheet
2
- // http://sass-lang.com/
2
+ // https://sass-lang.com/
3
3
 
@@ -18,7 +18,7 @@ describe 'Atom feed' do
18
18
  it "uses Atom's XML namespace" do
19
19
  with_temp_content_directory do
20
20
  visit_feed
21
- assert_has_xpath '//feed[@xmlns="http://www.w3.org/2005/Atom"]'
21
+ assert_has_xpath '//feed[@xmlns="https://www.w3.org/2005/Atom"]'
22
22
  end
23
23
  end
24
24
 
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+ require_relative '../../../lib/nesta/commands'
3
+
4
+ describe 'nesta build' do
5
+ include ModelFactory
6
+ include TestConfiguration
7
+
8
+ def silencing_stdout(&block)
9
+ stdout, $stdout = $stdout, StringIO.new
10
+ yield
11
+ ensure
12
+ $stdout.close
13
+ $stdout = stdout
14
+ end
15
+
16
+ it 'builds HTML file from Markdown file' do
17
+ in_temporary_project do
18
+ with_temp_content_directory do
19
+ page = create(:page)
20
+ command = Nesta::Commands::Build.new('output_dir')
21
+
22
+ process = Minitest::Mock.new
23
+ silencing_stdout { command.execute(process) }
24
+
25
+ assert_exists_in_project File.join('output_dir', page.abspath + '.html')
26
+ end
27
+ end
28
+ end
29
+
30
+ it 'reads domain name from config file' do
31
+ domain = 'mysite.com'
32
+
33
+ in_temporary_project do
34
+ stub_config('build' => { 'domain' => domain }) do
35
+ command = Nesta::Commands::Build.new('output_dir')
36
+
37
+ assert_equal domain, command.domain
38
+ end
39
+ end
40
+ end
41
+
42
+ it 'overrides domain name if set on command line' do
43
+ domain = 'mysite.com'
44
+
45
+ in_temporary_project do
46
+ stub_config('build' => { 'domain' => 'ignored.com' }) do
47
+ command = Nesta::Commands::Build.new('output_dir', 'domain' => domain)
48
+
49
+ assert_equal domain, command.domain
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,9 +1,6 @@
1
1
  require 'test_helper'
2
- require_relative '../../../support/silence_commands_during_tests'
3
2
  require_relative '../../../../lib/nesta/commands'
4
3
 
5
- Nesta::Commands::Demo::Content.send(:include, SilenceCommandsDuringTests)
6
-
7
4
  describe 'nesta demo:content' do
8
5
  include TemporaryFiles
9
6
 
@@ -11,10 +8,15 @@ describe 'nesta demo:content' do
11
8
  Nesta::Commands::Demo::Content.demo_repository = '../../fixtures/demo-content.git'
12
9
  end
13
10
 
11
+ def process_stub
12
+ Object.new.tap do |stub|
13
+ def stub.run(*args); end
14
+ end
15
+ end
16
+
14
17
  it 'clones the demo repository and configures project to use it' do
15
18
  in_temporary_project do
16
- Nesta::Commands::Demo::Content.new.execute
17
- assert_exists_in_project 'content-demo/pages/index.haml'
19
+ Nesta::Commands::Demo::Content.new.execute(process_stub)
18
20
 
19
21
  yaml = File.read(File.join(project_root, 'config', 'config.yml'))
20
22
  assert_match /content: content-demo/, yaml
@@ -24,7 +26,7 @@ describe 'nesta demo:content' do
24
26
  it 'ensures demo repository is ignored by git' do
25
27
  in_temporary_project do
26
28
  FileUtils.mkdir('.git')
27
- Nesta::Commands::Demo::Content.new.execute
29
+ Nesta::Commands::Demo::Content.new.execute(process_stub)
28
30
  assert_match /content-demo/, File.read(project_path('.git/info/exclude'))
29
31
  end
30
32
  end
@@ -9,13 +9,13 @@ describe 'nesta edit' do
9
9
  end
10
10
 
11
11
  it 'launches the editor' do
12
- ENV['EDITOR'] = 'touch'
12
+ ENV['EDITOR'] = 'vi'
13
13
  edited_file = 'path/to/page.md'
14
+ process = Minitest::Mock.new
15
+ process.expect(:run, true, [ENV['EDITOR'], /#{edited_file}$/])
14
16
  with_temp_content_directory do
15
- FileUtils.mkdir_p(Nesta::Config.page_path(File.dirname(edited_file)))
16
17
  command = Nesta::Commands::Edit.new(edited_file)
17
- command.execute
18
- assert File.exist?(Nesta::Config.page_path(edited_file)), 'editor not run'
18
+ command.execute(process)
19
19
  end
20
20
  end
21
21
  end
@@ -1,9 +1,6 @@
1
1
  require 'test_helper'
2
- require_relative '../../support/silence_commands_during_tests'
3
2
  require_relative '../../../lib/nesta/commands'
4
3
 
5
- Nesta::Commands::New.send(:include, SilenceCommandsDuringTests)
6
-
7
4
  describe 'nesta new' do
8
5
  include TemporaryFiles
9
6
 
@@ -19,30 +16,36 @@ describe 'nesta new' do
19
16
  remove_temp_directory
20
17
  end
21
18
 
19
+ def process_stub
20
+ Object.new.tap do |stub|
21
+ def stub.run(*args); end
22
+ end
23
+ end
24
+
22
25
  describe 'without options' do
23
26
  it 'creates the content directories' do
24
- Nesta::Commands::New.new(project_root).execute
27
+ Nesta::Commands::New.new(project_root).execute(process_stub)
25
28
  assert_exists_in_project 'content/attachments'
26
29
  assert_exists_in_project 'content/pages'
27
30
  end
28
31
 
29
32
  it 'creates the home page' do
30
- Nesta::Commands::New.new(project_root).execute
33
+ Nesta::Commands::New.new(project_root).execute(process_stub)
31
34
  assert_exists_in_project 'content/pages/index.haml'
32
35
  end
33
36
 
34
37
  it 'creates the rackup file' do
35
- Nesta::Commands::New.new(project_root).execute
38
+ Nesta::Commands::New.new(project_root).execute(process_stub)
36
39
  assert_exists_in_project 'config.ru'
37
40
  end
38
41
 
39
42
  it 'creates the config.yml file' do
40
- Nesta::Commands::New.new(project_root).execute
43
+ Nesta::Commands::New.new(project_root).execute(process_stub)
41
44
  assert_exists_in_project 'config/config.yml'
42
45
  end
43
46
 
44
47
  it 'creates a Gemfile' do
45
- Nesta::Commands::New.new(project_root).execute
48
+ Nesta::Commands::New.new(project_root).execute(process_stub)
46
49
  assert_exists_in_project 'Gemfile'
47
50
  assert_match /gem 'nesta'/, gemfile_source
48
51
  end
@@ -51,67 +54,35 @@ describe 'nesta new' do
51
54
  describe 'with --git option' do
52
55
  it 'creates a .gitignore file' do
53
56
  command = Nesta::Commands::New.new(project_root, 'git' => '')
54
- command.stub(:run_process, nil) do
55
- command.execute
56
- assert_match /\.bundle/, File.read(project_path('.gitignore'))
57
- end
58
- end
59
-
60
- def disabling_git_hooks
61
- # I (@gma) have got a git repository template setup on my computer
62
- # containing git hooks that automatically run ctags in a
63
- # background process whenever I run `git commit`. The hooks are
64
- # copied into new repositories when I run `git init`.
65
- #
66
- # The generation of the ctags file (in a forked process) causes a
67
- # race condition; sometimes ctags will recreate a test's project
68
- # folder and git directory after the test's `after` block has
69
- # deleted it. If the project directory isn't removed after each
70
- # test, the New command will throw an error in the subsequent
71
- # test (complaining that the project directory already exists).
72
- #
73
- templates = temp_path('git_template')
74
- FileUtils.mkdir_p(templates)
75
- ENV['GIT_TEMPLATE_DIR'] = templates
76
- yield
77
- ENV.delete('GIT_TEMPLATE_DIR')
78
- FileUtils.rm_r(templates)
57
+ command.execute(process_stub)
58
+ assert_match /\.bundle/, File.read(project_path('.gitignore'))
79
59
  end
80
60
 
81
61
  it 'creates a git repo' do
82
- disabling_git_hooks do
83
- command = Nesta::Commands::New.new(project_root, 'git' => '')
84
- command.execute
85
- assert_exists_in_project '.git/config'
86
- end
87
- end
88
-
89
- it 'commits the blank project' do
90
- disabling_git_hooks do
91
- command = Nesta::Commands::New.new(project_root, 'git' => '')
92
- command.execute
93
- Dir.chdir(project_root) do
94
- assert_match /Initial commit/, `git log --pretty=oneline | head -n 1`
95
- end
96
- end
62
+ command = Nesta::Commands::New.new(project_root, 'git' => '')
63
+ process = Minitest::Mock.new
64
+ process.expect(:run, true, ['git', 'init'])
65
+ process.expect(:run, true, ['git', 'add', '.'])
66
+ process.expect(:run, true, ['git', 'commit', '-m', 'Initial commit'])
67
+ command.execute(process)
97
68
  end
98
69
  end
99
70
 
100
71
  describe 'with --vlad option' do
101
72
  it 'adds vlad to Gemfile' do
102
- Nesta::Commands::New.new(project_root, 'vlad' => '').execute
73
+ Nesta::Commands::New.new(project_root, 'vlad' => '').execute(process_stub)
103
74
  assert_match /gem 'vlad', '2.1.0'/, gemfile_source
104
75
  assert_match /gem 'vlad-git', '2.2.0'/, gemfile_source
105
76
  end
106
77
 
107
78
  it 'configures the vlad rake tasks' do
108
- Nesta::Commands::New.new(project_root, 'vlad' => '').execute
79
+ Nesta::Commands::New.new(project_root, 'vlad' => '').execute(process_stub)
109
80
  assert_exists_in_project 'Rakefile'
110
81
  assert_match /require 'vlad'/, rakefile_source
111
82
  end
112
83
 
113
84
  it 'creates deploy.rb' do
114
- Nesta::Commands::New.new(project_root, 'vlad' => '').execute
85
+ Nesta::Commands::New.new(project_root, 'vlad' => '').execute(process_stub)
115
86
  assert_exists_in_project 'config/deploy.rb'
116
87
  deploy_source = File.read(project_path('config/deploy.rb'))
117
88
  assert_match /set :application, 'mysite.com'/, deploy_source
@@ -24,13 +24,16 @@ describe 'nesta plugin:create' do
24
24
  "nesta-plugin-#{plugin_name}"
25
25
  end
26
26
 
27
+ def process_stub
28
+ Object.new.tap do |stub|
29
+ def stub.run(*args); end
30
+ end
31
+ end
32
+
27
33
  def create_plugin(&block)
28
34
  Dir.chdir(working_directory) do
29
35
  command = Nesta::Commands::Plugin::Create.new(plugin_name)
30
- command.stub(:run_process, nil) do
31
- command.execute
32
- yield
33
- end
36
+ command.execute(process_stub)
34
37
  end
35
38
  end
36
39
 
@@ -16,9 +16,15 @@ describe 'nesta theme:create' do
16
16
  remove_temp_directory
17
17
  end
18
18
 
19
+ def process_stub
20
+ Object.new.tap do |stub|
21
+ def stub.run(*args); end
22
+ end
23
+ end
24
+
19
25
  it 'creates default files in the theme directory' do
20
26
  Dir.chdir(project_root) do
21
- Nesta::Commands::Theme::Create.new('theme-name').execute
27
+ Nesta::Commands::Theme::Create.new('theme-name').execute(process_stub)
22
28
  end
23
29
  assert_exists_in_project theme_path('README.md')
24
30
  assert_exists_in_project theme_path('app.rb')
@@ -26,7 +32,7 @@ describe 'nesta theme:create' do
26
32
 
27
33
  it 'copies default view templates into views directory' do
28
34
  Dir.chdir(project_root) do
29
- Nesta::Commands::Theme::Create.new('theme-name').execute
35
+ Nesta::Commands::Theme::Create.new('theme-name').execute(process_stub)
30
36
  end
31
37
  %w(layout.haml page.haml master.sass).each do |template|
32
38
  assert_exists_in_project theme_path("views/#{template}")
@@ -13,9 +13,15 @@ describe 'nesta theme:enable' do
13
13
  remove_temp_directory
14
14
  end
15
15
 
16
+ def process_stub
17
+ Object.new.tap do |stub|
18
+ def stub.run(*args); end
19
+ end
20
+ end
21
+
16
22
  it 'enables the theme' do
17
23
  Dir.chdir(project_root) do
18
- Nesta::Commands::Theme::Enable.new('theme-name').execute
24
+ Nesta::Commands::Theme::Enable.new('theme-name').execute(process_stub)
19
25
  assert_match /^theme: theme-name/, File.read('config/config.yml')
20
26
  end
21
27
  end
@@ -1,9 +1,6 @@
1
1
  require 'test_helper'
2
- require_relative '../../../support/silence_commands_during_tests'
3
2
  require_relative '../../../../lib/nesta/commands'
4
3
 
5
- Nesta::Commands::Theme::Install.send(:include, SilenceCommandsDuringTests)
6
-
7
4
  describe 'nesta theme:install' do
8
5
  include TemporaryFiles
9
6
 
@@ -27,35 +24,42 @@ describe 'nesta theme:install' do
27
24
  remove_temp_directory
28
25
  end
29
26
 
27
+ def process_stub
28
+ Object.new.tap do |stub|
29
+ def stub.run(*args); end
30
+ end
31
+ end
32
+
30
33
  it 'clones the repository' do
34
+ process = Minitest::Mock.new
35
+ process.expect(:run, true, ['git', 'clone', repo_url, "themes/#{theme_name}"])
31
36
  in_temporary_project do
32
- Nesta::Commands::Theme::Install.new(repo_url).execute
33
- assert File.directory?(theme_dir), 'theme not cloned'
37
+ Nesta::Commands::Theme::Install.new(repo_url).execute(process)
34
38
  end
35
39
  end
36
40
 
37
41
  it "removes the theme's .git directory" do
38
42
  in_temporary_project do
39
- Nesta::Commands::Theme::Install.new(repo_url).execute
43
+ Nesta::Commands::Theme::Install.new(repo_url).execute(process_stub)
40
44
  refute File.exist?("#{theme_dir}/.git"), '.git folder found'
41
45
  end
42
46
  end
43
47
 
44
48
  it 'enables the freshly installed theme' do
45
49
  in_temporary_project do
46
- Nesta::Commands::Theme::Install.new(repo_url).execute
50
+ Nesta::Commands::Theme::Install.new(repo_url).execute(process_stub)
47
51
  assert_match /theme: #{theme_name}/, File.read('config/config.yml')
48
52
  end
49
53
  end
50
54
 
51
55
  it 'determines name of theme from name of repository' do
52
- url = 'git://foobar.com/path/to/nesta-theme-the-name.git'
56
+ url = 'https://foobar.com/path/to/nesta-theme-the-name.git'
53
57
  command = Nesta::Commands::Theme::Install.new(url)
54
58
  assert_equal 'the-name', command.theme_name
55
59
  end
56
60
 
57
61
  it "falls back to name of repo when theme name doesn't match correct format" do
58
- url = 'git://foobar.com/path/to/mytheme.git'
62
+ url = 'https://foobar.com/path/to/mytheme.git'
59
63
  command = Nesta::Commands::Theme::Install.new(url)
60
64
  assert_equal 'mytheme', command.theme_name
61
65
  end
@@ -75,7 +75,7 @@ describe 'Overriding files in gem and themes' do
75
75
  end
76
76
  end
77
77
 
78
- it 'renders stylesheet in the the gem if no others found' do
78
+ it 'renders stylesheet in the gem if no others found' do
79
79
  in_nesta_project do
80
80
  visit '/css/master.css'
81
81
  assert_equal 200, page.status_code
@@ -31,7 +31,7 @@ describe 'XML sitemap' do
31
31
 
32
32
  it 'has a urlset tag' do
33
33
  for_site_with_page do
34
- namespace = 'http://www.sitemaps.org/schemas/sitemap/0.9'
34
+ namespace = 'https://www.sitemaps.org/schemas/sitemap/0.9'
35
35
  assert_has_xpath "//urlset[@xmlns='#{namespace}']"
36
36
  end
37
37
  end
@@ -22,7 +22,7 @@ module TemporaryFiles
22
22
  def in_temporary_project(*args, &block)
23
23
  FileUtils.mkdir_p(File.join(project_root, 'config'))
24
24
  File.open(File.join(project_root, 'config', 'config.yml'), 'w').close
25
- Dir.chdir(project_root) { yield }
25
+ Dir.chdir(project_root) { yield project_root }
26
26
  ensure
27
27
  remove_temp_directory
28
28
  end
@@ -2,10 +2,8 @@ module TestConfiguration
2
2
  include TemporaryFiles
3
3
 
4
4
  def stub_config(config, &block)
5
- Nesta::Config.stub(:yaml_exists?, true) do
6
- Nesta::Config.stub(:yaml_conf, config) do
7
- yield
8
- end
5
+ Nesta::Config.instance.stub(:config, config) do
6
+ yield
9
7
  end
10
8
  end
11
9