diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..b9ad93f --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +-I./lib/spec diff --git a/Gemfile b/Gemfile index 519c249..b50cf3c 100644 --- a/Gemfile +++ b/Gemfile @@ -28,7 +28,7 @@ group :development do end group :test do - gem "minitest", "~> 4.6" + gem "rspec", "~> 2.13.0" end gem 'sinatra', '~> 1.3.3' diff --git a/Gemfile.lock b/Gemfile.lock index c9fff6d..3f29dca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,6 +16,7 @@ GEM chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) + diff-lcs (1.2.2) directory_watcher (1.5.1) execjs (1.4.0) multi_json (~> 1.0) @@ -54,7 +55,6 @@ GEM maruku (0.6.1) syntax (>= 1.0.0) method_source (0.8.1) - minitest (4.6.2) multi_json (1.5.0) posix-spawn (0.3.6) pry (0.9.12) @@ -74,6 +74,14 @@ GEM rb-inotify (0.8.8) ffi (>= 0.5.0) redcarpet (2.2.2) + rspec (2.13.0) + rspec-core (~> 2.13.0) + rspec-expectations (~> 2.13.0) + rspec-mocks (~> 2.13.0) + rspec-core (2.13.1) + rspec-expectations (2.13.0) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.13.0) rubypants (0.2.0) safe_yaml (0.7.1) sass (3.2.5) @@ -109,7 +117,6 @@ DEPENDENCIES haml (~> 3.1.7) jekyll (~> 1.0.0.beta2) liquid (~> 2.3.0) - minitest (~> 4.6) pygments.rb (~> 0.3.4) rack (~> 1.5.0) rake (~> 10.0.3) @@ -117,6 +124,7 @@ DEPENDENCIES rb-fsevent rb-inotify redcarpet (~> 2.2.2) + rspec (~> 2.13.0) rubypants (~> 0.2.0) sass-globbing (~> 1.0.0) sinatra (~> 1.3.3) diff --git a/Rakefile b/Rakefile index 76b8b6a..53bce2d 100644 --- a/Rakefile +++ b/Rakefile @@ -577,9 +577,12 @@ end # # Run tests for Octopress module, found in lib/. # -Rake::TestTask.new do |t| - t.pattern = "lib/spec/**/*_spec.rb" +require 'rspec/core/rake_task' +desc "Run all examples" +RSpec::Core::RakeTask.new(:spec) do |t| + t.pattern = "./lib/spec{,/*/**}/*_spec.rb" end +task :test => :spec def get_unpublished(posts, options={}) result = "" diff --git a/lib/Gemfile.lock b/lib/Gemfile.lock deleted file mode 100644 index c38017c..0000000 --- a/lib/Gemfile.lock +++ /dev/null @@ -1,12 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - minitest (4.6.2) - rake (10.0.3) - -PLATFORMS - ruby - -DEPENDENCIES - minitest (~> 4.6) - rake (~> 10.0) diff --git a/lib/octopress.rb b/lib/octopress.rb index 62facca..9d2704f 100644 --- a/lib/octopress.rb +++ b/lib/octopress.rb @@ -2,18 +2,15 @@ $:.unshift File.expand_path(File.dirname(__FILE__)) # For use/testing when no ge require "octopress/core_ext" require "octopress/configuration" +require "octopress/inquirable_string" require "octopress/js_asset_manager" module Octopress - class InquirableString < String - def method_missing(name, *args, &block) - if(name =~ /^.*\?$/) - val = name.to_s.sub(/\?$/, '') - return self == val - else - super - end - end + # Static: Get absolute file path of the octopress lib directory + # + # Returns the absolute path to the octopress lib directory + def self.lib_root + File.dirname(__FILE__) end # Static: Fetches the Octopress environment diff --git a/lib/octopress/inquirable_string.rb b/lib/octopress/inquirable_string.rb new file mode 100644 index 0000000..46b8cba --- /dev/null +++ b/lib/octopress/inquirable_string.rb @@ -0,0 +1,12 @@ +module Octopress + class InquirableString < String + def method_missing(name, *args, &block) + if(name =~ /^.*\?$/) + val = name.to_s.sub(/\?$/, '') + return self == val + else + super + end + end + end +end diff --git a/lib/spec/octopress/configuration_spec.rb b/lib/spec/octopress/configuration_spec.rb index 8b13225..785a4ce 100644 --- a/lib/spec/octopress/configuration_spec.rb +++ b/lib/spec/octopress/configuration_spec.rb @@ -1,5 +1,4 @@ -require 'minitest/autorun' -require_relative '../../octopress' +require "spec_helper" describe Octopress do describe ".configurator" do @@ -16,7 +15,7 @@ describe Octopress do it "should accept a path pointing to a config directory" do Octopress.configurator(File.join(File.dirname(__FILE__), '../', 'fixtures', 'env')) - Octopress.env.must_equal 'config_specified_environment' + Octopress.env.should eq('config_specified_environment') end end @@ -32,12 +31,10 @@ describe Octopress do ENV['OCTOPRESS_ENV'] = @old_env end - subject do - Octopress.configuration - end + let(:configuration) { Octopress.configuration } it "should provide access to the specified configuration" do - subject[:env].must_equal 'config_specified_environment' + configuration[:env].should eq('config_specified_environment') end end end @@ -48,10 +45,7 @@ describe Octopress::Configuration do before do @octo_config = Octopress::Configuration.new(File.join(File.dirname(__FILE__), '../', 'fixtures', 'no_override')) end - - subject do - @octo_config.read_configuration - end + let(:configuration) { @octo_config.read_configuration } it "returns the default config with keys as symbols" do expected_config = { :url => "http://yoursite.com", @@ -60,7 +54,7 @@ describe Octopress::Configuration do :author => "Your Name", :simple_search => "http://google.com/search", :description => nil } - subject.must_equal expected_config + configuration.should eq(expected_config) end end @@ -68,10 +62,7 @@ describe Octopress::Configuration do before do @octo_config = Octopress::Configuration.new(File.join(File.dirname(__FILE__), '../', 'fixtures', 'override')) end - - subject do - @octo_config.read_configuration - end + let(:configuration) { @octo_config.read_configuration } it "returns the default config with keys as symbols" do expected_config = { :url => "http://myownsite.com", @@ -80,7 +71,7 @@ describe Octopress::Configuration do :author => "John Doe", :simple_search => "http://google.com/search", :description => nil } - subject.must_equal expected_config + configuration.should eq(expected_config) end end end diff --git a/lib/spec/octopress/octopress_spec.rb b/lib/spec/octopress/octopress_spec.rb index eeae584..cb24962 100644 --- a/lib/spec/octopress/octopress_spec.rb +++ b/lib/spec/octopress/octopress_spec.rb @@ -1,16 +1,14 @@ -require 'minitest/autorun' -require_relative '../../octopress' +require "spec_helper" describe Octopress do describe '#env' do - describe "when ENV['OCTOPRESS_ENV'] is specified" do + context "when ENV['OCTOPRESS_ENV'] is specified" do + let (:old_value) { ENV['OCTOPRESS_ENV'] } before do - @old_value = ENV['OCTOPRESS_ENV'] ENV['OCTOPRESS_ENV'] = 'some_environment' end - after do - ENV['OCTOPRESS_ENV'] = @old_value + ENV['OCTOPRESS_ENV'] = old_value end subject do @@ -18,7 +16,7 @@ describe Octopress do end it "returns the environment as something that quacks like a string" do - subject.must_equal 'some_environment' + should eq('some_environment') end # For the InquirableString functionality... @@ -28,7 +26,7 @@ describe Octopress do end it "returns true when the environment is set to 'some_environment'" do - subject.must_equal true + should be_true end end @@ -38,7 +36,7 @@ describe Octopress do end it "returns false when the environment is set to 'some_environment'" do - subject.must_equal false + should be_false end end end @@ -60,7 +58,7 @@ describe Octopress do end it "returns the environment as something that quacks like a string" do - subject.must_equal 'config_specified_environment' + should eq('config_specified_environment') end # For the InquirableString functionality... @@ -70,7 +68,7 @@ describe Octopress do end it "returns true when the environment is set to 'config_specified_environment'" do - subject.must_equal true + should be_true end end @@ -80,7 +78,7 @@ describe Octopress do end it "returns false when the environment is set to 'config_specified_environment'" do - subject.must_equal false + should be_false end end end @@ -96,9 +94,9 @@ describe Octopress do end it "returns the initial environment value, then after it's changed, returns the new one" do - Octopress.env.must_equal 'value_a' + Octopress.env.should eq('value_a') ENV['OCTOPRESS_ENV'] = 'value_b' - Octopress.env.must_equal 'value_b' + Octopress.env.should eq('value_b') end end end diff --git a/lib/spec/spec_helper.rb b/lib/spec/spec_helper.rb new file mode 100644 index 0000000..5b9d654 --- /dev/null +++ b/lib/spec/spec_helper.rb @@ -0,0 +1,19 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +require File.expand_path("../../octopress", __FILE__) +require 'rspec' +require 'rspec/autorun' + +# Requires supporting ruby files with custom matchers and macros, etc, +# in spec/support/ and its subdirectories. +Dir[Octopress.lib_root.concat("spec/support/**/*.rb")].each {|f| require f} + +RSpec.configure do |config| + # Include FactoryGirl helpers + # config.include FactoryGirl::Syntax::Methods + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = "random" +end