Skip to content

Commit

Permalink
v1.0.3 - Refactor specs
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaberer committed Aug 1, 2014
1 parent bd0034d commit 5b4f65d
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 41 deletions.
21 changes: 20 additions & 1 deletion .travis.yml
@@ -1,4 +1,23 @@
language: ruby
env:
global:
- "JRUBY_OPTS=-Xcext.enabled=true"
rvm:
- 1.9.2
- 2.1.0
- 2.0.0
- 1.9.3
- 1.9.2
- 1.8.7
- jruby-18mode
- jruby-19mode
- ruby-head
- jruby-head
- ree
matrix:
allow_failures:
- rvm: 1.8.7
- rvm: ree
- rvm: jruby-18mode
- rvm: jruby-19mode
- rvm: jruby-head
fast_finish: true
26 changes: 12 additions & 14 deletions cinch-simplecalc.gemspec
Expand Up @@ -8,23 +8,21 @@ Gem::Specification.new do |gem|
gem.version = Cinch::Plugins::Simplecalc::VERSION
gem.authors = ['Brian Haberer']
gem.email = ['bhaberer@gmail.com']
gem.description = %q{Cinch Plugin that passes simple numeric math propblems to the Calc gem}
gem.summary = %q{Cinch Plugin to do simple math}
gem.description = %q(Cinch Plugin that passes simple numeric math propblems to the Calc gem)
gem.summary = %q(Cinch Plugin to do simple math)
gem.homepage = 'https://github.com/bhaberer/cinch-simplecalc'
gem.license = 'MIT'

gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
gem.require_paths = ['lib']

gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'coveralls'
gem.add_development_dependency 'cinch-test'

gem.add_dependency 'cinch', '~> 2.0.12'
gem.add_dependency 'cinch-toolbox', '~> 1.1.0'
gem.add_dependency 'cinch-cooldown', '~> 1.1.1'
gem.add_dependency 'calc', '~> 1.0.0'
gem.add_development_dependency 'rake', '~> 10'
gem.add_development_dependency 'rspec', '~> 3'
gem.add_development_dependency 'coveralls', '~> 0.7'
gem.add_development_dependency 'cinch-test', '~> 0.1', '>= 0.1.0'
gem.add_dependency 'cinch', '~> 2'
gem.add_dependency 'cinch-cooldown', '~> 1.1', '>= 1.1.1'
gem.add_dependency 'cinch-toolbox', '~> 1.1'
gem.add_dependency 'calc', '~> 1'
end
36 changes: 19 additions & 17 deletions lib/cinch/plugins/simplecalc.rb
Expand Up @@ -3,29 +3,31 @@
require 'cinch'
require 'cinch/cooldown'

module Cinch::Plugins
# Simple Plugin to do quick math
class SimpleCalc
include Cinch::Plugin
module Cinch
module Plugins
# Simple Plugin to do quick math
class SimpleCalc
include Cinch::Plugin

enforce_cooldown
enforce_cooldown

self.help = 'Use .math <problem> to do math. (i.e. .math 2 + 2)'
self.help = 'Use .math <problem> to do math. (i.e. .math 2 + 2)'

match /math (.+)/
match(/math (.+)/)

def execute(m, problem)
m.reply calc(problem), true
end
def execute(m, problem)
m.reply calc(problem), true
end

private
private

def calc(problem)
answer = Calc.evaluate(problem)
answer unless answer == problem
rescue ZeroDivisionError
# Rescue against people being cute.
"I'm sorry, Dave, I'm afraid I can't do that."
def calc(problem)
answer = Calc.evaluate(problem)
answer unless answer == problem
rescue ZeroDivisionError
# Rescue against people being cute.
"I'm sorry, Dave, I'm afraid I can't do that."
end
end
end
end
2 changes: 1 addition & 1 deletion lib/cinch/plugins/simplecalc/version.rb
Expand Up @@ -3,7 +3,7 @@ module Cinch
module Plugins
# Versioning Info
class Simplecalc
VERSION = '1.0.2'
VERSION = '1.0.3'
end
end
end
10 changes: 4 additions & 6 deletions spec/cinch-simplecalc_spec.rb
Expand Up @@ -10,19 +10,17 @@

it 'should allow users to perform simple math' do
msg = make_message(@bot, '!math 2 + 2')
get_replies(msg).last.text
.should == 'test: 4'
expect(get_replies(msg).last.text).to eq('test: 4')
end

it 'should strip all non numeric information from the string' do
msg = make_message(@bot, '!math cos 2')
get_replies(msg).last.text
.should == 'test: 2'
expect(get_replies(msg).last.text).to eq('test: 2')
end

it 'should crack wise if asked to do the impossible' do
msg = make_message(@bot, '!math 1 / 0')
get_replies(msg).last.text
.should == 'test: I\'m sorry, Dave, I\'m afraid I can\'t do that.'
expect(get_replies(msg).last.text)
.to eq('test: I\'m sorry, Dave, I\'m afraid I can\'t do that.')
end
end
10 changes: 8 additions & 2 deletions spec/spec_helper.rb
@@ -1,5 +1,11 @@
require 'coveralls'
Coveralls.wear!
require 'simplecov'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
SimpleCov.start

require 'cinch-simplecalc'
require 'cinch/test'

0 comments on commit 5b4f65d

Please sign in to comment.