Sha256: 4b0e35ab82a7314703529ab1f6a89e6b90475adf106af139179f0079adf25f9b

Contents?: true

Size: 1.82 KB

Versions: 5

Compression:

Stored size: 1.82 KB

Contents

require 'spec_helper'

describe Riveter::Command do
  it_should_behave_like "a class with attributes", TestCommand

  describe "class" do
    subject { TestCommand }

    describe ".command_name" do
      it { should respond_to(:command_name) }
      it { subject.command_name.should be_a(ActiveModel::Name) }
    end

    describe ".i18n_scope" do
      it { should respond_to(:i18n_scope) }
      it { subject.i18n_scope.should eq(:commands) }
    end

    describe ".success_notice" do
      it { should respond_to(:success_notice) }
      it { subject.success_notice.should eq('Successfully executed Test command.') }
    end
  end

  describe "instance" do
    subject { TestCommand.new() }

    describe "#can_perform?" do
      it "should yield false when invalid" do
        subject.can_perform?.should be_false
      end

      it "should yield true when valid" do
        subject.name = 'test'
        subject.can_perform?.should be_true
      end
    end

    describe "#submit" do
      it "should yield false when invalid" do
        subject.submit().should be_false
      end

      it "should yield true when valid" do
        allow(subject).to receive(:perform) { true }

        subject.name = 'test'
        subject.submit().should be_true
      end

      it "should assign attributes" do
        allow(subject).to receive(:perform) { true }

        subject.submit(:name => 'test')
        subject.name.should eq('test')
      end

      it "should not assign unknown attributes" do
        subject.submit(:unknown => 'test')
        subject.name.should be_blank
      end

      it "should invoke associated service" do
        allow(subject).to receive(:valid?) { true }
        expect_any_instance_of(TestService).to receive(:perform).with(subject, :arg) { true }

        subject.submit(:arg, :name => 'test')
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
riveter-0.0.7 spec/riveter/command_spec.rb
riveter-0.0.6 spec/riveter/command_spec.rb
riveter-0.0.5 spec/riveter/command_spec.rb
riveter-0.0.4 spec/riveter/command_spec.rb
riveter-0.0.3 spec/riveter/command_spec.rb