Skip to content

Allow reading the command and status in the exception#71

Merged
albertalef merged 3 commits intoalbertalef:masterfrom
gerases:readable_command_and_status_in_exception
Mar 2, 2026
Merged

Allow reading the command and status in the exception#71
albertalef merged 3 commits intoalbertalef:masterfrom
gerases:readable_command_and_status_in_exception

Conversation

@gerases
Copy link
Copy Markdown
Contributor

@gerases gerases commented Feb 24, 2026

No description provided.

@gerases
Copy link
Copy Markdown
Contributor Author

gerases commented Feb 24, 2026

I noticed that I couldn't examine the command that threw the exception. So it's a quick fix for that.

@albertalef
Copy link
Copy Markdown
Owner

Nice, could you add some test for this? To in some moment some people not remove and break the dev scripts

@albertalef
Copy link
Copy Markdown
Owner

Thanks for the PR

@gerases
Copy link
Copy Markdown
Contributor Author

gerases commented Feb 25, 2026

will do

@gerases
Copy link
Copy Markdown
Contributor Author

gerases commented Feb 25, 2026

Full disclosure, I used AI to help with the spec. I'm not super proficient with specs yet.

@albertalef
Copy link
Copy Markdown
Owner

No problem, thanks for your honesty.

I saw the tests here, but has some things that i like to do a few things that make me sure that the test is covering other possible problems as well.

I will send you here ideas in some hours, and you check what you think

@gerases
Copy link
Copy Markdown
Contributor Author

gerases commented Feb 27, 2026

Sounds good

Comment on lines +3 to +4
require_relative "../lib/rubyshell/error"
require_relative "../lib/rubyshell"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the Rspec are already eagerloading this files, so, is not being needed to require manually

Comment on lines +7 to +17
let(:command) { "ls -z" }
let(:stderr) { "ls: illegal option -- z" }
let(:status) { 1 }

subject(:error) do
described_class.new(
command: command,
stderr: stderr,
status: status
)
end
Copy link
Copy Markdown
Owner

@albertalef albertalef Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, i prefer to use a real system feature to run the test scenario, instead just stub a part of the code.

Instead create a error manually and pass his params, i used to do something like:

let(:error_instance) do
  sh.ls(-z)
rescue error
  error
end

describe 'Methods' do
  describe 'attr_readers' do
    it 'has command reader' do
      expect(error_instance.command).to eq('ls -z')
    end
   
    it 'has status reader' do
      expect(error_instance.status).to eq(1)
    end
  end
end

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. In the expectations, i like to hardcode the expected value to be sure that the tests cannot be changed unintentionally in the future when there are more scenarios.

  2. I like to create some "folder" separations between the tests soon as possible (Using the describe "Methods")

  3. Like i said above, for me, is better to have a test that use the real code to setup the scenario, instead "mocking" the execution to go to a specific way

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to respectfully disagree. Since these tests might run on a user's system and we don't know what he/she might have aliased the command to, I prefer not to invoke any real executables.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly any users machine has the ls command xD.

And the rest of the tests of the lib already use this for validation, so, this will not be a problem here. And if in some situation start to be a problem, we will need to fix in the entire application tests, or the user will run the test on a container (i will be able to configure a docker compose for this).

@albertalef
Copy link
Copy Markdown
Owner

albertalef commented Feb 27, 2026

@gerases See the comments and let me know what you think

@gerases
Copy link
Copy Markdown
Contributor Author

gerases commented Mar 2, 2026

I've refactored the test, let me know if you're ok with it

@albertalef
Copy link
Copy Markdown
Owner

Looks nice! Thanks!

@albertalef albertalef merged commit 13bd40c into albertalef:master Mar 2, 2026
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants