Skip to content

Instantly share code, notes, and snippets.

@patmaddox
Created August 7, 2014 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patmaddox/5cb31be563890b17e636 to your computer and use it in GitHub Desktop.
Save patmaddox/5cb31be563890b17e636 to your computer and use it in GitHub Desktop.
rubysteps 008 - tdd - approval tests snippet
require 'approvals/rspec'
def output_methods(target, methods)
methods.inject([]) do |results, m|
results << %("#{target}".#{m} => #{target.send(m)})
end
end
describe "Ruby standard library" do
it "has a useful String class" do
string = "fOo"
verify { output_methods(string, [:downcase, :upcase, :size, :empty?]) }
end
it "has a useful Hash class" do
hash = { foo: 'bar' }
verify { output_methods(hash, [:keys, :values, :size]) }
end
it "has a useful Array class" do
array = [1, 2, 4, 3, 'chicken']
verify { output_methods(array, [:first, :last, :size]) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment