diff --git a/.github/workflows/examples-wkhtmltopdf_rspec.yml b/.github/workflows/examples-wkhtmltopdf_rspec.yml
new file mode 100644
index 0000000..8c57c6a
--- /dev/null
+++ b/.github/workflows/examples-wkhtmltopdf_rspec.yml
@@ -0,0 +1,28 @@
+name: "Examples: wkhtmltopdf module (RSpec)"
+
+on:
+ push:
+ branches:
+ - main
+
+ pull_request:
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ name: Ruby ${{ matrix.ruby }}
+ strategy:
+ matrix:
+ ruby:
+ - '3.2.0'
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Ruby
+ uses: ruby/setup-ruby@v1
+ with:
+ ruby-version: ${{ matrix.ruby }}
+ bundler-cache: true
+ - name: Run the example
+ working-directory: ./examples
+ run: ruby wkhtmltopdf_rspec.rb
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index f6216f2..c73cb0f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,4 +6,7 @@
/pkg/
/spec/reports/
/tmp/
+/examples/tmp/*.pdf
*.gem
+.DS_Store
+.tool-versions
diff --git a/Gemfile.lock b/Gemfile.lock
index b86a79e..9533ff9 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -140,7 +140,9 @@ GEM
yard (0.9.34)
PLATFORMS
+ -darwin-21
arm64-darwin-21
+ arm64-darwin-22
x86_64-darwin-22
x86_64-linux
diff --git a/examples/fixtures/web_page/index.html b/examples/fixtures/web_page/index.html
new file mode 100644
index 0000000..791fe91
--- /dev/null
+++ b/examples/fixtures/web_page/index.html
@@ -0,0 +1,168 @@
+
+
+
+
+
+
+
+
+
+ Sticky Footer Template ยท Bootstrap v5.3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/fixtures/web_page/styles.css b/examples/fixtures/web_page/styles.css
new file mode 100644
index 0000000..f8be437
--- /dev/null
+++ b/examples/fixtures/web_page/styles.css
@@ -0,0 +1,9 @@
+/* Custom page CSS
+-------------------------------------------------- */
+/* Not required for template or sticky footer method. */
+
+.container {
+ width: auto;
+ max-width: 680px;
+ padding: 0 15px;
+}
diff --git a/examples/tmp/.gitkeep b/examples/tmp/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/examples/wkhtmltopdf_rspec.rb b/examples/wkhtmltopdf_rspec.rb
new file mode 100644
index 0000000..cd54efe
--- /dev/null
+++ b/examples/wkhtmltopdf_rspec.rb
@@ -0,0 +1,62 @@
+require "bundler/inline"
+
+gemfile do
+ source "https://rubygems.org"
+ gem "rspec"
+ gem "wkhtmltopdf-binary"
+ gem "testcontainers-core", path: "../core", require: "testcontainers"
+
+ group :test do
+ gem "webmock"
+ end
+end
+
+require "rspec"
+require "rspec/autorun"
+require "webmock/rspec"
+
+RSpec.configure do |config|
+end
+
+RSpec::Matchers.define :exist_file do
+ match do |file_path|
+ File.exist?(file_path)
+ end
+end
+
+describe "Wkhtmltopdf Example" do
+ let(:url) { "https://getbootstrap.com/docs/5.3/examples/sticky-footer/" }
+ let(:pdfs_path) { "#{__dir__}/tmp:/tmp:rw" }
+ let(:command) { [url, file_name] }
+ let(:file_name) { "/tmp/document.pdf" }
+ let(:file_path) { "#{__dir__}#{file_name}" }
+ let(:container) do
+ Testcontainers::DockerContainer.new("surnet/alpine-wkhtmltopdf:3.17.0-0.12.6-small")
+ end
+
+ before do
+ WebMock.allow_net_connect!
+ container.with_filesystem_binds([pdfs_path])
+ end
+
+ after(:each) do
+ WebMock.allow_net_connect!
+ container&.stop
+ container&.remove
+ end
+
+ context "when using html" do
+ before(:each) do
+ stub_request(:get, url).to_return(
+ body: File.read("#{__dir__}/fixtures/web_page/index.html")
+ )
+ end
+
+ it "generates a PDF page" do
+ container.with_command(command)
+ container.start
+
+ expect(file_path).to exist_file
+ end
+ end
+end