Skip to content

Commit

Permalink
Issue #105 Migrate from Minitest to RSpec (#106)
Browse files Browse the repository at this point in the history
* Create .rspec

* Update .rubocop.yml

* Update .travis.yml

* Update hanami-helpers.gemspec

* Update Rakefile

* Create escape_helper_spec.rb

* Create escape_helper_spec.rb

* Create escape_helper_spec.rb

* Delete escape_helper_spec.rb

* Create fixtures.rb

* Create version_spec.rb

* Update escape_helper_spec.rb

* Create html_helper_spec.rb

* create form_helper_spec in progress

* Create link_to_helper_spec.rb

* Create routing_helper_spec.rb

* Create number_formatting_helper_spec.rb

* Update escape_helper_spec.rb

* Create html_helper_spec

* Create number_formatter_helper_spec

* Create routing_helper_spec

* Rename number_formatter_helper_spec to number_formatter_helper_spec.rb

* Rename html_helper_spec to html_helper_spec.rb

* Rename routing_helper_spec to routing_helper_spec.rb

* Create form_helper_spec.rb

* Create link_to_helper_spec.rb

* Update .travis.yml

* Update fixtures.rb

* Create new.html.erb

* Add files via upload

* Create spec_helper.rb

* Create html_builder_spec.rb

* Update html_helper_spec.rb

* Update escape_helper_spec.rb

* Update form_helper_spec.rb

* Update html_helper_spec.rb

* Update escape_helper_spec.rb

* Update version_spec.rb

* Update

* Update form_helper_spec.rb

* Update html_helper_spec.rb

* Update number_formatting_helper_spec.rb

* clear trailing whitespace

* Update spec_helper.rb

* Update html_helper_spec.rb

* Update hanami-helpers.gemspec

* Update escape_helper_spec.rb

* fix indentation issues

* Update hanami-helpers.gemspec

* Update Rakefile

* Update form_helper_spec.rb

* Update form_helper_spec.rb

* Fix to skip errors about array and indent

* Fix to clear CI issue

This should fix this issue:

test/fixtures.rb:58:5: W: Lint/AmbiguousBlockAssociation: Parenthesize the param html to make sure that the block will be associated with the + method call. (https://github.com/bbatsov/ruby-style-guide#syntax)
    html { div 'Hello' } + html { div 'Hanami' }
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* Update form_helper_spec.rb

* Update fixtures.rb

* Update fixtures.rb

* Update form_helper_spec.rb

* Update fixtures.rb
  • Loading branch information
morrme authored and jodosha committed Apr 11, 2017
1 parent ed852dd commit 3425b08
Show file tree
Hide file tree
Showing 33 changed files with 4,184 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .rspec
@@ -0,0 +1,2 @@
--color
--require spec_helper
5 changes: 5 additions & 0 deletions .rubocop.yml
Expand Up @@ -5,5 +5,10 @@ inherit_from:
Metrics/BlockLength:
Exclude:
- "test/**/*_test.rb" # Minitest syntax generates this false positive
- 'spec/**/*'
Style/MethodMissing:
Enabled: false
Style/IndentHeredoc:
Enabled: false
Style/SymbolArray:
Enabled: false
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -5,7 +5,7 @@ before_install:
- gem update --system
- rvm @global do gem uninstall bundler -a -x
- rvm @global do gem install bundler -v 1.13.7
script: 'bundle exec rake test:coverage --trace && bundle exec rubocop'
script: 'bundle exec rake spec:coverage --trace && bundle exec rubocop'
rvm:
- 2.3.3
- 2.4.0
Expand Down
18 changes: 13 additions & 5 deletions Rakefile
@@ -1,17 +1,25 @@
require 'rake'
require 'rake/testtask'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rake/testtask'

Rake::TestTask.new do |t|
t.pattern = 'test/**/*_test.rb'
t.libs.push 'test'
end

namespace :test do
namespace :spec do
RSpec::Core::RakeTask.new(:unit) do |task|
file_list = FileList['spec/**/*_spec.rb']
file_list = file_list.exclude("spec/{integration,isolation}/**/*_spec.rb")

task.pattern = file_list
end

task :coverage do
ENV['COVERALL'] = 'true'
Rake::Task['test'].invoke
ENV['COVERAGE'] = 'true'
Rake::Task['spec:unit'].invoke
end
end

task default: :test
task default: 'spec:unit'
4 changes: 3 additions & 1 deletion hanami-helpers.gemspec
@@ -1,5 +1,7 @@
# coding: utf-8

lib = File.expand_path('../lib', __FILE__)

$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'hanami/helpers/version'

Expand All @@ -25,6 +27,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'bundler', '~> 1.6'
spec.add_development_dependency 'rake', '~> 11'
spec.add_development_dependency 'minitest', '~> 5.5'

spec.add_development_dependency 'rspec', '~> 3.5'
spec.add_development_dependency 'dry-struct', '~> 0.1'
end
64 changes: 64 additions & 0 deletions spec/hanami/helpers/escape_helper_spec.rb
@@ -0,0 +1,64 @@
RSpec.describe Hanami::Helpers::EscapeHelper do
before do
@view = EscapeView.new
end

it 'has a private escape html method' do
expect { @view.escape_html }.to raise_error(NoMethodError)
end

it 'has a private escape html attribute method' do
expect { @view.escape_html_attribute }.to raise_error(NoMethodError)
end

it 'has a private escape url method' do
expect { @view.escape_url }.to raise_error(NoMethodError)
end

it 'has a private raw method' do
expect { @view.raw }.to raise_error(NoMethodError)
end
it 'autoscape evil string' do
expect(@view.evil_string).to eq(%(<script>alert('xss')</script>))
end

it "don't autoscape safe string" do
expect(@view.good_string).to eq(%(this is a good string))
end

it 'autoscape attributes evil string' do
expect(@view.good_attributes_string).to eq(%(<a title='foo'>link</a>))
end

it "don't autoscape attributes safe string" do
expect(@view.evil_attributes_string).to eq(%(<a title='&lt;script&gt;alert&#x28;&#x27;xss&#x27;&#x29;&lt;&#x2f;script&gt;'>link</a>))
end

it 'autoscape url evil string' do
expect(@view.good_url_string).to eq(%(http://hanamirb.org))
end

it "don't autoscape url evil string" do
expect(@view.evil_url_string).to be_empty
end

it 'raw string is returned' do
expect(@view.raw_string).to eq(%(<div>I'm a raw string</div>))
end

it 'raw string is a Hanami::Helpers::Escape::SafeString class' do
expect(@view.raw_string.class).to eq(Hanami::Utils::Escape::SafeString)
end

it 'html helper alias' do
expect(@view.html_string_alias).to eq(%(this is a good string))
end

it 'html attribute helper alias' do
expect(@view.html_attribute_string_alias).to eq(%(<a title='foo'>link</a>))
end

it 'url helper alias' do
expect(@view.url_string_alias).to eq(%(http://hanamirb.org))
end
end

0 comments on commit 3425b08

Please sign in to comment.