-
Notifications
You must be signed in to change notification settings - Fork 168
Add Ruby workflow for embedded ruby code #707
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
base: main
Are you sure you want to change the base?
Changes from all commits
96f6b52
5cb8402
3db29db
816b026
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| name: Run Specs | ||
| on: [push, pull_request] | ||
|
|
||
| jobs: | ||
| test_embedded_ruby: | ||
| strategy: | ||
| matrix: | ||
| os: [ubuntu-latest, macos-latest] | ||
| ruby: [ '2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4', head] | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: ruby/setup-ruby@v1 | ||
| with: | ||
| ruby-version: ${{ matrix.ruby }} | ||
| - run: bundle install | ||
| working-directory: templatescompiler/erbrenderer/ | ||
| - run: bundle exec rake | ||
| working-directory: templatescompiler/erbrenderer/ | ||
| continue-on-error: ${{ matrix.ruby == 'head' }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Gemfile.lock |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| source "https://rubygems.org" | ||
|
|
||
| group :test do | ||
| gem "rake" | ||
| gem "rspec" | ||
| gem "standardrb" | ||
| end | ||
|
Comment on lines
+1
to
+7
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| require "rspec/core/rake_task" | ||
| require "standard/rake" | ||
|
|
||
| RSpec::Core::RakeTask.new(:spec) | ||
|
|
||
| task default: [:standard, :spec] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| require "spec_helper" | ||
| require "erb_renderer" | ||
|
|
||
| RSpec.describe "erb_renderer" do | ||
| describe "ERBRenderer" do | ||
| let(:test_tmpdir) { Dir.tmpdir } | ||
| let(:json_context_path) { File.join(test_tmpdir, "context.json") } | ||
|
|
||
aramprice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| before do | ||
| File.write(json_context_path, context_hash.to_json) | ||
| end | ||
|
|
||
| after do | ||
| File.unlink(json_context_path) if File.exist?(json_context_path) | ||
| end | ||
|
|
||
| describe "#initialize" do | ||
| let(:context_hash) { {} } | ||
|
|
||
| it "does not raise an error" do | ||
| expect { ERBRenderer.new(json_context_path) }.not_to raise_error | ||
| end | ||
| end | ||
|
|
||
| describe "#render" do | ||
| let(:context_hash) do | ||
| { | ||
| index: 867_5309, | ||
| global_properties: { | ||
| property1: "global_value1" | ||
| }, | ||
| cluster_properties: { | ||
| property2: "cluster_value1" | ||
| }, | ||
| default_properties: { | ||
| property1: "default_value1", | ||
| property2: "default_value2", | ||
| property3: "default_value3" | ||
| } | ||
| } | ||
| end | ||
|
|
||
| let(:erb_template_path) { File.join(test_tmpdir, "template.yml.erb") } | ||
| let(:erb_content) do | ||
| <<~TEST_TEMPLATE | ||
| --- | ||
| property1: <%= p('property1') %> | ||
| property2: <%= p('property2') %> | ||
| property3: <%= p('property3') %> | ||
| TEST_TEMPLATE | ||
| end | ||
|
|
||
| let(:rendered_template_path) { File.join(test_tmpdir, "template.yml") } | ||
| let(:expected_template_content) do | ||
| <<~EXPECTED_TEMPLATE | ||
| --- | ||
| property1: global_value1 | ||
| property2: cluster_value1 | ||
| property3: default_value3 | ||
| EXPECTED_TEMPLATE | ||
| end | ||
|
|
||
| let(:erb_renderer) { ERBRenderer.new(json_context_path) } | ||
|
|
||
| before do | ||
| File.write(erb_template_path, erb_content) | ||
| end | ||
|
|
||
| it "does not raise an error" do | ||
| expect { erb_renderer.render(erb_template_path, rendered_template_path) }.not_to raise_error | ||
| end | ||
|
|
||
| it "renders the expected content" do | ||
| erb_renderer.render(erb_template_path, rendered_template_path) | ||
| expect(File.read(rendered_template_path)).to eq(expected_template_content) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| require "rspec" | ||
| require "json" | ||
| require "tmpdir" | ||
|
|
||
| ERB_RENDERER_ROOT = File.expand_path("..", File.dirname(__FILE__)) | ||
|
|
||
| $LOAD_PATH.unshift(ERB_RENDERER_ROOT) |
Uh oh!
There was an error while loading. Please reload this page.