require "spec_helper"

describe Alextra::GenerateTask do
  context "file generation" do
    let(:app_name) { "AppName" }
    let(:file_name) { "app_name.rb" }
    after(:each) { File.delete(file_name) if File.exist?(file_name) }

    describe "generate" do
      it "generates methods based on the json schema" do
        expect do
          Alextra::GenerateTask.new("AppName", "./spec/fixtures/intent_schema.json").run
        end.to change{ Dir.glob(file_name).length }.by(1)

        expect( File.read(file_name) ).to include(
          "require 'alextra'",
          "class #{app_name} < Alextra::Base",
          "def launch(session, request)",
          "def hello_intent(session, request)",
          "def hello_user_intent(session, request)",
          "def end_session(session, request)",
          "run!",
        )
      end
    end
  end
end
