Sha256: 6730dc4925a5a12030de3b47257bd50b80e5edb2ea5d0cb50f0be1ab1577c498

Contents?: true

Size: 1.91 KB

Versions: 11

Compression:

Stored size: 1.91 KB

Contents

require 'spec_helper'

unless defined?(Rails)
  module Rails
    def self.root; end
  end
end

describe "asset_sync.rake" do
  let :rake do
    Rake.application = Rake::Application.new
  end

  let :load_path do
    [File.expand_path(File.join(File.dirname(__FILE__), "../../../../lib/nightcrawler_swift/tasks"))]
  end

  before do
    rake.rake_require "asset_sync", load_path, []

    Rake::Task.define_task("environment")
    Rake::Task.define_task("assets:precompile")
  end

  describe "nightcrawler_swift:rails:sync" do
    let(:task_name) { "nightcrawler_swift:rails:sync" }
    subject { rake[task_name] }

    before do
      allow(Rails).to receive(:root).and_return(".")
    end

    it "requires environment and assets:precompile" do
      expect(subject.prerequisites).to include "environment"
    end

    it "calls sync with Rails public dir path" do
      expect(NightcrawlerSwift).to receive(:sync).with("./public")
      subject.invoke
    end

    context "when occurs an error" do
      it "exits with code 1" do
        allow(STDERR).to receive(:puts)
        allow(NightcrawlerSwift).to receive(:sync).and_raise(StandardError.new)
        code = "wrong code"

        begin
          subject.invoke
        rescue SystemExit => e
          code = e.status
        end

        expect(code).to eql(1)
      end
    end
  end

  describe "nightcrawler_swift:rails:asset_sync" do
    let(:task_name) { "nightcrawler_swift:rails:asset_sync" }
    subject { rake[task_name] }

    it "calls 'assets:precompile' and 'nightcrawler_swift:rails:sync'" do
      task1 = double("task1", invoke: true)
      task2 = double("task2", invoke: true)

      expect(Rake::Task).to receive(:[]).with("assets:precompile").and_return(task1)
      expect(Rake::Task).to receive(:[]).with("nightcrawler_swift:rails:sync").and_return(task2)
      expect(task1).to receive(:invoke)
      expect(task2).to receive(:invoke)

      subject.invoke
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
nightcrawler_swift-1.0.0 spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
nightcrawler_swift-0.11.1 spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
nightcrawler_swift-0.11.0 spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
nightcrawler_swift-0.10.0 spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
nightcrawler_swift-0.9.0 spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
nightcrawler_swift-0.8.1 spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
nightcrawler_swift-0.8.0 spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
nightcrawler_swift-0.7.0 spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
nightcrawler_swift-0.6.0 spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
nightcrawler_swift-0.5.0 spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
nightcrawler_swift-0.4.0 spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb