-
Notifications
You must be signed in to change notification settings - Fork 0
MAM01
Dave Strus edited this page Feb 8, 2016
·
1 revision
- Inheritance
- The splat operator (
*
) method_missing
- More unit testing with
minitest
- Stubbing with
mocha
- Factory pattern
- Template Method pattern
Create a new gem...
$ bundle gem mutant_school_api_model
$ cd mutant_school_api_model
Edit the .gemspec file.
- Update
spec.version
to have "API" in all caps. - Enter a summary and description.
- Update the
bin
directory inspec.bindir
andspec.executables
. - Add
pry
andminitest-reporters
as development dependencies.
minitest-reporters
- Create customizable MiniTest output formats.
- Add
http
as a regular dependency.
HTTP (The Gem! a.k.a. http.rb) is a fast Ruby HTTP client with a chainable API, streaming support, and timeouts mutant_school_api_model.gemspec
spec.version = MutantSchoolAPIModel::VERSION
spec.summary = 'Mutant School API wrapper'
spec.description = 'Mutant School API wrapper for use in automated tests'
# ...
spec.bindir = "bin"
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
# ...
spec.add_development_dependency 'pry', '~> 0.10'
spec.add_development_dependency 'minitest-reporters', '~> 1.1'
spec.add_dependency 'http', '~> 1.0'
Add a few require
s in lib/mutant_school_api_model.rb:
require 'http'
require 'json'
require 'pry'
Rename the module in lib/mutant_school_api_model.rb and lib/mutant_school_api_model/version.rb to have "API" in all caps.
module MutantSchoolAPIModel
Update the bin/console
script to use pry
instead of irb
.
bin/console
#!/usr/bin/env ruby
require "bundler/setup"
require "mutant_school_api_model"
# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
require "pry"
Pry.start
- Rename
test
tospec
. - Rename
spec/mutant_school_api_model_test.rb
tospec/mutant_school_api_model_spec.rb
Rewrite the existing test in declarative style. spec/mutant_school_api_model_spec.rb
require 'test_helper'
describe MutantSchoolApiModel do
it 'has a version number' do
_(::MutantSchoolApiModel::VERSION).wont_be_nil
end
it 'does something useful' do
_(false).must_be_same_as true
end
end
Update the Rakefile
to look for spec
files.
Rakefile
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "spec"
t.libs << "lib"
t.test_files = FileList['spec/**/*_spec.rb']
end
task :default => :spec
Update spec/test_helper.rb to use Minitest::Reporters
.
require "minitest/reporters"
Minitest::Reporters.use!
Run the tests. One should pass, and the other should fail.