module NRSER::RSpex::SharedExamples

Just a namespace module where I stuck shared examples, with lil' utils to alias them to multiple string and symbol names if you like.

Constants

EXPECT_SUBJECT

Shared Example Blocks and Binding

FUNCTION

Shared example for a functional method that compares input and output pairs.

Public Class Methods

bind_names(proc, name, prefix: nil) click to toggle source

Bind a proc as an RSpec shared example to string and symbol names

# File lib/nrser/rspex/shared_examples.rb, line 47
def self.bind_names proc, name, prefix: nil
  names = [name.to_s, name_to_sym( name )]
  
  unless prefix.nil?
    names << "#{ prefix } #{ name}"
    names << name_to_sym( "#{ prefix }_#{ name}" )
  end
  
  names.each do |name|
    shared_examples name, &proc
  end
end
name_to_sym(name) click to toggle source

Shitty but simple conversion of natural string names to more symbol-y ones.

@example

name_to_sym 'expect subject'
# => :expect_subject

@example

name_to_sym 'function'
# => :function

Doesn't do anything fancy-pants under the hood.

@param [String | Symbol] name

@return [Symbol]

# File lib/nrser/rspex/shared_examples.rb, line 36
def self.name_to_sym name
  name.
    to_s.
    gsub( /\s+/, '_' ).
    gsub( /[^a-zA-Z0-9_]/, '' ).
    downcase.
    to_sym
end