├── .gitignore ├── .travis.yml ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── bin ├── loc └── standardize ├── grumpy_old_man.gemspec ├── lib ├── grumpy_old_man.rb └── grumpy_old_man │ └── version.rb └── spec └── grumpy_old_man_spec.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rvmrc 3 | _site 4 | _layouts 5 | images 6 | pkg 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - ruby 4 | - jruby 5 | - rbx 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | # Specify your gem's dependencies in auth_token.gemspec 6 | gemspec 7 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | grumpy_old_man (0.1.6) 5 | rspec 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | ast (2.4.2) 11 | coderay (1.1.3) 12 | diff-lcs (1.4.4) 13 | magic_frozen_string_literal (1.2.0) 14 | method_source (1.0.0) 15 | parallel (1.20.1) 16 | parser (3.0.1.1) 17 | ast (~> 2.4.1) 18 | pry (0.14.1) 19 | coderay (~> 1.1) 20 | method_source (~> 1.0) 21 | rainbow (3.0.0) 22 | rake (13.0.3) 23 | regexp_parser (2.1.1) 24 | rexml (3.2.5) 25 | rspec (3.10.0) 26 | rspec-core (~> 3.10.0) 27 | rspec-expectations (~> 3.10.0) 28 | rspec-mocks (~> 3.10.0) 29 | rspec-core (3.10.1) 30 | rspec-support (~> 3.10.0) 31 | rspec-expectations (3.10.1) 32 | diff-lcs (>= 1.2.0, < 2.0) 33 | rspec-support (~> 3.10.0) 34 | rspec-mocks (3.10.2) 35 | diff-lcs (>= 1.2.0, < 2.0) 36 | rspec-support (~> 3.10.0) 37 | rspec-support (3.10.2) 38 | rubocop (1.14.0) 39 | parallel (~> 1.10) 40 | parser (>= 3.0.0.0) 41 | rainbow (>= 2.2.2, < 4.0) 42 | regexp_parser (>= 1.8, < 3.0) 43 | rexml 44 | rubocop-ast (>= 1.5.0, < 2.0) 45 | ruby-progressbar (~> 1.7) 46 | unicode-display_width (>= 1.4.0, < 3.0) 47 | rubocop-ast (1.5.0) 48 | parser (>= 3.0.1.1) 49 | rubocop-performance (1.11.2) 50 | rubocop (>= 1.7.0, < 2.0) 51 | rubocop-ast (>= 0.4.0) 52 | ruby-progressbar (1.11.0) 53 | standard (1.1.1) 54 | rubocop (= 1.14.0) 55 | rubocop-performance (= 1.11.2) 56 | unicode-display_width (2.0.0) 57 | 58 | PLATFORMS 59 | arm64-darwin-20 60 | 61 | DEPENDENCIES 62 | bundler (>= 2.0) 63 | grumpy_old_man! 64 | magic_frozen_string_literal 65 | pry 66 | rake 67 | standard 68 | 69 | BUNDLED WITH 70 | 2.2.15 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Lines of Code](http://img.shields.io/badge/lines_of_code-20-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/) 2 | 3 | # Grumpy Old Man 4 | 5 | ## Adding old school asserts to RSpec 6 | 7 | GrumpyOldMan adds the following methods to RSpec without compromising any of RSpec's other features. 8 | 9 | * `assert` 10 | * `assert_equal` 11 | * `assert_raise` 12 | * `refute` 13 | 14 | > NOTE: If you're using [rspec-rails](https://github.com/rspec/rspec-rails), these methods are delegated to MiniTest and you don't need GrumpyOldMan. 15 | 16 | Testing libraries exist to help you do the following. 17 | 18 | 1. Execute some code 19 | 1. Verify that it produced the expected outcome 20 | 21 | Or more simply... 22 | 23 | ```ruby 24 | assert true 25 | ``` 26 | 27 | Unfortunately RSpec adds a lot of [unnecessary complexity](https://fs.blog/2018/01/complexity-bias/). 28 | *Looking at you __expectations__ and __matchers__.* 29 | 30 | ## Simplicity FTW 31 | 32 | Consider the following example from the RSpec docs. 33 | 34 | ```ruby 35 | expect(order.total).to eq(Money.new(5.55, :USD)) 36 | ``` 37 | 38 | Rewritten with GrumpyOldMan. 39 | ```ruby 40 | assert order.total == Money.new(5.55, :USD) 41 | 42 | # or ... 43 | 44 | assert_equal order.total, Money.new(5.55, :USD) 45 | ``` 46 | 47 | Simple `asserts` encourage test code that resembles your application logic. 48 | 49 | ## Usage 50 | 51 | ```bash 52 | bundle add grumpy_old_man 53 | ``` 54 | 55 | Simply include GrumpyOldMan in your spec/test like so. 56 | 57 | ```ruby 58 | require "grumpy_old_man" 59 | 60 | describe Thing do 61 | include GrumpyOldMan 62 | 63 | it "should be simple" do 64 | assert true 65 | assert_equal true, true 66 | assert_raise(Exception) { raise } 67 | refute false 68 | end 69 | end 70 | ``` 71 | 72 | You may not agree, but I'm sticking with my old fashioned assert. 73 | **Now get off my lawn!** 74 | 75 | *If you like GrupyOldMan, check out [PryTest](https://github.com/hopsoft/pry-test) and discover just how serene testing can be.* 76 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "rake" 4 | require "bundler/gem_tasks" 5 | require "rspec/core/rake_task" 6 | 7 | RSpec::Core::RakeTask.new(:spec) 8 | 9 | task default: :spec 10 | -------------------------------------------------------------------------------- /bin/loc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cloc ./lib 4 | -------------------------------------------------------------------------------- /bin/standardize: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | bundle exec magic_frozen_string_literal 4 | bundle exec standardrb --fix 5 | -------------------------------------------------------------------------------- /grumpy_old_man.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | lib = File.expand_path("../lib", __FILE__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require "grumpy_old_man/version" 6 | 7 | Gem::Specification.new do |gem| 8 | gem.name = "grumpy_old_man" 9 | gem.version = GrumpyOldMan::VERSION 10 | gem.authors = ["Nathan Hopkins"] 11 | gem.email = ["natehop@gmail.com"] 12 | gem.description = "Asserts for RSpec" 13 | gem.summary = "Asserts for RSpec" 14 | gem.homepage = "https://github.com/hopsoft/grumpy_old_man" 15 | gem.license = "MIT" 16 | 17 | gem.files = Dir["lib/**/*.rb", "bin/*", "[A-Z].*"] 18 | gem.test_files = Dir["spec/**/*.rb"] 19 | gem.require_paths = ["lib"] 20 | 21 | gem.add_dependency "rspec" 22 | 23 | gem.add_development_dependency "bundler", ">= 2.0" 24 | gem.add_development_dependency "magic_frozen_string_literal" 25 | gem.add_development_dependency "pry" 26 | gem.add_development_dependency "rake" 27 | gem.add_development_dependency "standard" 28 | end 29 | -------------------------------------------------------------------------------- /lib/grumpy_old_man.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "grumpy_old_man/version" 4 | 5 | # A mixin for RSpec tests that provides old school assert methods. 6 | module GrumpyOldMan 7 | # A simple assert for RSpec. 8 | # 9 | # @example 10 | # assert true 11 | # 12 | # @example 13 | # assert { true.to_s == "true" } 14 | # 15 | # @param [Object] arg An optional arg to assert as equal to true. 16 | def assert(arg = nil) 17 | arg = yield if block_given? 18 | assert_equal !!arg, true 19 | end 20 | 21 | # A simple refute for RSpec. 22 | # 23 | # @example 24 | # refute false 25 | # 26 | # @example 27 | # refute { false.to_s == "true" } 28 | # 29 | # @param [Object] arg An optional arg to assert as equal to true. 30 | def refute(arg = nil) 31 | arg = yield if block_given? 32 | assert_equal !!arg, false 33 | end 34 | 35 | # A basic assert helper that tests for Object equality. 36 | # Tests for object equivalence rather than object identity since this is sufficient for most tests. 37 | # 38 | # @param [Object] actual The Object to compare. 39 | # @param [Object] expected The expected value. 40 | def assert_equal(actual, expected) 41 | expect(actual).to eql(expected) 42 | end 43 | 44 | # A basic assert helper that ensures an Error was raised. 45 | # @param [Class] ex The expected Exception class. 46 | def assert_raise(ex, &block) 47 | expect(Proc.new(&block)).to raise_error(ex) 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /lib/grumpy_old_man/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GrumpyOldMan 4 | VERSION = "0.1.6" 5 | end 6 | -------------------------------------------------------------------------------- /spec/grumpy_old_man_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require File.expand_path("../../lib/grumpy_old_man", __FILE__) 4 | 5 | describe RSpec do 6 | include GrumpyOldMan 7 | 8 | it "should support assert with GrumpyOldMan" do 9 | assert true 10 | end 11 | 12 | it "should support refute with GrumpyOldMan" do 13 | refute false 14 | end 15 | 16 | it "should support assert_equal with GrumpyOldMan" do 17 | assert_equal true, true 18 | end 19 | 20 | it "should support assert_raise with GrumpyOldMan" do 21 | assert_raise(Exception) { raise } 22 | end 23 | end 24 | --------------------------------------------------------------------------------