spec/cli_spec.rb in wordless-0.3.0 vs spec/cli_spec.rb in wordless-0.4.0
- old
+ new
@@ -1,34 +1,26 @@
+require 'thor'
require 'spec_helper'
describe Wordless::CLI do
- before :all do
- wp_api_response = <<-eof
- upgrade
- http://wordpress.org/download/
- http://wordpress.org/wordpress-3.3.1.zip
- 3.3.1
- en_US
- 5.2.4
- 5.0
- eof
- FakeWeb.register_uri(:get, %r|http://api.wordpress.org/core/version-check/1.5/.*|, :body => wp_api_response)
- FakeWeb.register_uri(:get, "http://wordpress.org/wordpress-3.3.1.zip", :body => File.expand_path('spec/fixtures/wordpress_stub.zip'))
+ let(:config) do
+ { :wordless_repo => File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'wordless')) }
end
- before :each do
- Wordless::CLI.class_variable_set :@@config, {
- :wordless_repo => File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'wordless'))
- }
+ before do
+ Wordless::WordlessCLI.class_variable_set(:@@config, config)
+ end
+
+ before do
@original_wd = Dir.pwd
Dir.chdir('tmp')
end
- after :each do
+ after do
Dir.chdir(@original_wd)
- %w(tmp/wordpress tmp/myapp).each do |dir|
+ Dir["tmp/*"].each do |dir|
FileUtils.rm_rf(dir) if File.directory? dir
end
end
context "#new" do
@@ -83,18 +75,25 @@
end
end
context "#compile" do
context "with a valid Wordless installation" do
+ let(:compiled_css) { 'wp-content/themes/myapp/assets/stylesheets/screen.css' }
+ let(:compiled_js) { 'wp-content/themes/myapp/assets/javascripts/application.js' }
+
before :each do
Wordless::CLI.start ['new', 'myapp']
end
it "compiles static assets" do
Wordless::CLI.start ['compile']
- File.exists?('wp-content/themes/myapp/assets/stylesheets/screen.css').should be_true
- File.exists?('wp-content/themes/myapp/assets/javascripts/application.js').should be_true
+
+ File.exists?(compiled_css).should be_true
+ File.exists?(compiled_js).should be_true
+
+ File.readlines(compiled_css).grep(/html{line-height:1}/).should_not be_empty
+ File.readlines(compiled_js).grep(/return "Yep, it works!";/).should_not be_empty
end
end
end
context "#clean" do
@@ -121,11 +120,11 @@
File.exists?(default_css).should be_false
File.exists?(default_js).should be_false
end
it "should remove assets specified on config" do
- Wordless::CLI.class_variable_set :@@config, {
+ Wordless::WordlessCLI.class_variable_set :@@config, {
:static_css => [ first_css, second_css ],
:static_js => [ first_js, second_js ]
}
[ first_css, second_css, first_js, second_js ].each do |file|
@@ -142,35 +141,41 @@
context "#deploy" do
let(:cli) { Wordless::CLI.new }
let(:file) { 'shrubbery.txt' }
+ let(:wordless_cli) { Wordless::WordlessCLI.new({}, Thor.new) }
- before :each do
+ before do
FileUtils.mkdir_p('myapp') and Dir.chdir('myapp')
FileUtils.touch('wp-config.php')
- Wordless::CLI.class_variable_set :@@config, {
+ end
+
+ before do
+ cli.stub(:wordless_cli).and_return(wordless_cli)
+ Wordless::WordlessCLI.class_variable_set :@@config, {
:deploy_command => "touch #{file}"
}
end
it "should deploy via the deploy command" do
cli.deploy
File.exists?(file).should be_true
end
it "should compile and clean if refresh option is passed" do
- cli.should_receive(:compile).and_return(true)
- cli.should_receive(:clean).and_return(true)
- cli.stub(:options).and_return({ 'refresh' => true })
+ wordless_cli.should_receive(:compile).and_return(true)
+ wordless_cli.should_receive(:clean).and_return(true)
+ wordless_cli.stub(:options).and_return({ 'refresh' => true })
+
cli.deploy
end
context "if a custom deploy is passed" do
let(:file) { 'knights.txt' }
it "should launch the custom deploy command" do
- cli.stub(:options).and_return({ 'command' => "touch #{file}" })
+ wordless_cli.stub(:options).and_return({ 'command' => "touch #{file}" })
cli.deploy
File.exists?(file).should be_true
end
end
end