Skip to content

Commit 77f85c0

Browse files
authored
Merge pull request #27 from gravitystorm/rspec
Add rspec and some basic tests
2 parents cd68d77 + 29d4075 commit 77f85c0

File tree

7 files changed

+207
-1
lines changed

7 files changed

+207
-1
lines changed

.github/workflows/rspec.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Rspec
2+
on:
3+
- push
4+
- pull_request
5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
7+
cancel-in-progress: true
8+
env:
9+
ruby: '3.5'
10+
jobs:
11+
rspec:
12+
name: Rspec
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out code
16+
uses: actions/checkout@v4
17+
- name: Setup ruby
18+
uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: ${{ env.ruby }}
21+
rubygems: 3.4.10
22+
bundler-cache: true
23+
- name: Run rspec
24+
run: bundle exec rspec

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--require spec_helper

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
inherit_from: .rubocop_todo.yml
33

4+
plugins:
5+
- rubocop-rspec
6+
47
AllCops:
58
TargetRubyVersion: 2.7
69

.rubocop_todo.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2025-09-19 19:11:34 UTC using RuboCop version 1.80.2.
3+
# on 2025-11-28 15:41:06 UTC using RuboCop version 1.81.7.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -36,6 +36,11 @@ Naming/AccessorMethodName:
3636
Exclude:
3737
- 'lib/glug/layer.rb'
3838

39+
# Offense count: 1
40+
# Configuration parameters: CountAsOne.
41+
RSpec/ExampleLength:
42+
Max: 53
43+
3944
# Offense count: 1
4045
# This cop supports safe autocorrection (--autocorrect).
4146
# Configuration parameters: EnforcedStyle.

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
source 'https://rubygems.org'
44

5+
gem 'rspec'
56
gem 'rubocop', require: false
7+
gem 'rubocop-rspec', require: false
8+
9+
gemspec

spec/lib/glug/stylesheet_spec.rb

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# frozen_string_literal: true
2+
3+
describe Glug::Stylesheet do
4+
it 'processes a basic stylesheet' do
5+
json = described_class.new do
6+
version 8
7+
center [0.5, 53]
8+
end.to_json
9+
expect(json).to eql('{"version":8,"center":[0.5,53],"sources":{},"layers":[]}')
10+
end
11+
12+
it 'processes the example stylesheet' do
13+
json = described_class.new do
14+
version 8
15+
name 'My first stylesheet'
16+
source :shortbread, type: 'vector', url: 'https://vector.openstreetmap.org/shortbread_v1/tilejson.json'
17+
18+
layer(:roads, zoom: 10..13, source: :shortbread) do
19+
line_width 6
20+
line_color match(highway,
21+
'motorway', :blue,
22+
'trunk', :green,
23+
'primary', :red,
24+
'secondary', :orange,
25+
0x888888)
26+
end
27+
end.to_json
28+
expect(json).to eq(<<~DOC
29+
{
30+
"version":8,
31+
"name":"My first stylesheet",
32+
"sources":{
33+
"shortbread":{
34+
"type":"vector",
35+
"url":"https://vector.openstreetmap.org/shortbread_v1/tilejson.json"
36+
}
37+
},
38+
"layers":[
39+
{
40+
"paint":{
41+
"line-width":6,
42+
"line-color":[
43+
"match",
44+
["get","highway"],
45+
"motorway",
46+
"blue",
47+
"trunk",
48+
"green",
49+
"primary",
50+
"red",
51+
"secondary",
52+
"orange",
53+
8947848
54+
]
55+
},
56+
"source":"shortbread",
57+
"id":"roads",
58+
"source-layer":"roads",
59+
"type":"line",
60+
"minzoom":10,
61+
"maxzoom":13
62+
}
63+
]
64+
}
65+
DOC
66+
.strip)
67+
end
68+
end

spec/spec_helper.rb

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# frozen_string_literal: true
2+
3+
# This file was generated by the `rspec --init` command. Conventionally, all
4+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5+
# The generated `.rspec` file contains `--require spec_helper` which will cause
6+
# this file to always be loaded, without a need to explicitly require it in any
7+
# files.
8+
#
9+
# Given that it is always loaded, you are encouraged to keep this file as
10+
# light-weight as possible. Requiring heavyweight dependencies from this file
11+
# will add to the boot time of your test suite on EVERY test run, even for an
12+
# individual file that may not need all of that loaded. Instead, consider making
13+
# a separate helper file that requires the additional dependencies and performs
14+
# the additional setup, and require it from the spec files that actually need
15+
# it.
16+
#
17+
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18+
19+
require 'glug'
20+
21+
RSpec.configure do |config|
22+
# rspec-expectations config goes here. You can use an alternate
23+
# assertion/expectation library such as wrong or the stdlib/minitest
24+
# assertions if you prefer.
25+
config.expect_with :rspec do |expectations|
26+
# This option will default to `true` in RSpec 4. It makes the `description`
27+
# and `failure_message` of custom matchers include text for helper methods
28+
# defined using `chain`, e.g.:
29+
# be_bigger_than(2).and_smaller_than(4).description
30+
# # => "be bigger than 2 and smaller than 4"
31+
# ...rather than:
32+
# # => "be bigger than 2"
33+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34+
end
35+
36+
# rspec-mocks config goes here. You can use an alternate test double
37+
# library (such as bogus or mocha) by changing the `mock_with` option here.
38+
config.mock_with :rspec do |mocks|
39+
# Prevents you from mocking or stubbing a method that does not exist on
40+
# a real object. This is generally recommended, and will default to
41+
# `true` in RSpec 4.
42+
mocks.verify_partial_doubles = true
43+
end
44+
45+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
46+
# have no way to turn it off -- the option exists only for backwards
47+
# compatibility in RSpec 3). It causes shared context metadata to be
48+
# inherited by the metadata hash of host groups and examples, rather than
49+
# triggering implicit auto-inclusion in groups with matching metadata.
50+
config.shared_context_metadata_behavior = :apply_to_host_groups
51+
52+
# The settings below are suggested to provide a good initial experience
53+
# with RSpec, but feel free to customize to your heart's content.
54+
# # This allows you to limit a spec run to individual examples or groups
55+
# # you care about by tagging them with `:focus` metadata. When nothing
56+
# # is tagged with `:focus`, all examples get run. RSpec also provides
57+
# # aliases for `it`, `describe`, and `context` that include `:focus`
58+
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
59+
# config.filter_run_when_matching :focus
60+
#
61+
# # Allows RSpec to persist some state between runs in order to support
62+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
63+
# # you configure your source control system to ignore this file.
64+
# config.example_status_persistence_file_path = "spec/examples.txt"
65+
#
66+
# # Limits the available syntax to the non-monkey patched syntax that is
67+
# # recommended. For more details, see:
68+
# # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
69+
# config.disable_monkey_patching!
70+
#
71+
# # This setting enables warnings. It's recommended, but in some cases may
72+
# # be too noisy due to issues in dependencies.
73+
# config.warnings = true
74+
#
75+
# # Many RSpec users commonly either run the entire suite or an individual
76+
# # file, and it's useful to allow more verbose output when running an
77+
# # individual spec file.
78+
# if config.files_to_run.one?
79+
# # Use the documentation formatter for detailed output,
80+
# # unless a formatter has already been configured
81+
# # (e.g. via a command-line flag).
82+
# config.default_formatter = "doc"
83+
# end
84+
#
85+
# # Print the 10 slowest examples and example groups at the
86+
# # end of the spec run, to help surface which specs are running
87+
# # particularly slow.
88+
# config.profile_examples = 10
89+
#
90+
# # Run specs in random order to surface order dependencies. If you find an
91+
# # order dependency and want to debug it, you can fix the order by providing
92+
# # the seed, which is printed after each run.
93+
# # --seed 1234
94+
# config.order = :random
95+
#
96+
# # Seed global randomization in this process using the `--seed` CLI option.
97+
# # Setting this allows you to use `--seed` to deterministically reproduce
98+
# # test failures related to randomization by passing the same `--seed` value
99+
# # as the one that triggered the failure.
100+
# Kernel.srand config.seed
101+
end

0 commit comments

Comments
 (0)