This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):010:0> -1 % 24 | |
=> 23 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> words = "a".split(/\w+|\s/); | |
[ '', '' ] | |
> words = "a".split(/\W+|\s); | |
words = "a".split(/\W+|\s); | |
^ | |
SyntaxError: Invalid regular expression: missing / | |
> words = "a".split(/\W+|\s/); | |
[ 'a' ] | |
> words = "there's a list of words".split(/\w+|\s/); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lam = lambda { puts "hello world" } | |
def method(func) | |
func.call | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "minitest/autorun" | |
module Cipher | |
extend self | |
def call(str) | |
str.gsub(/\s/) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'minitest', '~> 5.4' | |
require 'minitest/autorun' | |
require_relative '../lib/bottles' | |
class BottlesTest < Minitest::Test | |
def test_the_first_verse | |
expected = <<-VERSE | |
99 bottles of beer on the wall, 99 bottles of beer. | |
Take one down and pass it around, 98 bottles of beer on the wall. | |
VERSE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def node(input, *args) | |
if input.is_a?(::Symbol) | |
[type, [name, predicate(input, *args).to_ast]] | |
elsif input.respond_to?(:rule) | |
[type, [name, [:type, input]]] | |
elsif input.is_a?(::Class) && input < ::Dry::Struct | |
[type, [name, [:schema, Schema.create_class(self, input)]]] | |
elsif input.is_a?(Schema) | |
[type, [name, schema(input).to_ast]] | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context "structs" do | |
subject(:schema) do | |
Dry::Validation.Schema do | |
required(:person).filled(Person) | |
end | |
end | |
class Name < Dry::Struct::Value | |
attribute :given_name, 'strict.string' | |
attribute :family_name, 'strict.string' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "spec_helper" | |
RSpec.describe SAML::Consumer do | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Examples of doing test doubles in Go tests | |
// Extracted from https://blog.8thlight.com/uncle-bob/2014/05/14/TheLittleMocker.html | |
type Authorizer interface { | |
Authorize(username, password string) bool | |
} | |
// Dummy: Pass it around when you don't care how it is use | |
type DummyAuthorizer struct {} | |
func (da *DummyAuthorizer) Authorize(username, password string) bool { | |
return false | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestCreateInstanceFromMissingPlaybook(t *testing.T) { | |
nt := newNotificationTestHelper() | |
defer nt.Close() | |
store := store.New() | |
is := NewInstanceService(store) | |
i := &instance.Instance{PlaybookID: "vanishing-pb", ID: "gone"} | |
_, err := is.Create(i) | |
assert.NotNil(t, err) |