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

Change the default generated request spec for hanami new #19

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

jodosha
Copy link
Member

@jodosha jodosha commented Oct 24, 2023

Fix

As of 2.1.0, we don't generate a default route anymore.
As a result, in the test environment, a GET request to / is a 404 (Not Found).

The default request spec is used to assert that the root path was successfully found (200).
Running for the first time the specs, after generating the app results in a failing test.

👉 While having a failing test is in line with TDD/BDD philosophy as a clear indicator to implement a missing feature, the experience can be unpleasant for newcomers.
The uncertainty of trying a new framework can be a source of anxiety, and seeing a failing test can have negative emotional imprinting.

👉 My take is to generate a test that expects a 404.
It communicates to the user that we decided to generate an app with a missing root route.
Reassuring twice for the user: it's not them, Hanami team knows what they're doing.


Before

Negative imprinting: failing spec.

⚡ bundle exec rake
/Users/jodosha/.rubies/ruby-3.2.2/bin/ruby -I/Users/jodosha/.gem/ruby/3.2.2/gems/rspec-core-3.12.2/lib:/Users/jodosha/.gem/ruby/3.2.2/gems/rspec-support-3.12.1/lib /Users/jodosha/.gem/ruby/3.2.2/gems/rspec-core-3.12.2/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb

Randomized with seed 42204

Root
  is successful (FAILED - 1)

Failures:

  1) Root is successful
     Failure/Error: expect(last_response).to be_successful
       expected `#<Rack::MockResponse:0x000000010c312b28 @original_headers={"Content-Type"=>"text/plain; charset=utf-8...:45:in `invoke'\n - rspec-core (3.12.2) exe/rspec:4:in `<main>'\n\n"], @buffered=true, @length=4094>.successful?` to be truthy, got false
     # ./spec/requests/root_spec.rb:8:in `block (2 levels) in <top (required)>'

Top 1 slowest examples (0.07353 seconds, 95.7% of total time):
  Root is successful
    0.07353 seconds ./spec/requests/root_spec.rb:4

Finished in 0.07687 seconds (files took 0.4163 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/requests/root_spec.rb:4 # Root is successful

Randomized with seed 42204

/Users/jodosha/.rubies/ruby-3.2.2/bin/ruby -I/Users/jodosha/.gem/ruby/3.2.2/gems/rspec-core-3.12.2/lib:/Users/jodosha/.gem/ruby/3.2.2/gems/rspec-support-3.12.1/lib /Users/jodosha/.gem/ruby/3.2.2/gems/rspec-core-3.12.2/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb failed

After

Positive imprinting: passing spec.

⚡ bundle exec rake
/Users/jodosha/.rubies/ruby-3.2.2/bin/ruby -I/Users/jodosha/.gem/ruby/3.2.2/gems/rspec-core-3.12.2/lib:/Users/jodosha/.gem/ruby/3.2.2/gems/rspec-support-3.12.1/lib /Users/jodosha/.gem/ruby/3.2.2/gems/rspec-core-3.12.2/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb

Randomized with seed 59621

Root
  is not found

Top 1 slowest examples (0.06069 seconds, 95.3% of total time):
  Root is not found
    0.06069 seconds ./spec/requests/root_spec.rb:4

Finished in 0.0637 seconds (files took 0.3812 seconds to load)
1 example, 0 failures

Randomized with seed 59621

Closes #17

@jodosha jodosha self-assigned this Oct 24, 2023
@jodosha jodosha added this to the v2.1.0 milestone Oct 24, 2023
@jodosha jodosha added the bug Something isn't working label Oct 24, 2023
@jodosha jodosha requested a review from a team October 24, 2023 08:21
Copy link
Member

@timriley timriley left a comment

Choose a reason for hiding this comment

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

This makes a lot of sense to me 👍🏼

Thanks for picking this up. 🙏🏼 When preparing the way for the welcome page (i.e. when I removed the default route), it was definitely not my intention to leave new apps with a failing spec.

@jodosha jodosha merged commit 6351998 into main Oct 24, 2023
9 checks passed
@jodosha jodosha deleted the fix/hanami-new-default-request-test branch October 24, 2023 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change the generated default RSpec request test
2 participants