Skip to content

Commit

Permalink
Introduce let(:value)
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Oct 26, 2023
1 parent b6feb2a commit ed2e01d
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 89 deletions.
3 changes: 2 additions & 1 deletion lib/hanami/rspec/generators/part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def template(path, context)
require "erb"

ERB.new(
File.read(__dir__ + "/part/#{path}")
File.read(__dir__ + "/part/#{path}"),
trim_mode: "-"
).result(context.ctx)
end

Expand Down
7 changes: 7 additions & 0 deletions lib/hanami/rspec/generators/part/part_base_spec.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# frozen_string_literal: true

RSpec.describe <%= camelized_app_name %>::Views::Part do
<%- if ruby_implicity_keyword_argument? -%>
subject { described_class.new(value:) }
<%- else -%>
subject { described_class.new(value: value) }
<%- end -%>
let(:value) { double("value") }

it "works" do
expect(subject).to be_kind_of(described_class)
end
Expand Down
7 changes: 7 additions & 0 deletions lib/hanami/rspec/generators/part/part_slice_base_spec.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# frozen_string_literal: true

RSpec.describe <%= camelized_slice_name %>::Views::Part do
<%- if ruby_implicity_keyword_argument? -%>
subject { described_class.new(value:) }
<%- else -%>
subject { described_class.new(value: value) }
<%- end -%>
let(:value) { double("value") }

it "works" do
expect(subject).to be_kind_of(described_class)
end
Expand Down
7 changes: 7 additions & 0 deletions lib/hanami/rspec/generators/part/part_slice_spec.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# frozen_string_literal: true

RSpec.describe <%= camelized_slice_name %>::Views::Parts::<%= camelized_name %> do
<%- if ruby_implicity_keyword_argument? -%>
subject { described_class.new(value:) }
<%- else -%>
subject { described_class.new(value: value) }
<%- end -%>
let(:value) { double("<%= underscored_name %>") }

it "works" do
expect(subject).to be_kind_of(described_class)
end
Expand Down
7 changes: 7 additions & 0 deletions lib/hanami/rspec/generators/part/part_spec.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# frozen_string_literal: true

RSpec.describe <%= camelized_app_name %>::Views::Parts::<%= camelized_name %> do
<%- if ruby_implicity_keyword_argument? -%>
subject { described_class.new(value:) }
<%- else -%>
subject { described_class.new(value: value) }
<%- end -%>
let(:value) { double("<%= underscored_name %>") }

it "works" do
expect(subject).to be_kind_of(described_class)
end
Expand Down
9 changes: 7 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

require "hanami/rspec"
require "fileutils"

TMP = File.join(Dir.pwd, "tmp")

RSpec.configure do |config|
config.expect_with :rspec do |expectations|
Expand All @@ -11,6 +14,10 @@
mocks.verify_partial_doubles = true
end

config.after do
FileUtils.rm_rf(TMP) if File.directory?(TMP)
end

config.shared_context_metadata_behavior = :apply_to_host_groups

config.filter_run_when_matching :focus
Expand All @@ -28,5 +35,3 @@

Kernel.srand config.seed
end

TMP = File.join(Dir.pwd, "tmp")
Loading

0 comments on commit ed2e01d

Please sign in to comment.