navtastic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Navtastic::Renderer do
4
+ describe '.render' do
5
+ subject(:renderer) { described_class.render menu }
6
+
7
+ let(:current_url) { '/' }
8
+ let(:menu) do
9
+ menu = Navtastic::Menu.new
10
+ menu.item "Home", '/'
11
+ menu.current_url = current_url
12
+ menu
13
+ end
14
+
15
+ it "returns an instance of Navtastic::Renderer" do
16
+ expect(renderer).to be_a described_class
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Navtastic do
4
+ subject(:define_menu) do
5
+ described_class.define menu_name do |menu|
6
+ menu.item 'a', '/'
7
+ end
8
+ end
9
+
10
+ let(:menu_name) { "test" }
11
+
12
+ describe '.define' do
13
+ context "when a block was given" do
14
+ it "doesn't raise an error" do
15
+ expect { define_menu }.not_to raise_error
16
+ end
17
+
18
+ it "stores the menu in the store" do
19
+ expect { define_menu }.to(change { described_class.all_menus.count })
20
+ end
21
+
22
+ it "converts a string to a symbol in the store" do
23
+ define_menu
24
+ expect(described_class.all_menus).to include menu_name.to_sym
25
+ end
26
+ end
27
+
28
+ context "when no block was given" do
29
+ subject(:define_menu) { described_class.define :test }
30
+
31
+ it "raises an ArgumentError" do
32
+ expect { define_menu }.to raise_error ArgumentError
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '.render' do
38
+ before { define_menu }
39
+
40
+ subject(:renderer) { described_class.render(menu_name, '/') }
41
+
42
+ context "when the menu was found" do
43
+ specify { expect(renderer).to be_a Navtastic::Renderer }
44
+ end
45
+
46
+ context "when the menu was not found" do
47
+ subject(:renderer) { described_class.render("foo", '/') }
48
+
49
+ specify { expect { renderer }.to raise_error KeyError }
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,113 @@
1
+ if ENV["COVERAGE"]
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ end
5
+
6
+ # This file was generated by the `rspec --init` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
9
+ # this file to always be loaded, without a need to explicitly require it in any
10
+ # files.
11
+ #
12
+ # Given that it is always loaded, you are encouraged to keep this file as
13
+ # light-weight as possible. Requiring heavyweight dependencies from this file
14
+ # will add to the boot time of your test suite on EVERY test run, even for an
15
+ # individual file that may not need all of that loaded. Instead, consider making
16
+ # a separate helper file that requires the additional dependencies and performs
17
+ # the additional setup, and require it from the spec files that actually need
18
+ # it.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+
22
+ require 'bundler/setup'
23
+ Bundler.setup
24
+
25
+ require 'navtastic'
26
+ require 'pp'
27
+
28
+ require 'support/navtastic_store'
29
+
30
+ RSpec.configure do |config|
31
+ # rspec-expectations config goes here. You can use an alternate
32
+ # assertion/expectation library such as wrong or the stdlib/minitest
33
+ # assertions if you prefer.
34
+ config.expect_with :rspec do |expectations|
35
+ # This option will default to `true` in RSpec 4. It makes the `description`
36
+ # and `failure_message` of custom matchers include text for helper methods
37
+ # defined using `chain`, e.g.:
38
+ # be_bigger_than(2).and_smaller_than(4).description
39
+ # # => "be bigger than 2 and smaller than 4"
40
+ # ...rather than:
41
+ # # => "be bigger than 2"
42
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
43
+ end
44
+
45
+ # rspec-mocks config goes here. You can use an alternate test double
46
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
47
+ config.mock_with :rspec do |mocks|
48
+ # Prevents you from mocking or stubbing a method that does not exist on
49
+ # a real object. This is generally recommended, and will default to
50
+ # `true` in RSpec 4.
51
+ mocks.verify_partial_doubles = true
52
+ end
53
+
54
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
55
+ # have no way to turn it off -- the option exists only for backwards
56
+ # compatibility in RSpec 3). It causes shared context metadata to be
57
+ # inherited by the metadata hash of host groups and examples, rather than
58
+ # triggering implicit auto-inclusion in groups with matching metadata.
59
+ config.shared_context_metadata_behavior = :apply_to_host_groups
60
+
61
+ # The settings below are suggested to provide a good initial experience
62
+ # with RSpec, but feel free to customize to your heart's content.
63
+
64
+ # This allows you to limit a spec run to individual examples or groups
65
+ # you care about by tagging them with `:focus` metadata. When nothing
66
+ # is tagged with `:focus`, all examples get run. RSpec also provides
67
+ # aliases for `it`, `describe`, and `context` that include `:focus`
68
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
69
+ config.filter_run_when_matching :focus
70
+
71
+ # Allows RSpec to persist some state between runs in order to support
72
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
73
+ # you configure your source control system to ignore this file.
74
+ config.example_status_persistence_file_path = "spec/examples.txt"
75
+
76
+ # Limits the available syntax to the non-monkey patched syntax that is
77
+ # recommended. For more details, see:
78
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
79
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
80
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
81
+ config.disable_monkey_patching!
82
+
83
+ # This setting enables warnings. It's recommended, but in some cases may
84
+ # be too noisy due to issues in dependencies.
85
+ config.warnings = true
86
+
87
+ # Many RSpec users commonly either run the entire suite or an individual
88
+ # file, and it's useful to allow more verbose output when running an
89
+ # individual spec file.
90
+ if config.files_to_run.one?
91
+ # Use the documentation formatter for detailed output,
92
+ # unless a formatter has already been configured
93
+ # (e.g. via a command-line flag).
94
+ config.default_formatter = "doc"
95
+ end
96
+
97
+ # Print the 10 slowest examples and example groups at the
98
+ # end of the spec run, to help surface which specs are running
99
+ # particularly slow.
100
+ # config.profile_examples = 10
101
+
102
+ # Run specs in random order to surface order dependencies. If you find an
103
+ # order dependency and want to debug it, you can fix the order by providing
104
+ # the seed, which is printed after each run.
105
+ # --seed 1234
106
+ # config.order = :random
107
+
108
+ # Seed global randomization in this process using the `--seed` CLI option.
109
+ # Setting this allows you to use `--seed` to deterministically reproduce
110
+ # test failures related to randomization by passing the same `--seed` value
111
+ # as the one that triggered the failure.
112
+ Kernel.srand config.seed
113
+ end
@@ -0,0 +1,51 @@
1
+ # Check if the menu has a specific current item
2
+ RSpec::Matchers.define :have_current_item do |item = nil|
3
+ match do |menu|
4
+ @current_item = menu.current_item
5
+
6
+ if item.nil?
7
+ !@current_item.nil?
8
+ else
9
+ @current_item == item
10
+ end
11
+ end
12
+
13
+ description do
14
+ "have a current item"
15
+ end
16
+
17
+ failure_message do
18
+ if item.nil?
19
+ <<~EOL
20
+ expected a current item, but no current item was found
21
+ EOL
22
+ else
23
+ <<~EOL
24
+ expected: #{item.url}
25
+ actual: #{actual}
26
+ EOL
27
+ end
28
+ end
29
+
30
+ failure_message_when_negated do
31
+ if item.nil?
32
+ <<~EOL
33
+ expected: no current item
34
+ actual: #{actual}
35
+ EOL
36
+ else
37
+ <<~EOL
38
+ expected: url != #{item.url}
39
+ actual: #{actual}
40
+ EOL
41
+ end
42
+ end
43
+
44
+ def actual
45
+ if @current_item.nil?
46
+ "nil"
47
+ else
48
+ @current_item.url
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,6 @@
1
+ # Remove all stored menus before every test
2
+ RSpec.configure do |config|
3
+ config.before(:each) do
4
+ Navtastic.instance_variable_get(:@menu_store).clear
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: navtastic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aram Visser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: arbre
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: redcarpet
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.48'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.48'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.15'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.15'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
97
+ description:
98
+ email: hello@aramvisser.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files:
102
+ - README.md
103
+ files:
104
+ - ".circleci/config.yml"
105
+ - ".codeclimate.yml"
106
+ - ".gitignore"
107
+ - ".rubocop.yml"
108
+ - ".yardopts"
109
+ - CHANGELOG.md
110
+ - Gemfile
111
+ - LICENSE
112
+ - README.md
113
+ - Rakefile
114
+ - lib/navtastic.rb
115
+ - lib/navtastic/item.rb
116
+ - lib/navtastic/menu.rb
117
+ - lib/navtastic/renderer.rb
118
+ - lib/navtastic/version.rb
119
+ - navtastic.gemspec
120
+ - spec/demo/index.rhtml
121
+ - spec/demo/server.rb
122
+ - spec/navtastic/item_spec.rb
123
+ - spec/navtastic/menu_spec.rb
124
+ - spec/navtastic/renderer_spec.rb
125
+ - spec/navtastic_spec.rb
126
+ - spec/spec_helper.rb
127
+ - spec/support/matchers/current_item.rb
128
+ - spec/support/navtastic_store.rb
129
+ homepage: http://github.com/aramvisser/navtastic
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.6.8
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Define and render complex navigation menus
153
+ test_files:
154
+ - spec/demo/index.rhtml
155
+ - spec/demo/server.rb
156
+ - spec/navtastic/item_spec.rb
157
+ - spec/navtastic/menu_spec.rb
158
+ - spec/navtastic/renderer_spec.rb
159
+ - spec/navtastic_spec.rb
160
+ - spec/spec_helper.rb
161
+ - spec/support/matchers/current_item.rb
162
+ - spec/support/navtastic_store.rb