Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

What about improving the README about testing? #103

Closed
blocknotes opened this issue Dec 29, 2022 · 1 comment
Closed

What about improving the README about testing? #103

blocknotes opened this issue Dec 29, 2022 · 1 comment

Comments

@blocknotes
Copy link

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?

@sunny
Copy link
Owner

sunny commented Dec 29, 2022

Thank you! 馃

I wouldn鈥檛 want to add too much to the README as it鈥檚 big enough already.

I鈥檝e added this to the Wiki, as a link pointing directly to this issue since your spec is a perfectly good example of using RSpec with Actor. 馃帀

If you think of more testing strategies, we could eventually turn this into a page, but a link should do the trick for now.

@sunny sunny closed this as completed Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants