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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: remove unexpected rspec help output when running rspec. #28

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

kewlar
Copy link
Contributor

@kewlar kewlar commented Dec 2, 2024

Hi,

I've been having an issue that whenever I run rspec on the aoc_rb gem project, in addition to the spec results it also prints an unexpected "help" output which is kind of weird - it looks like it's for RSpec, but on a closer look it's actually for AocRb commands (but it says rspec instead of aoc).

This PR fixes it by moving Thor.start invocation to, what I hope is, a more appropriate place for it - the "bin" files.


Expectation

When running rspec on this project I expect only the results of the specs to be printed.

$ rspec

AocRb::App
  fetch_input
    sends a GET request to AOC for today's input

...some output skipped...

12 examples, 0 failures

Bug

When running rspec I also get the help output of the Thor commands, AocRb::App and AocRb::Cli. Also, weirdly, the help output states rspec instead of aoc.

$ rspec
Commands:
  rspec exec            # executes and optionally submits the puzzle for today, or the specified date
  rspec help [COMMAND]  # Describe available commands or one specific command
  rspec output          # outputs results from your solution for the given day
  rspec prep            # preps everything you need for a new puzzle
  rspec spec            # runs tests for today, or the specified date

Commands:
  rspec help [COMMAND]  # Describe available commands or one specific command
  rspec new NAME        # Creates a new AoC project with the given name


AocRb::App
  fetch_input
    sends a GET request to AOC for today's input

...some output skipped...

12 examples, 0 failures

Fix

Moves Thor.start invocations from the respective class files to their respective "bin" files, so that Thor.start would no longer be called when rspec is loading the classes for the spec run.


Sorry if my description is terse. It's been a while since I contributed.

@pacso
Copy link
Owner

pacso commented Dec 4, 2024

I haven't been able to reproduce this yet. In my project it runs as expected (I hit CTRL+C to prevent it running 10 years worth of tests):

$ rspec
.........................^C
RSpec is shutting down and will print the summary report... Interrupt again to force quit (warning: at_exit hooks will be skipped if you force quit).
.

Finished in 1.06 seconds (files took 0.23402 seconds to load)
26 examples, 0 failures

I'll try again with a fresh project and see if I can reproduce it that way.

@kewlar
Copy link
Contributor Author

kewlar commented Dec 5, 2024

Oh, no, I must have said it wrong.

It happens when I run rspec in the directory of aoc_rb gem.

Full output, so that you could see that these are the gem specs:

📂 gems/aoc_rb ⎇ main ▷ rspec
Commands:
  rspec exec            # executes and optionally submits the puzzle for today, or the specified date
  rspec help [COMMAND]  # Describe available commands or one specific command
  rspec output          # outputs results from your solution for the given day
  rspec prep            # preps everything you need for a new puzzle
  rspec spec            # runs tests for today, or the specified date

Commands:
  rspec help [COMMAND]  # Describe available commands or one specific command
  rspec new NAME        # Creates a new AoC project with the given name


AocRb::App
  fetch_input
    sends a GET request to AOC for today's input
    can override the current date
    saves the downloaded input into the correct challenge directory
  fetch_instructions
    sends a GET request to AOC for today's instructions
    converts the returned HTML into markdown and saves it to the correct challenge directory
    correctly splits the instructions into two files when both parts are returned
  output
    can return output

AocRb::Puzzle
  #padded(day)
    returns 01 for 1
    returns 09 for 9
    returns 12 for 12

AocRb
  has the expected version number

aoc
  can create a new project

Finished in 1.19 seconds (files took 0.3577 seconds to load)
12 examples, 0 failures

It happens when I run tests with rake, too, though the output is different (because the Thor commands receive different arguments then):

📂 gems/aoc_rb ⎇ main ▷ rake
/home/kewlar/.rbenv/versions/3.3.6/bin/ruby -I/home/kewlar/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.2/lib:/home/kewlar/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rspec-support-3.13.1/lib /home/kewlar/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.2/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
Could not find command "__pattern".
Could not find command "__pattern".

AocRb::App
  fetch_input
    sends a GET request to AOC for today's input
    can override the current date
    saves the downloaded input into the correct challenge directory
  fetch_instructions
    sends a GET request to AOC for today's instructions
    converts the returned HTML into markdown and saves it to the correct challenge directory
    correctly splits the instructions into two files when both parts are returned
  output
    can return output

AocRb::Puzzle
  #padded(day)
    returns 01 for 1
    returns 09 for 9
    returns 12 for 12

AocRb
  has the expected version number

aoc
  can create a new project

Finished in 1.16 seconds (files took 0.33341 seconds to load)
12 examples, 0 failures

@pacso
Copy link
Owner

pacso commented Dec 5, 2024

Ah, OK - that makes a lot more sense, and yes I also see the same behaviour.

PR looks good 👍🏻

@pacso pacso added the skip-changelog Skip changelog check label Dec 5, 2024
@pacso pacso merged commit f65866f into pacso:main Dec 5, 2024
7 of 8 checks passed
@kewlar kewlar deleted the fix/unwanted-rspec-help branch December 5, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog Skip changelog check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants