-
Notifications
You must be signed in to change notification settings - Fork 3
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
Introduce support for hanami generate part
#18
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionality-wise, this all looks good!
Though I wonder if there might be a slightly more instructive shape we could give the generated spec file.
There's one real issue with the current spec file: it doesn't really reflect the shape this file will need to take once the tests become real. At that stage, we'll need to be initialising the part manually and passing a value in.
So could we possibly get a little bit closer with our default files? Something like this?
# frozen_string_literal: true
RSpec.describe Bookshelf::Views::Parts::User do
# TODO: detect if we're on a modern enough ruby, then make this `(value:)`, which is so much nicer
subject(:part) { described_class.new(value: value) }
let(:value) {
# Replace this with your domain object
Object.new
}
it "works" do
expect(subject).to be_kind_of(described_class)
end
end
With this as the default spec file, the user:
- Knows they need to pass a value to their part
- Has the code already set up to do so
- Just needs to replace the code inside
let(:value)
- And after that, everything is good to go :)
What do you think?
@timriley A few considerations 👇 .
|
@timriley More considerations on base part and Given the following base part, located at # auto_register: false
# frozen_string_literal: true
module Bookshelf
module Views
class Part < Hanami::View::Part
def inspekt
helper.html.tag(:code, value.inspect)
end
end
end
end How do I unit-test this? # frozen_string_literal: true
RSpec.describe Bookshelf::Views::Part do
subject { described_class.new(value:) }
describe "#inspekt" do
let(:value) { Client.new }
it "works" do
expect(subject.inspekt).to eq(%(<code>#{value.inspect}</code>))
end
end
end With that concrete example, how can we generate a useful, ready-to-go spec file for the base part? # frozen_string_literal: true
RSpec.describe Bookshelf::Views::Part do
subject { described_class.new(value:) }
let(:value) { double("obj") }
it "works" do
expect(subject).to be_kind_of(described_class)
end
end |
Your Proposal for the generated spec is perfect, @jodosha! Also, your proposal just above for the base part's spec looks great to me too! Two thumbs up! |
0ee2c87
to
ed2e01d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Feature
Support RSpec generation for
hanami generate part
(see hanami/cli#117)App
Slice
Ref hanami/cli#117
Ref hanami/cli#113