-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for RSpec to previews as test cases (#1408)
* Add rspec-rails gem * Add support for render_previews in RSpec tests * Enable RSpec tests on CI * Update lib/view_component/render_preview_helper.rb * Update lib/view_component/render_preview_helper.rb * Update Gemfile Co-authored-by: Joel Hawksley <[email protected]>
- Loading branch information
1 parent
386279b
commit 5b9dad7
Showing
14 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../test/sandbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require "simplecov" | ||
require "simplecov-console" | ||
|
||
if ENV["MEASURE_COVERAGE"] | ||
SimpleCov.start do | ||
command_name "rails#{ENV["RAILS_VERSION"]}-ruby#{ENV["RUBY_VERSION"]}" if ENV["RUBY_VERSION"] | ||
|
||
formatter SimpleCov::Formatter::Console | ||
end | ||
end | ||
|
||
require "bundler/setup" | ||
|
||
# Configure Rails Environment | ||
ENV["RAILS_ENV"] = "test" | ||
|
||
require "view_component/deprecation" | ||
ViewComponent::Deprecation.behavior = :silence | ||
|
||
require File.expand_path("../sandbox/config/environment.rb", __FILE__) | ||
require "rspec/rails" | ||
|
||
RSpec.configure do |config| | ||
config.include ViewComponent::TestHelpers | ||
end |
25 changes: 25 additions & 0 deletions
25
test/sandbox/spec/components/previews/preview_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
describe PreviewComponent do | ||
include ViewComponent::RenderPreviewHelper | ||
|
||
before do | ||
ViewComponent::Preview.load_previews | ||
end | ||
|
||
it "renders the preview" do | ||
render_preview(:default) | ||
|
||
expect(page).to have_css "h1", text: "Lorem Ipsum" | ||
end | ||
end | ||
|
||
describe "PreviewComponent" do | ||
include ViewComponent::RenderPreviewHelper | ||
|
||
before do | ||
ViewComponent::Preview.load_previews | ||
end | ||
|
||
it "raises an error" do | ||
expect { render_preview(:default) }.to raise_error(/expected a described_class/) | ||
end | ||
end |