Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Jan 6, 2020
1 parent b5c2cd5 commit e8ce323
Show file tree
Hide file tree
Showing 8 changed files with 448 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.4

Expand All @@ -10,6 +14,8 @@ Layout/LineLength:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/CyclomaticComplexity:
Expand All @@ -18,6 +24,10 @@ Metrics/MethodLength:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
RSpec/ExampleLength:
Enabled: false
RSpec/MultipleExpectations:
Enabled: false
Style/AccessModifierDeclarations:
EnforcedStyle: inline
Style/ClassAndModuleChildren:
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
language: ruby
rvm:
- 2.4
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gem 'codecov', '~> 0.1.16'
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.9'
gem 'rubocop', '~> 0.78.0'
gem 'rubocop-rspec', '~> 1.37'
gem 'simplecov', '~> 0.17.1'
gem 'sorbet', '~> 0.5.5200'
gem 'sorbet-runtime', '~> 0.5.5200'
Expand Down
6 changes: 5 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task default: :spec
task :lint do
sh 'rubocop'
end

task default: %i[lint spec]
196 changes: 196 additions & 0 deletions spec/data/sig_handler.rb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
class Signatures
# comment sig_void
sig {void}
def sig_void; end

# comment sig_override_void
sig.override.void
def sig_override_void; end

# comment sig_arguments
sig {params(a: Integer, b: Integer).void}
def sig_arguments(a, b); end

# comment sig_multiline_arguments
sig do
params(
a: Integer,
b: Integer,
).void
end
def sig_multiline_arguments(a, b); end

# comment sig_multiline_comments
# comment sig_multiline_comments
sig {void}
def sig_multiline_comments; end

# comment sig_class_method
sig {void}
def self.sig_class_method; end

class << self
# comment reopening
sig {void}
def reopening; end
end

# At end of class
sig {void}
end

class Subclass < Signatures
# with subclass
sig {void}
def method; end
end

class ClassWithCode
# bar
sig {void}
def bar; end

puts 'foobar'

# foo
sig {void}
def foo; end
end

class Outer
# outer method
sig {void}
def outer; end

class Inner
# inner method
sig {void}
def inner; end
end

# outer method 2
sig {void}
def outer2; end
end

module Module
# module function
sig {void}
def self.foo; end

# module instance method
sig {void}
def bar; end
end

class SigReturn
sig {returns(Integer)}
def one; 1; end

# @deprecated do not use
sig {returns(Integer)}
def two; 2; end

# @return [Numeric]
sig {returns(Integer)}
def three; 3; end

# @return the number four
sig {returns(Integer)}
def four; 4; end

sig {params(int: Integer).returns(Float)}
def plus_one(int); int + 1.0; end

sig {returns(T.any(Numeric, String))}
def plus(a, b); a + b; end

sig {void}
def void_method; end
end

class SigAbstract
sig {abstract}
def one; end

# @abstract subclass must implement
sig {abstract}
def two; end

sig {abstract.returns(Boolean)}
def with_return; true; end

sig {abstract.void}
def with_void; end
end

class SigParams
# @param bar the thing
# @param baz [Object] the other thing
sig {params(bar: T.any(String, Symbol), baz: T.nilable(String)).void}
def foo(bar, baz); end

sig do
params(
blk: T.proc.params(arg0: String).returns(T::Array[Hash])
)
.returns(NilClass)
end
def blk_method(&blk); nil; end

sig do
override
.params(block: T.proc.params(
model: EmailConversation,
mutator: T.untyped,
).void)
.void
end
def impl_blk_method(&block); end
end

class CollectionSigs
sig {params(arr: T::Array[String]).void}
def collection(arr); end

sig {params(arr: T::Array[T::Array[String]]).void}
def nested_collection(arr); end

sig {params(arr: T::Array[T.any(String, Symbol)]).returns(TrueClass)}
def mixed_collection(arr); true; end

sig {returns(T::Hash[String, Symbol])}
def hash_method; end

sig {returns([String, Integer])}
def fixed_array; ['', 0]; end

# @!visibility protected
sig {returns({foo: T.nilable(String)})}
def fixed_hash; {foo: nil}; end

sig do
params(
tos_acceptance: T.nilable({
date: Integer,
ip: String,
user_agent: T.nilable(String),
signator: T.nilable(String),
iovation_blackbox: T.nilable(String),
})
)
.returns(NilClass)
end
def fixed_param_hash(tos_acceptance); nil; end
end

class AttrSigs
sig {returns(String)}
attr_accessor :my_accessor

sig {returns(Integer)}
attr_reader :my_reader

sig {params(my_writer: T.nilable(Symbol)).returns(T.nilable(Symbol))}
attr_writer :my_writer
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require_relative '../lib/yard_sorbet'

if ENV['CI'] == 'true'
require 'simplecov'
require 'codecov'
Expand Down
Loading

0 comments on commit e8ce323

Please sign in to comment.