-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add automated tests for HTML generation
- Loading branch information
1 parent
eefa5c2
commit 4c9bd79
Showing
12 changed files
with
391 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spec/examples.txt |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# https://docs.rubocop.org/rubocop/configuration | ||
|
||
require: | ||
- rubocop-capybara | ||
- rubocop-rspec | ||
|
||
AllCops: | ||
NewCops: enable | ||
TargetRubyVersion: 3.3 | ||
|
||
Style/TrailingCommaInArguments: | ||
EnforcedStyleForMultiline: consistent_comma | ||
|
||
Style/TrailingCommaInArrayLiteral: | ||
EnforcedStyleForMultiline: consistent_comma | ||
|
||
Style/TrailingCommaInHashLiteral: | ||
EnforcedStyleForMultiline: consistent_comma | ||
|
||
Metrics/AbcSize: | ||
Enabled: false | ||
|
||
Metrics/MethodLength: | ||
Max: 50 | ||
|
||
RSpec/ExampleLength: | ||
Max: 50 | ||
|
||
RSpecRails/InferredSpecType: | ||
Enabled: false |
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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
gem 'capybara', '~> 3.40' | ||
gem 'rspec', '~> 3.13' | ||
gem 'selenium-webdriver', '~> 4.20' | ||
gem 'webrick', '~> 1.8' | ||
|
||
gem 'rubocop', '~> 1.63', require: false | ||
gem 'rubocop-capybara', '~> 2.20', require: false | ||
gem 'rubocop-rspec', '~> 2.29', require: false |
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,114 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
addressable (2.8.6) | ||
public_suffix (>= 2.0.2, < 6.0) | ||
ast (2.4.2) | ||
base64 (0.2.0) | ||
capybara (3.40.0) | ||
addressable | ||
matrix | ||
mini_mime (>= 0.1.3) | ||
nokogiri (~> 1.11) | ||
rack (>= 1.6.0) | ||
rack-test (>= 0.6.3) | ||
regexp_parser (>= 1.5, < 3.0) | ||
xpath (~> 3.2) | ||
diff-lcs (1.5.1) | ||
json (2.7.2) | ||
language_server-protocol (3.17.0.3) | ||
matrix (0.4.2) | ||
mini_mime (1.1.5) | ||
nokogiri (1.16.4-aarch64-linux) | ||
racc (~> 1.4) | ||
nokogiri (1.16.4-arm-linux) | ||
racc (~> 1.4) | ||
nokogiri (1.16.4-arm64-darwin) | ||
racc (~> 1.4) | ||
nokogiri (1.16.4-x86-linux) | ||
racc (~> 1.4) | ||
nokogiri (1.16.4-x86_64-darwin) | ||
racc (~> 1.4) | ||
nokogiri (1.16.4-x86_64-linux) | ||
racc (~> 1.4) | ||
parallel (1.24.0) | ||
parser (3.3.1.0) | ||
ast (~> 2.4.1) | ||
racc | ||
public_suffix (5.0.5) | ||
racc (1.7.3) | ||
rack (3.0.10) | ||
rack-test (2.1.0) | ||
rack (>= 1.3) | ||
rainbow (3.1.1) | ||
regexp_parser (2.9.0) | ||
rexml (3.2.6) | ||
rspec (3.13.0) | ||
rspec-core (~> 3.13.0) | ||
rspec-expectations (~> 3.13.0) | ||
rspec-mocks (~> 3.13.0) | ||
rspec-core (3.13.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-expectations (3.13.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-mocks (3.13.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-support (3.13.1) | ||
rubocop (1.63.4) | ||
json (~> 2.3) | ||
language_server-protocol (>= 3.17.0) | ||
parallel (~> 1.10) | ||
parser (>= 3.3.0.2) | ||
rainbow (>= 2.2.2, < 4.0) | ||
regexp_parser (>= 1.8, < 3.0) | ||
rexml (>= 3.2.5, < 4.0) | ||
rubocop-ast (>= 1.31.1, < 2.0) | ||
ruby-progressbar (~> 1.7) | ||
unicode-display_width (>= 2.4.0, < 3.0) | ||
rubocop-ast (1.31.3) | ||
parser (>= 3.3.1.0) | ||
rubocop-capybara (2.20.0) | ||
rubocop (~> 1.41) | ||
rubocop-factory_bot (2.25.1) | ||
rubocop (~> 1.41) | ||
rubocop-rspec (2.29.1) | ||
rubocop (~> 1.40) | ||
rubocop-capybara (~> 2.17) | ||
rubocop-factory_bot (~> 2.22) | ||
rubocop-rspec_rails (~> 2.28) | ||
rubocop-rspec_rails (2.28.3) | ||
rubocop (~> 1.40) | ||
ruby-progressbar (1.13.0) | ||
rubyzip (2.3.2) | ||
selenium-webdriver (4.20.1) | ||
base64 (~> 0.2) | ||
rexml (~> 3.2, >= 3.2.5) | ||
rubyzip (>= 1.2.2, < 3.0) | ||
websocket (~> 1.0) | ||
unicode-display_width (2.5.0) | ||
webrick (1.8.1) | ||
websocket (1.2.10) | ||
xpath (3.2.0) | ||
nokogiri (~> 1.8) | ||
|
||
PLATFORMS | ||
aarch64-linux | ||
arm-linux | ||
arm64-darwin | ||
x86-linux | ||
x86_64-darwin | ||
x86_64-linux | ||
|
||
DEPENDENCIES | ||
capybara (~> 3.40) | ||
rspec (~> 3.13) | ||
rubocop (~> 1.63) | ||
rubocop-capybara (~> 2.20) | ||
rubocop-rspec (~> 2.29) | ||
selenium-webdriver (~> 4.20) | ||
webrick (~> 1.8) | ||
|
||
BUNDLED WITH | ||
2.5.9 |
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,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'scratch_space' | ||
|
||
RSpec.describe 'The crate list', type: :feature do | ||
let(:scratch) { ScratchSpace.new } | ||
let(:registry) { scratch.registry } | ||
|
||
before { registry.start } | ||
|
||
after do | ||
registry.stop | ||
scratch.cleanup | ||
end | ||
|
||
it 'shows the crate and version' do | ||
names = %w[a bb ccc dddd] | ||
|
||
names.each do |name| | ||
scratch | ||
.crate(name:, version: '1.0.0') | ||
.lib_rs(%(pub const ID: &str = "#{name}";)) | ||
.publish_to(registry) | ||
end | ||
|
||
visit registry.url | ||
|
||
within(:section, 'Available crates') do | ||
names.each do |name| | ||
aggregate_failures do | ||
expect(page).to have_content(name) | ||
expect(page).to have_select('version', with_options: ['1.0.0']) | ||
end | ||
end | ||
end | ||
end | ||
|
||
Capybara.add_selector(:section) do | ||
xpath { |title| ".//section[h1[contains(., '#{title}')]]" } | ||
end | ||
end |
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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'capybara/rspec' | ||
|
||
$LOAD_PATH << 'spec/support' | ||
|
||
RSpec.configure do |config| | ||
config.expect_with :rspec do |expectations| | ||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true | ||
end | ||
|
||
config.mock_with :rspec do |mocks| | ||
mocks.verify_partial_doubles = true | ||
end | ||
|
||
config.shared_context_metadata_behavior = :apply_to_host_groups | ||
|
||
config.filter_run_when_matching :focus | ||
|
||
config.example_status_persistence_file_path = 'spec/examples.txt' | ||
|
||
config.disable_monkey_patching! | ||
|
||
config.warnings = true | ||
|
||
config.default_formatter = 'doc' if config.files_to_run.one? | ||
|
||
config.profile_examples = 10 | ||
|
||
config.order = :random | ||
Kernel.srand config.seed | ||
end | ||
|
||
Capybara.default_driver = Capybara.javascript_driver = :selenium_headless | ||
Capybara.run_server = false |
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,53 @@ | ||
# frozen_string_literal: true | ||
|
||
class Crate | ||
attr_reader :name, :version | ||
|
||
def initialize(name:, version:, root:) | ||
@name = name | ||
@version = version | ||
@root = root | ||
@source = {} | ||
end | ||
|
||
def lib_rs(content) | ||
@source['lib.rs'] = content | ||
self | ||
end | ||
|
||
def publish_to(registry) | ||
Dir.mkdir(@root) | ||
|
||
cargo_toml = @root.join('Cargo.toml') | ||
File.open(cargo_toml, 'w') do |f| | ||
content = <<~TOML | ||
[package] | ||
name = "#{@name}" | ||
version = "#{@version}" | ||
edition = "2021" | ||
TOML | ||
f.write(content) | ||
end | ||
|
||
src = @root.join('src') | ||
Dir.mkdir(src) | ||
|
||
@source.each do |name, content| | ||
file = src.join(name) | ||
File.write(file, content) | ||
end | ||
|
||
system('cargo', 'package', '--quiet', chdir: @root, exception: true) | ||
package = @root.join('target', 'package', "#{name}-#{version}.crate") | ||
|
||
system( | ||
'../target/debug/margo', | ||
'add', | ||
'--registry', | ||
registry.root.to_s, | ||
package.to_s, | ||
%i[out err] => File::NULL, | ||
exception: true, | ||
) | ||
end | ||
end |
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,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'registry_server' | ||
|
||
class Registry | ||
attr_reader :root | ||
|
||
def initialize(root) | ||
@root = root | ||
@server = RegistryServer.new(@root) | ||
end | ||
|
||
def start | ||
@server.start | ||
system( | ||
'../target/debug/margo', | ||
'init', | ||
'--base-url', | ||
url, | ||
# TODO: Add a `--defaults` | ||
'--html', | ||
'true', | ||
'--html-suggested-registry-name', | ||
'qwidge', | ||
@root.to_s, | ||
%i[out err] => File::NULL, | ||
exception: true, | ||
) | ||
end | ||
|
||
def stop | ||
@server.stop | ||
end | ||
|
||
def url | ||
@server.url | ||
end | ||
end |
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,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'webrick' | ||
|
||
class RegistryServer | ||
def initialize(root) | ||
@server = WEBrick::HTTPServer.new( | ||
DocumentRoot: root, | ||
BindAddress: '127.0.0.1', | ||
Port: 0, | ||
Logger: WEBrick::Log.new(IO::NULL), | ||
AccessLog: [], | ||
) | ||
end | ||
|
||
def start | ||
@thread = Thread.new do | ||
@server.start | ||
end | ||
end | ||
|
||
def stop | ||
@server.shutdown | ||
@thread.join | ||
end | ||
|
||
def url | ||
"http://#{address}:#{port}/" | ||
end | ||
|
||
def address | ||
@server.config[:BindAddress] | ||
end | ||
|
||
def port | ||
@server.config[:Port] | ||
end | ||
end |
Oops, something went wrong.