Skip to content

What about improving the README about testing? #103

@blocknotes

Description

@blocknotes

Thank you for this nice gem! 😄
In past I used the Interactor gem quite a lot, I recently switched to Actor and I find it a nice improvement.

As in the subject: perhaps it could be nice to suggest some testing strategies for actors.

For example, with RSpec I recently wrote something like this:

RSpec.describe ParseFileName, type: :actor do
  describe ".result" do
    subject(:result) { described_class.result(file_name:) }

    context "with a valid file_name" do
      let(:file_name) { "sample_file_name_20221229010101.csv" }

      it { expect(result).to be_a_success }

      it "parses the file_name and returns an Hash" do
        expected_hash = {
          prefix: :sample,
          name: "file_name",
          timestamp: Time.zone.strptime("20221229010101", "%Y%m%d%H%M%S")
        }
        expect(result.formatted_attributes).to eq expected_hash
      end
    end

    context "with an invalid file_name" do
      let(:file_name) { "wrong_name.csv" }

      it { expect(result).to be_a_failure }
      it { expect(result.error).to eq "Invalid format for \"#{file_name}\"" }
    end
  end
end

In this case I preferred to use result to avoid checking exceptions.

WDYT?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions