geo_pattern 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +30 -0
- data/.gitignore +1 -0
- data/.simplecov +1 -0
- data/Gemfile +17 -19
- data/README.md +35 -12
- data/Rakefile +45 -49
- data/geo_pattern.gemspec +18 -22
- data/lib/geo_pattern/background.rb +9 -7
- data/lib/geo_pattern/background_generators/solid_generator.rb +4 -2
- data/lib/geo_pattern/color.rb +3 -1
- data/lib/geo_pattern/color_generators/base_color_generator.rb +12 -10
- data/lib/geo_pattern/color_generators/simple_generator.rb +2 -0
- data/lib/geo_pattern/color_preset.rb +7 -1
- data/lib/geo_pattern/errors.rb +2 -0
- data/lib/geo_pattern/geo_pattern_task.rb +11 -9
- data/lib/geo_pattern/helpers.rb +7 -5
- data/lib/geo_pattern/pattern.rb +6 -4
- data/lib/geo_pattern/pattern_generator.rb +14 -12
- data/lib/geo_pattern/pattern_helpers.rb +11 -8
- data/lib/geo_pattern/pattern_preset.rb +3 -1
- data/lib/geo_pattern/pattern_sieve.rb +5 -3
- data/lib/geo_pattern/pattern_store.rb +20 -18
- data/lib/geo_pattern/pattern_validator.rb +4 -2
- data/lib/geo_pattern/rake_task.rb +19 -16
- data/lib/geo_pattern/roles/comparable_metadata.rb +2 -0
- data/lib/geo_pattern/roles/named_generator.rb +3 -1
- data/lib/geo_pattern/seed.rb +2 -0
- data/lib/geo_pattern/structure.rb +9 -7
- data/lib/geo_pattern/structure_generators/base_generator.rb +17 -14
- data/lib/geo_pattern/structure_generators/chevrons_generator.rb +19 -17
- data/lib/geo_pattern/structure_generators/concentric_circles_generator.rb +19 -17
- data/lib/geo_pattern/structure_generators/diamonds_generator.rb +23 -17
- data/lib/geo_pattern/structure_generators/hexagons_generator.rb +25 -23
- data/lib/geo_pattern/structure_generators/mosaic_squares_generator.rb +35 -35
- data/lib/geo_pattern/structure_generators/nested_squares_generator.rb +23 -21
- data/lib/geo_pattern/structure_generators/octagons_generator.rb +12 -11
- data/lib/geo_pattern/structure_generators/overlapping_circles_generator.rb +13 -11
- data/lib/geo_pattern/structure_generators/overlapping_rings_generator.rb +15 -13
- data/lib/geo_pattern/structure_generators/plaid_generator.rb +18 -18
- data/lib/geo_pattern/structure_generators/plus_signs_generator.rb +24 -18
- data/lib/geo_pattern/structure_generators/sine_waves_generator.rb +17 -15
- data/lib/geo_pattern/structure_generators/squares_generator.rb +10 -9
- data/lib/geo_pattern/structure_generators/tessellation_generator.rb +36 -34
- data/lib/geo_pattern/structure_generators/triangles_generator.rb +22 -19
- data/lib/geo_pattern/structure_generators/xes_generator.rb +26 -19
- data/lib/geo_pattern/svg_image.rb +10 -8
- data/lib/geo_pattern/version.rb +3 -1
- data/lib/geo_pattern.rb +53 -51
- data/script/console +4 -3
- data/spec/background_generators/solid_generator_spec.rb +16 -14
- data/spec/background_spec.rb +13 -11
- data/spec/color_generators/base_color_generator_spec.rb +10 -8
- data/spec/color_generators/simple_generator_spec.rb +5 -3
- data/spec/color_preset_spec.rb +17 -15
- data/spec/color_spec.rb +8 -6
- data/spec/geo_pattern_spec.rb +59 -58
- data/spec/helpers_spec.rb +30 -28
- data/spec/pattern_preset_spec.rb +15 -13
- data/spec/pattern_sieve_spec.rb +13 -11
- data/spec/pattern_spec.rb +20 -18
- data/spec/pattern_store_spec.rb +21 -19
- data/spec/pattern_validator_spec.rb +11 -9
- data/spec/seed_spec.rb +6 -4
- data/spec/spec_helper.rb +9 -8
- data/spec/structure_generators/chevrons_generator_spec.rb +4 -2
- data/spec/structure_generators/concentric_circles_generator_spec.rb +4 -2
- data/spec/structure_generators/diamonds_generator_spec.rb +4 -2
- data/spec/structure_generators/hexagons_generator_spec.rb +4 -2
- data/spec/structure_generators/mosaic_squares_generator_spec.rb +4 -2
- data/spec/structure_generators/nested_squares_generator_spec.rb +4 -2
- data/spec/structure_generators/octagons_generator_spec.rb +4 -2
- data/spec/structure_generators/overlapping_circles_generator_spec.rb +4 -2
- data/spec/structure_generators/overlapping_rings_generator_spec.rb +4 -2
- data/spec/structure_generators/plaid_generator_spec.rb +4 -2
- data/spec/structure_generators/plus_signs_generator_spec.rb +4 -2
- data/spec/structure_generators/sine_waves_generator_spec.rb +4 -2
- data/spec/structure_generators/squares_generator_spec.rb +4 -2
- data/spec/structure_generators/tessellation_generator_spec.rb +4 -2
- data/spec/structure_generators/triangles_generator_spec.rb +4 -2
- data/spec/structure_generators/xes_generator_spec.rb +4 -2
- data/spec/structure_spec.rb +18 -16
- data/spec/support/aruba.rb +6 -6
- data/spec/support/helpers/fixtures.rb +3 -1
- data/spec/support/kernel.rb +8 -2
- data/spec/support/matchers/image.rb +4 -2
- data/spec/support/matchers/name.rb +3 -1
- data/spec/support/rspec.rb +4 -2
- data/spec/support/shared_examples/generator.rb +12 -10
- data/spec/support/shared_examples/pattern.rb +7 -5
- data/spec/support/shared_examples/pattern_name.rb +4 -2
- data/spec/support/shared_examples/structure.rb +12 -10
- data/spec/support/string.rb +3 -2
- data/spec/svg_spec.rb +5 -3
- metadata +11 -59
- data/.rubocop.yml +0 -71
- data/.travis.yml +0 -12
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe ColorGenerators::SimpleGenerator do
|
2
4
|
subject(:generator) { described_class.new(color_string) }
|
3
5
|
|
4
|
-
let(:color_string) {
|
6
|
+
let(:color_string) { "#ff00ff" }
|
5
7
|
|
6
8
|
it { is_expected.not_to be_nil }
|
7
9
|
|
8
|
-
describe
|
10
|
+
describe "#generate" do
|
9
11
|
let(:color) { generator.generate }
|
10
|
-
it { expect(color.to_svg).to eq
|
12
|
+
it { expect(color.to_svg).to eq "rgb(255, 0, 255)" }
|
11
13
|
end
|
12
14
|
end
|
data/spec/color_preset_spec.rb
CHANGED
@@ -1,37 +1,39 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
RSpec.describe ColorPreset do
|
4
6
|
subject(:preset) { ColorPreset.new(**options) }
|
5
7
|
let(:options) do
|
6
8
|
{
|
7
|
-
base_color:
|
9
|
+
base_color: "#0f0f0f"
|
8
10
|
}
|
9
11
|
end
|
10
12
|
|
11
13
|
it { expect(preset).not_to be nil }
|
12
14
|
|
13
|
-
describe
|
14
|
-
it { expect(preset.base_color).to eq
|
15
|
+
describe "#base_color" do
|
16
|
+
it { expect(preset.base_color).to eq "#0f0f0f" }
|
15
17
|
end
|
16
18
|
|
17
|
-
describe
|
18
|
-
context
|
19
|
+
describe "#color" do
|
20
|
+
context "when set" do
|
19
21
|
let(:options) do
|
20
22
|
{
|
21
|
-
base_color:
|
22
|
-
color:
|
23
|
+
base_color: "#0f0f0f",
|
24
|
+
color: "#1f1f1f"
|
23
25
|
}
|
24
26
|
end
|
25
27
|
|
26
|
-
it { expect(preset.color).to eq
|
28
|
+
it { expect(preset.color).to eq "#1f1f1f" }
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
describe
|
31
|
-
context
|
32
|
+
describe "#mode?" do
|
33
|
+
context "when nil" do
|
32
34
|
let(:options) do
|
33
35
|
{
|
34
|
-
base_color:
|
36
|
+
base_color: "#0f0f0f",
|
35
37
|
color: nil
|
36
38
|
}
|
37
39
|
end
|
@@ -39,11 +41,11 @@ RSpec.describe ColorPreset do
|
|
39
41
|
it { expect(preset).to be_mode :base_color }
|
40
42
|
end
|
41
43
|
|
42
|
-
context
|
44
|
+
context "when defined" do
|
43
45
|
let(:options) do
|
44
46
|
{
|
45
|
-
base_color:
|
46
|
-
color:
|
47
|
+
base_color: "#0f0f0f",
|
48
|
+
color: "#1f1f1f"
|
47
49
|
}
|
48
50
|
end
|
49
51
|
|
data/spec/color_spec.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
RSpec.describe GeoPattern::Color do
|
4
6
|
subject(:color) { described_class.new(color_string) }
|
5
|
-
let(:color_string) {
|
6
|
-
let(:seed) { instance_double(
|
7
|
+
let(:color_string) { "#ff00ff" }
|
8
|
+
let(:seed) { instance_double("GeoPattern::Seed") }
|
7
9
|
|
8
|
-
describe
|
9
|
-
it { expect(color.to_svg).to eq
|
10
|
+
describe "#to_svg" do
|
11
|
+
it { expect(color.to_svg).to eq "rgb(255, 0, 255)" }
|
10
12
|
end
|
11
13
|
|
12
|
-
describe
|
14
|
+
describe "#to_html" do
|
13
15
|
it { expect(color.to_html).to eq color_string }
|
14
16
|
end
|
15
17
|
end
|
data/spec/geo_pattern_spec.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
3
4
|
|
4
5
|
RSpec.describe GeoPattern do
|
5
6
|
subject(:pattern) { GeoPattern.generate(input) }
|
6
|
-
let(:input) {
|
7
|
-
let(:color) {
|
7
|
+
let(:input) { "Mastering Markdown" }
|
8
|
+
let(:color) { "#ffcc00" }
|
8
9
|
let(:rgb_base_color) { PatternHelpers.html_to_rgb_for_string(seed, color) }
|
9
|
-
let(:seed) { instance_double(
|
10
|
+
let(:seed) { instance_double("GeoPattern::Seed") }
|
10
11
|
|
11
12
|
before :each do
|
12
13
|
allow(seed).to receive(:to_i).with(14, 3).and_return(2616)
|
@@ -15,42 +16,42 @@ RSpec.describe GeoPattern do
|
|
15
16
|
|
16
17
|
it { expect(pattern).not_to be_nil }
|
17
18
|
|
18
|
-
describe
|
19
|
-
context
|
19
|
+
describe ".generate" do
|
20
|
+
context "when invoked with the same input it returns the same output" do
|
20
21
|
let(:other_pattern) { GeoPattern.generate(input) }
|
21
22
|
it { expect(pattern.to_svg).to eq other_pattern.to_svg }
|
22
23
|
end
|
23
24
|
|
24
|
-
context
|
25
|
+
context "when an invalid option is given" do
|
25
26
|
subject(:pattern) { GeoPattern.generate(input, **args) }
|
26
|
-
let(:args) { {
|
27
|
+
let(:args) { {unknown: true} }
|
27
28
|
|
28
29
|
it { expect { pattern }.to raise_error ArgumentError }
|
29
30
|
end
|
30
31
|
|
31
|
-
context
|
32
|
-
let(:new_color) {
|
32
|
+
context "set background color of generated pattern" do
|
33
|
+
let(:new_color) { "#ffcc00" }
|
33
34
|
|
34
|
-
context
|
35
|
+
context "when a base color is set" do
|
35
36
|
subject(:pattern) { GeoPattern.generate(input, base_color: color) }
|
36
|
-
let(:new_color) {
|
37
|
+
let(:new_color) { "#04fbf6" }
|
37
38
|
|
38
39
|
it { expect(pattern.background.color.to_html).to eq(new_color) }
|
39
40
|
end
|
40
41
|
|
41
|
-
context
|
42
|
+
context "when a color is set" do
|
42
43
|
subject(:pattern) { GeoPattern.generate(input, color: color) }
|
43
44
|
|
44
45
|
it { expect(pattern.background.color.to_html).to eq(new_color) }
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
context
|
49
|
+
context "specify the pattern" do
|
49
50
|
subject(:pattern) { GeoPattern.generate(input, patterns: chosen_pattern) }
|
50
51
|
|
51
52
|
let(:chosen_pattern) { :sine_waves }
|
52
53
|
|
53
|
-
context
|
54
|
+
context "when the deprecated generator option is used" do
|
54
55
|
subject(:pattern) { GeoPattern.generate(input, generator: chosen_pattern) }
|
55
56
|
subject(:other_pattern) { GeoPattern.generate(input, patterns: chosen_pattern) }
|
56
57
|
|
@@ -58,57 +59,57 @@ RSpec.describe GeoPattern do
|
|
58
59
|
it { silence(:stderr) { expect(pattern.to_svg).to eq other_pattern.to_svg } }
|
59
60
|
end
|
60
61
|
|
61
|
-
context
|
62
|
-
let(:chosen_pattern) { [
|
62
|
+
context "when multiple patterns are selected" do
|
63
|
+
let(:chosen_pattern) { %i[sine_waves xes] }
|
63
64
|
|
64
65
|
it { expect(pattern.structure.name).to eq(:sine_waves).or eq(:xes) }
|
65
66
|
end
|
66
67
|
|
67
|
-
context
|
68
|
-
it_behaves_like
|
69
|
-
it_behaves_like
|
70
|
-
it_behaves_like
|
71
|
-
it_behaves_like
|
72
|
-
it_behaves_like
|
73
|
-
it_behaves_like
|
74
|
-
it_behaves_like
|
75
|
-
it_behaves_like
|
76
|
-
it_behaves_like
|
77
|
-
it_behaves_like
|
78
|
-
it_behaves_like
|
79
|
-
it_behaves_like
|
80
|
-
it_behaves_like
|
81
|
-
it_behaves_like
|
82
|
-
it_behaves_like
|
83
|
-
it_behaves_like
|
68
|
+
context "when an old style pattern was chosen via class name" do
|
69
|
+
it_behaves_like "an old style pattern", ChevronPattern, :chevrons
|
70
|
+
it_behaves_like "an old style pattern", ConcentricCirclesPattern, :concentric_circles
|
71
|
+
it_behaves_like "an old style pattern", DiamondPattern, :diamonds
|
72
|
+
it_behaves_like "an old style pattern", HexagonPattern, :hexagons
|
73
|
+
it_behaves_like "an old style pattern", MosaicSquaresPattern, :mosaic_squares
|
74
|
+
it_behaves_like "an old style pattern", NestedSquaresPattern, :nested_squares
|
75
|
+
it_behaves_like "an old style pattern", OctagonPattern, :octagons
|
76
|
+
it_behaves_like "an old style pattern", OverlappingCirclesPattern, :overlapping_circles
|
77
|
+
it_behaves_like "an old style pattern", OverlappingRingsPattern, :overlapping_rings
|
78
|
+
it_behaves_like "an old style pattern", PlaidPattern, :plaid
|
79
|
+
it_behaves_like "an old style pattern", PlusSignPattern, :plus_signs
|
80
|
+
it_behaves_like "an old style pattern", SineWavePattern, :sine_waves
|
81
|
+
it_behaves_like "an old style pattern", SquarePattern, :squares
|
82
|
+
it_behaves_like "an old style pattern", TessellationPattern, :tessellation
|
83
|
+
it_behaves_like "an old style pattern", TrianglePattern, :triangles
|
84
|
+
it_behaves_like "an old style pattern", XesPattern, :xes
|
84
85
|
end
|
85
86
|
|
86
|
-
context
|
87
|
-
it_behaves_like
|
88
|
-
it_behaves_like
|
89
|
-
it_behaves_like
|
90
|
-
it_behaves_like
|
91
|
-
it_behaves_like
|
92
|
-
it_behaves_like
|
93
|
-
it_behaves_like
|
94
|
-
it_behaves_like
|
95
|
-
it_behaves_like
|
96
|
-
it_behaves_like
|
97
|
-
it_behaves_like
|
98
|
-
it_behaves_like
|
99
|
-
it_behaves_like
|
100
|
-
it_behaves_like
|
101
|
-
it_behaves_like
|
102
|
-
it_behaves_like
|
87
|
+
context "when an valid pattern was chosen" do
|
88
|
+
it_behaves_like "a chosen pattern", :chevrons
|
89
|
+
it_behaves_like "a chosen pattern", :concentric_circles
|
90
|
+
it_behaves_like "a chosen pattern", :diamonds
|
91
|
+
it_behaves_like "a chosen pattern", :hexagons
|
92
|
+
it_behaves_like "a chosen pattern", :mosaic_squares
|
93
|
+
it_behaves_like "a chosen pattern", :nested_squares
|
94
|
+
it_behaves_like "a chosen pattern", :octagons
|
95
|
+
it_behaves_like "a chosen pattern", :overlapping_circles
|
96
|
+
it_behaves_like "a chosen pattern", :overlapping_rings
|
97
|
+
it_behaves_like "a chosen pattern", :plaid
|
98
|
+
it_behaves_like "a chosen pattern", :plus_signs
|
99
|
+
it_behaves_like "a chosen pattern", :sine_waves
|
100
|
+
it_behaves_like "a chosen pattern", :squares
|
101
|
+
it_behaves_like "a chosen pattern", :tessellation
|
102
|
+
it_behaves_like "a chosen pattern", :triangles
|
103
|
+
it_behaves_like "a chosen pattern", :xes
|
103
104
|
end
|
104
105
|
|
105
|
-
context
|
106
|
-
InvalidPatternClass = Class.new
|
106
|
+
context "when invalid patterns were chosen" do
|
107
|
+
InvalidPatternClass = Class.new # rubocop:disable Lint/ConstantDefinitionInBlock
|
107
108
|
|
108
|
-
it_behaves_like
|
109
|
-
it_behaves_like
|
110
|
-
it_behaves_like
|
111
|
-
it_behaves_like
|
109
|
+
it_behaves_like "an invalid pattern", InvalidPatternClass
|
110
|
+
it_behaves_like "an invalid pattern", "invalid_pattern"
|
111
|
+
it_behaves_like "an invalid pattern", :invalid_pattern
|
112
|
+
it_behaves_like "an invalid pattern", [:sine_waves, "invalid_pattern"]
|
112
113
|
end
|
113
114
|
end
|
114
115
|
end
|
data/spec/helpers_spec.rb
CHANGED
@@ -1,64 +1,66 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
RSpec.describe Helpers do
|
4
|
-
describe
|
6
|
+
describe ".underscore" do
|
5
7
|
subject { described_class.underscore string }
|
6
8
|
|
7
|
-
context
|
8
|
-
let(:string) {
|
9
|
+
context "when string is empty" do
|
10
|
+
let(:string) { "" }
|
9
11
|
|
10
|
-
it { is_expected.to eq
|
12
|
+
it { is_expected.to eq "" }
|
11
13
|
end
|
12
14
|
|
13
|
-
context
|
14
|
-
let(:string) {
|
15
|
+
context "when string is in snakecase" do
|
16
|
+
let(:string) { "HelloWorld" }
|
15
17
|
|
16
|
-
it { is_expected.to eq
|
18
|
+
it { is_expected.to eq "hello_world" }
|
17
19
|
end
|
18
20
|
|
19
|
-
context
|
20
|
-
let(:string) {
|
21
|
+
context "when string is in snakecase at some places" do
|
22
|
+
let(:string) { "helloWorld" }
|
21
23
|
|
22
|
-
it { is_expected.to eq
|
24
|
+
it { is_expected.to eq "hello_world" }
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
describe
|
28
|
+
describe ".demodulize" do
|
27
29
|
subject { described_class.demodulize string }
|
28
30
|
|
29
|
-
context
|
31
|
+
context "when constant" do
|
30
32
|
before :each do
|
31
|
-
stub_const(
|
33
|
+
stub_const("HelloWorld", Class.new)
|
32
34
|
end
|
33
35
|
|
34
36
|
let(:string) { HelloWorld }
|
35
37
|
|
36
|
-
it { is_expected.to eq
|
38
|
+
it { is_expected.to eq "HelloWorld" }
|
37
39
|
end
|
38
40
|
|
39
|
-
context
|
40
|
-
context
|
41
|
-
let(:string) {
|
41
|
+
context "when string" do
|
42
|
+
context "is empty" do
|
43
|
+
let(:string) { "" }
|
42
44
|
|
43
|
-
it { is_expected.to eq
|
45
|
+
it { is_expected.to eq "" }
|
44
46
|
end
|
45
47
|
|
46
|
-
context
|
47
|
-
let(:string) {
|
48
|
+
context "starts with ::" do
|
49
|
+
let(:string) { "::Class" }
|
48
50
|
|
49
|
-
it { is_expected.to eq
|
51
|
+
it { is_expected.to eq "Class" }
|
50
52
|
end
|
51
53
|
|
52
|
-
context
|
53
|
-
let(:string) {
|
54
|
+
context "has :: in betweend" do
|
55
|
+
let(:string) { "HelloWorld::Class" }
|
54
56
|
|
55
|
-
it { is_expected.to eq
|
57
|
+
it { is_expected.to eq "Class" }
|
56
58
|
end
|
57
59
|
|
58
|
-
context
|
59
|
-
let(:string) {
|
60
|
+
context "when no namespaces is given" do
|
61
|
+
let(:string) { "HelloWorld" }
|
60
62
|
|
61
|
-
it { is_expected.to eq
|
63
|
+
it { is_expected.to eq "HelloWorld" }
|
62
64
|
end
|
63
65
|
end
|
64
66
|
end
|
data/spec/pattern_preset_spec.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
RSpec.describe PatternPreset do
|
4
6
|
subject(:preset) { PatternPreset.new(options) }
|
5
7
|
let(:options) do
|
6
8
|
{
|
7
|
-
fill_color_dark:
|
8
|
-
fill_color_light:
|
9
|
-
stroke_color:
|
9
|
+
fill_color_dark: "#222",
|
10
|
+
fill_color_light: "#ddd",
|
11
|
+
stroke_color: "#000",
|
10
12
|
stroke_opacity: 0.02,
|
11
13
|
opacity_min: 0.02,
|
12
14
|
opacity_max: 0.15
|
@@ -15,27 +17,27 @@ RSpec.describe PatternPreset do
|
|
15
17
|
|
16
18
|
it { expect(preset).not_to be nil }
|
17
19
|
|
18
|
-
describe
|
19
|
-
it { expect(preset.fill_color_dark).to eq
|
20
|
+
describe "#fill_color_dark" do
|
21
|
+
it { expect(preset.fill_color_dark).to eq "#222" }
|
20
22
|
end
|
21
23
|
|
22
|
-
describe
|
23
|
-
it { expect(preset.fill_color_light).to eq
|
24
|
+
describe "#fill_color_light" do
|
25
|
+
it { expect(preset.fill_color_light).to eq "#ddd" }
|
24
26
|
end
|
25
27
|
|
26
|
-
describe
|
27
|
-
it { expect(preset.stroke_color).to eq
|
28
|
+
describe "#stroke_color" do
|
29
|
+
it { expect(preset.stroke_color).to eq "#000" }
|
28
30
|
end
|
29
31
|
|
30
|
-
describe
|
32
|
+
describe "#stroke_opacity" do
|
31
33
|
it { expect(preset.stroke_opacity).to eq 0.02 }
|
32
34
|
end
|
33
35
|
|
34
|
-
describe
|
36
|
+
describe "#opacity_min" do
|
35
37
|
it { expect(preset.opacity_min).to eq 0.02 }
|
36
38
|
end
|
37
39
|
|
38
|
-
describe
|
40
|
+
describe "#opacity_max" do
|
39
41
|
it { expect(preset.opacity_max).to eq 0.15 }
|
40
42
|
end
|
41
43
|
end
|
data/spec/pattern_sieve_spec.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
RSpec.describe PatternSieve do
|
4
6
|
subject(:sieve) { PatternSieve.new(requested_patterns, seed, store) }
|
5
7
|
|
6
8
|
before :each do
|
7
|
-
stub_const(
|
8
|
-
stub_const(
|
9
|
+
stub_const("Pattern1", Class.new)
|
10
|
+
stub_const("Pattern2", Class.new)
|
9
11
|
end
|
10
12
|
|
11
|
-
let(:store) { instance_double(
|
13
|
+
let(:store) { instance_double("GeoPattern::PatternStore") }
|
12
14
|
let(:available_patterns) { [Pattern1, Pattern2] }
|
13
|
-
let(:requested_patterns) { [
|
14
|
-
let(:seed) { instance_double(
|
15
|
+
let(:requested_patterns) { %i[pattern1 pattern2] }
|
16
|
+
let(:seed) { instance_double("GeoPattern::Seed") }
|
15
17
|
|
16
18
|
before :each do
|
17
19
|
allow(seed).to receive(:to_i).with(20, 1).and_return(1)
|
@@ -21,8 +23,8 @@ RSpec.describe PatternSieve do
|
|
21
23
|
# Minimum valid object test
|
22
24
|
it { expect(sieve).not_to be_nil }
|
23
25
|
|
24
|
-
describe
|
25
|
-
context
|
26
|
+
describe "#fetch" do
|
27
|
+
context "when requested_patterns is empty" do
|
26
28
|
let(:requested_patterns) { nil }
|
27
29
|
|
28
30
|
before :each do
|
@@ -33,7 +35,7 @@ RSpec.describe PatternSieve do
|
|
33
35
|
it { expect(sieve.fetch).to eq Pattern2 }
|
34
36
|
end
|
35
37
|
|
36
|
-
context
|
38
|
+
context "when a valid pattern is requested" do
|
37
39
|
let(:requested_patterns) { [:pattern1] }
|
38
40
|
|
39
41
|
before :each do
|
@@ -43,7 +45,7 @@ RSpec.describe PatternSieve do
|
|
43
45
|
it { expect(sieve.fetch).to eq Pattern1 }
|
44
46
|
end
|
45
47
|
|
46
|
-
context
|
48
|
+
context "when an invalid pattern is requested" do
|
47
49
|
let(:requested_patterns) { [:patternX] }
|
48
50
|
|
49
51
|
before :each do
|
@@ -53,7 +55,7 @@ RSpec.describe PatternSieve do
|
|
53
55
|
it { expect(sieve.fetch).to be nil }
|
54
56
|
end
|
55
57
|
|
56
|
-
context
|
58
|
+
context "when a requested pattern is nil" do
|
57
59
|
let(:requested_patterns) { [:pattern1, nil, :pattern2] }
|
58
60
|
|
59
61
|
before :each do
|
data/spec/pattern_spec.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
RSpec.describe Pattern do
|
4
6
|
subject(:pattern) { Pattern.new(svg_image) }
|
5
7
|
|
6
|
-
let(:svg_image) { instance_double(
|
7
|
-
let(:svg_image_content) { fixtures_path(
|
8
|
-
let(:background) { instance_double(
|
9
|
-
let(:background_image) { instance_double(
|
8
|
+
let(:svg_image) { instance_double("GeoPattern::SvgImage") }
|
9
|
+
let(:svg_image_content) { fixtures_path("generated_patterns/sine_waves.svg").read.chomp }
|
10
|
+
let(:background) { instance_double("GeoPattern::Background") }
|
11
|
+
let(:background_image) { instance_double("GeoPattern::SvgImage") }
|
10
12
|
let(:background_body) { %(<rect x="0" y="0" width="100%" height="100%" fill="rgb(121, 131, 76)" />) }
|
11
|
-
let(:structure) { instance_double(
|
12
|
-
let(:structure_image) { instance_double(
|
13
|
-
let(:structure_body) { %(<path d
|
13
|
+
let(:structure) { instance_double("GeoPattern::Structure") }
|
14
|
+
let(:structure_image) { instance_double("GeoPattern::SvgImage") }
|
15
|
+
let(:structure_body) { %(<path d="M0 53 C 28.0 0, 52.0 0, 80 53 S 132.0 106, 160 53 S 212.0 0, 240.0, 53" fill="none" stroke="#222" style="opacity:0.046;stroke-width:6px;" transform="translate(-40, -79.5)" />) }
|
14
16
|
|
15
17
|
it { expect(pattern).not_to be_nil }
|
16
18
|
|
@@ -24,7 +26,7 @@ RSpec.describe Pattern do
|
|
24
26
|
allow(structure).to receive(:image).and_return structure_image
|
25
27
|
end
|
26
28
|
|
27
|
-
describe
|
29
|
+
describe "#to_s" do
|
28
30
|
before :each do
|
29
31
|
allow(svg_image).to receive(:to_s).and_return(svg_image_content)
|
30
32
|
end
|
@@ -32,25 +34,25 @@ RSpec.describe Pattern do
|
|
32
34
|
it { expect(pattern.to_s).to eq svg_image_content }
|
33
35
|
end
|
34
36
|
|
35
|
-
describe
|
37
|
+
describe "#to_base64" do
|
36
38
|
before :each do
|
37
39
|
allow(svg_image).to receive(:to_s).and_return(svg_image_content)
|
38
40
|
end
|
39
41
|
|
40
|
-
it { expect(pattern.to_base64).to include
|
42
|
+
it { expect(pattern.to_base64).to include "PHN2ZyB4bWxuc" }
|
41
43
|
end
|
42
44
|
|
43
|
-
describe
|
45
|
+
describe "#to_data_uri" do
|
44
46
|
before :each do
|
45
47
|
allow(svg_image).to receive(:to_s).and_return(svg_image_content)
|
46
48
|
end
|
47
49
|
|
48
|
-
it { expect(pattern.to_data_uri).to include
|
50
|
+
it { expect(pattern.to_data_uri).to include "PHN2ZyB4bWxuc" }
|
49
51
|
end
|
50
52
|
|
51
|
-
describe
|
52
|
-
context
|
53
|
-
let(:generator) { instance_double(
|
53
|
+
describe "#generate_me" do
|
54
|
+
context "when a background is added" do
|
55
|
+
let(:generator) { instance_double("GeoPattern::BackgroundGenerator") }
|
54
56
|
|
55
57
|
before :each do
|
56
58
|
expect(generator).to receive(:generate).with(pattern)
|
@@ -62,11 +64,11 @@ RSpec.describe Pattern do
|
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
65
|
-
describe
|
67
|
+
describe "#include?" do
|
66
68
|
it do
|
67
69
|
expect(svg_image).to receive(:include?)
|
68
70
|
|
69
|
-
pattern.include?
|
71
|
+
pattern.include? ""
|
70
72
|
end
|
71
73
|
end
|
72
74
|
end
|
data/spec/pattern_store_spec.rb
CHANGED
@@ -1,46 +1,48 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
RSpec.describe PatternStore do
|
4
6
|
subject(:pattern_store) { PatternStore.new }
|
5
7
|
|
6
8
|
it { expect(pattern_store).not_to be_nil }
|
7
9
|
|
8
|
-
describe
|
9
|
-
context
|
10
|
-
context
|
11
|
-
let(:pattern_name) {
|
12
|
-
it_behaves_like
|
10
|
+
describe "#[]" do
|
11
|
+
context "when a known pattern is requested" do
|
12
|
+
context "as string" do
|
13
|
+
let(:pattern_name) { "xes" }
|
14
|
+
it_behaves_like "a known pattern name"
|
13
15
|
end
|
14
16
|
|
15
|
-
context
|
17
|
+
context "as klass" do
|
16
18
|
let(:pattern_name) { XesPattern }
|
17
|
-
it_behaves_like
|
19
|
+
it_behaves_like "a known pattern name"
|
18
20
|
end
|
19
21
|
|
20
|
-
context
|
22
|
+
context "as symbol" do
|
21
23
|
let(:pattern_name) { :xes }
|
22
|
-
it_behaves_like
|
24
|
+
it_behaves_like "a known pattern name"
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
context
|
27
|
-
context
|
28
|
-
let(:pattern_name) {
|
29
|
-
it_behaves_like
|
28
|
+
context "when an unknown pattern is requested" do
|
29
|
+
context "as string" do
|
30
|
+
let(:pattern_name) { "unknown" }
|
31
|
+
it_behaves_like "an unknown pattern name"
|
30
32
|
end
|
31
33
|
|
32
|
-
context
|
34
|
+
context "as klass" do
|
33
35
|
let(:pattern_name) do
|
34
|
-
stub_const(
|
36
|
+
stub_const("UnknownPattern", Class.new)
|
35
37
|
UnknownPattern
|
36
38
|
end
|
37
39
|
|
38
|
-
it_behaves_like
|
40
|
+
it_behaves_like "an unknown pattern name"
|
39
41
|
end
|
40
42
|
|
41
|
-
context
|
43
|
+
context "as symbol" do
|
42
44
|
let(:pattern_name) { :unknown }
|
43
|
-
it_behaves_like
|
45
|
+
it_behaves_like "an unknown pattern name"
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|