Sha256: e908849808fea61701d646e869049f868aa16a5a7917dd3b72bec74a60e6b53d

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

require 'spec_helper'
require 'rake'

module RakeDashboard
  RSpec.describe TasksController, type: :controller do

    routes { RakeDashboard::Engine.routes }

    before do
      Dummy::Application.load_tasks
    end

    let(:tasks) { Rake::Task.tasks }

    describe "GET #index" do
      it "returns http success" do
        get :index
        expect(response).to have_http_status(:success)
      end

      it "should have tasks assigned from the configuration" do
        RakeDashboard.tasks = tasks
        get :index
        expect(assigns(:tasks)).to eql(tasks)
      end


    end

    describe "POST #create" do
      let(:task) { double("task") }
      before do
        allow(task).to receive(:invoke) { puts "invoked!" }
        allow(Rake::Task).to receive(:[]).with("secret").and_return(task)
      end

      it "returns http success" do
        post :create, task: :secret
        expect(response).to have_http_status(:success)
      end

      it "should invoke the passed rake task" do
        expect(Rake::Task).to receive(:[]).with("secret").and_return(task)

        post :create, task: :secret
        expect(response).to have_http_status(:success)
      end

      it "should respond with the task ouput" do
        expect(Rake::Task).to receive(:[]).with("secret").and_return(task)

        post :create, task: :secret
        expect(response.body).to eql("<pre>invoked!\n</pre>")
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rake_dashboard-0.2.0 spec/controllers/rake_dashboard/tasks_controller_spec.rb
rake_dashboard-0.1.0 spec/controllers/rake_dashboard/tasks_controller_spec.rb