stink_bomb 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb7ad358d7796194b94cb6a8eed905525e0bf75c
4
- data.tar.gz: 9b8abc3e4b9af39c16e5a3a813d5c53fcd1ef830
3
+ metadata.gz: c82e3f52414800f0276ac8121395d132c4215958
4
+ data.tar.gz: c9acb5ae4cdb5e12d2c79988ede0347d72e36914
5
5
  SHA512:
6
- metadata.gz: 62e8dce51d3f57e80cfdf245cbf0fd57f636e60a751ed0b21d20cbfa0cd25365e71495e137ebc3b476d1a5c661d9575831dbc749f90f69e3392a917784506080
7
- data.tar.gz: 96b4766e455ef771909044bda0415e50809b18629905532f150826c3233ce843212b3c605a61e2ba0f4766db316e47813bb0444dfeb85cc576c4c68c456f4841
6
+ metadata.gz: c3458bc18df1bc597e1fd402dc64aa954d9ba1b2311c1aa0f699773ada569c3a1c537239bd1f3fe96842db7e17bc36b6b05382b94b93f04d9ec41c65024dc16d
7
+ data.tar.gz: c102a4f09a8daaabaf7f96342943a2e41449fb3372675d153496afdde0e2ff43ca2be81d8aee58a09cd5925a5406ca757d4a14c1b9a9e3c3a12494241b9e7a32
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
1
  --color
2
- --warnings
3
2
  --require spec_helper
@@ -1,6 +1,8 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
4
  - 2.1.3
4
5
  script:
5
6
  - bundle exec travis lint --skip-completion-check
6
7
  - bundle exec rspec
8
+ - bundle exec rubocop -D
data/Gemfile CHANGED
@@ -4,9 +4,12 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :development, :test do
7
- gem 'coveralls'
8
- gem 'rake'
9
- gem 'travis'
10
- gem 'rubocop'
11
- gem 'rspec'
7
+ gem 'codeclimate-test-reporter', '~> 0.4.4'
8
+ gem 'guard-rspec', '~> 4.5.0'
9
+ gem 'guard-rubocop', '~> 1.2.0'
10
+ gem 'rake', '~> 10.4.2'
11
+ gem 'rspec', '~> 3.1.0'
12
+ gem 'rubocop', '~> 0.28.0'
13
+ gem 'simplecov', '~> 0.9.1'
14
+ gem 'travis', '~> 1.7.4'
12
15
  end
@@ -0,0 +1,22 @@
1
+ group :everything, halt_on_fail: true do
2
+ guard :rspec, cmd: 'bundle exec rspec' do
3
+ require 'guard/rspec/dsl'
4
+ dsl = Guard::RSpec::Dsl.new(self)
5
+
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+ end
15
+
16
+ guard :rubocop, cli: %w(-D) do
17
+ watch(/.+\.rb$/)
18
+ watch(/Guardfile/)
19
+ watch(/Rakefile/)
20
+ watch(/(?:.+\/)?\.rubocop\.yml$/) { |m| File.dirname(m[0]) }
21
+ end
22
+ end
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/stink_bomb.svg)](http://badge.fury.io/rb/stink_bomb)
4
4
  [![Build Status](https://travis-ci.org/ChalkSchools/stink-bomb.svg?branch=master)](https://travis-ci.org/ChalkSchools/stink-bomb)
5
- [![Coverage Status](https://img.shields.io/coveralls/ChalkSchools/stink-bomb.svg)](https://coveralls.io/r/ChalkSchools/stink-bomb?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/ChalkSchools/stink-bomb/badges/gpa.svg)](https://codeclimate.com/github/ChalkSchools/stink-bomb)
6
+ [![Test Coverage](https://codeclimate.com/github/ChalkSchools/stink-bomb/badges/coverage.svg)](https://codeclimate.com/github/ChalkSchools/stink-bomb)
6
7
 
7
8
  Create a `StinkBomb` that will throw an error if your code is out of date.
8
9
  Useful for when you have code that should be addressed in the near future,
@@ -32,7 +33,7 @@ StinkBomb.create('January 20, 2001')
32
33
 
33
34
  ## Contributing
34
35
 
35
- 1. Fork it ( https://github.com/[my-github-username]/stink-bomb/fork )
36
+ 1. Fork it ( https://github.com/ChalkSchools/stink-bomb/fork )
36
37
  2. Create your feature branch (`git checkout -b my-new-feature`)
37
38
  3. Commit your changes (`git commit -am 'Add some feature'`)
38
39
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ require 'rubocop/rake_task'
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: [:spec, :rubocop]
@@ -1,9 +1,54 @@
1
1
  require 'time'
2
2
  require 'stink_bomb/version'
3
+ require 'stink_bomb/configuration'
3
4
  require 'stink_bomb/bomb'
5
+ require 'stink_bomb/raise_bomb'
6
+ require 'stink_bomb/logger_bomb'
4
7
 
5
- class StinkBomb
6
- def self.create(datetime, message: nil)
7
- StinkBomb::Bomb.new(datetime, message: message)
8
+ module StinkBomb
9
+ class StinkyCodeError < StandardError; end
10
+
11
+ class << self
12
+ def create(deadline, message: nil)
13
+ deadline = parse(deadline)
14
+ message = fill_in_message(deadline, message)
15
+ bombs.each { |bomb| bomb.trigger(deadline, message: message) }
16
+ end
17
+
18
+ def configuration
19
+ @configuration ||= Configuration.new
20
+ end
21
+
22
+ def configure
23
+ yield configuration
24
+ end
25
+
26
+ def reset
27
+ @configuration = nil
28
+ end
29
+
30
+ def bombs
31
+ configuration.bombs
32
+ end
33
+
34
+ private
35
+
36
+ def fill_in_message(deadline, message)
37
+ (message || configured_message).gsub('{deadline}', deadline.to_s)
38
+ end
39
+
40
+ def configured_message
41
+ StinkBomb.configuration.message
42
+ end
43
+
44
+ def parse(time)
45
+ if time.is_a?(String)
46
+ Time.parse(time)
47
+ elsif time.respond_to?(:to_time)
48
+ time.to_time
49
+ else
50
+ fail 'Parameter has to be a Time, Date, or a String'
51
+ end
52
+ end
8
53
  end
9
54
  end
@@ -1,31 +1,7 @@
1
- class StinkBomb
1
+ module StinkBomb
2
2
  class Bomb
3
- attr_accessor :datetime
4
-
5
- def initialize(datetime, message: nil)
6
- self.datetime = parse(datetime)
7
- fail (message || fail_message) if !production? && past_datetime?
8
- end
9
-
10
- def parse(datetime)
11
- datetime = DateTime.parse(datetime) if datetime.is_a?(String)
12
- unless datetime.respond_to?(:to_datetime)
13
- fail 'Parameter has to be a Time, Date, or a String'
14
- end
15
-
16
- datetime.to_datetime
17
- end
18
-
19
- def fail_message
20
- "Your code stinks! It was supposed to be fixed by #{datetime}"
21
- end
22
-
23
- def production?
24
- ENV['RAILS_ENV'] == 'production' || ENV['RACK_ENV'] == 'production'
25
- end
26
-
27
- def past_datetime?
28
- Time.now.getlocal.to_datetime > datetime
3
+ def past_deadline?(deadline)
4
+ Time.now.utc > deadline.utc
29
5
  end
30
6
  end
31
7
  end
@@ -0,0 +1,40 @@
1
+ module StinkBomb
2
+ class Configuration
3
+ attr_accessor :message
4
+
5
+ def initialize(options = {})
6
+ self.message = options.fetch(:message) { default_message }
7
+ end
8
+
9
+ def raise=(error_class)
10
+ configure_bomb(RaiseBomb, error_class)
11
+ end
12
+
13
+ def logger=(logger)
14
+ configure_bomb(LoggerBomb, logger)
15
+ end
16
+
17
+ def bombs
18
+ @bombs ||= []
19
+ end
20
+
21
+ private
22
+
23
+ def configure_bomb(bomb_type, bomb_arg)
24
+ remove_bomb(bomb_type)
25
+ if bomb_arg == true
26
+ bombs << bomb_type.new
27
+ elsif bomb_arg
28
+ bombs << bomb_type.new(bomb_arg)
29
+ end
30
+ end
31
+
32
+ def remove_bomb(bomb_class)
33
+ bombs.delete_if { |bomb| bomb.is_a?(bomb_class) }
34
+ end
35
+
36
+ def default_message
37
+ 'Your code stinks! It was supposed to be fixed by {deadline}'
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,15 @@
1
+ module StinkBomb
2
+ class LoggerBomb < Bomb
3
+ attr_accessor :deadline
4
+
5
+ def initialize(logger = nil)
6
+ logger ||= Rails.logger if defined?(Rails)
7
+ fail 'logger responding to "info" is required' unless logger
8
+ @logger = logger
9
+ end
10
+
11
+ def trigger(deadline, message:)
12
+ @logger.info(message) if past_deadline?(deadline)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module StinkBomb
2
+ class RaiseBomb < Bomb
3
+ attr_writer :message
4
+
5
+ def initialize(error_class = StinkyCodeError)
6
+ @error_class = error_class
7
+ end
8
+
9
+ def trigger(deadline, message:)
10
+ fail @error_class, message if past_deadline?(deadline)
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
- class StinkBomb
2
- VERSION = '0.0.1'
1
+ module StinkBomb
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,67 @@
1
+ module StinkBomb
2
+ describe Configuration, '#bombs' do
3
+ let(:configuration) { StinkBomb::Configuration.new }
4
+
5
+ it 'returns an array of the currently assigned bombs' do
6
+ expect(configuration.bombs).to eq []
7
+ configuration.raise = true
8
+ expect(configuration.bombs.length).to eq 1
9
+ end
10
+ end
11
+
12
+ describe Configuration, '#raise=' do
13
+ let(:configuration) { StinkBomb::Configuration.new }
14
+ let(:message) { configuration.message }
15
+ let(:yesterday) { (Date.today - 1).to_time }
16
+
17
+ it 'removes any raise bombs when given false' do
18
+ configuration.bombs << RaiseBomb.new
19
+ configuration.raise = false
20
+ expect(configuration.bombs).to be_empty
21
+ end
22
+
23
+ it 'adds a bomb that raises a stinky error' do
24
+ configuration.raise = true
25
+ expect do
26
+ configuration.bombs.first.trigger(yesterday, message: message)
27
+ end.to raise_error(StinkyCodeError)
28
+ end
29
+
30
+ it 'adds a bomb that raises a specific error class when given' do
31
+ configuration.raise = StinkyTestError
32
+ expect do
33
+ configuration.bombs.first.trigger(yesterday, message: message)
34
+ end.to raise_error(StinkyTestError)
35
+ end
36
+ end
37
+
38
+ describe Configuration, '#logger=' do
39
+ let(:configuration) { StinkBomb::Configuration.new }
40
+ let(:message) { configuration.message }
41
+ let(:fake_logger) { double(info: 'foo') }
42
+ let(:yesterday) { (Date.today - 1).to_time }
43
+
44
+ it 'removes any logger bombs when given false' do
45
+ configuration.bombs << RaiseBomb.new
46
+ configuration.bombs << LoggerBomb.new(fake_logger)
47
+ configuration.logger = false
48
+ expect(configuration.bombs.length).to eq 1
49
+ expect(configuration.bombs.first).to be_a RaiseBomb
50
+ end
51
+
52
+ it 'adds a bomb that logs to the rails logger' do
53
+ stub_const('Rails', double(logger: fake_logger))
54
+ configuration.logger = true
55
+ configuration.bombs.first.trigger(yesterday, message: message)
56
+
57
+ expect(fake_logger).to have_received(:info).with(/Your code stinks!/)
58
+ end
59
+
60
+ it 'adds a bomb that logs to a custom logger' do
61
+ configuration.logger = fake_logger
62
+ configuration.bombs.first.trigger(yesterday, message: message)
63
+
64
+ expect(fake_logger).to have_received(:info).with(/Your code stinks!/)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,51 @@
1
+ module StinkBomb
2
+ describe LoggerBomb, '#initialize' do
3
+ let(:fake_logger) { double(info: 'foo') }
4
+ let(:yesterday) { (Date.today - 1).to_time }
5
+ let(:message) { StinkBomb.configuration.message }
6
+
7
+ it 'accepts a custom logger' do
8
+ LoggerBomb.new(fake_logger).trigger(yesterday, message: message)
9
+
10
+ expect(fake_logger).to have_received(:info).with(/Your code stinks!/)
11
+ end
12
+
13
+ it 'defaults to the Rails logger' do
14
+ stub_const('Rails', double(logger: fake_logger))
15
+
16
+ LoggerBomb.new.trigger(yesterday, message: message)
17
+
18
+ expect(fake_logger).to have_received(:info).with(/Your code stinks!/)
19
+ end
20
+
21
+ it 'fails if no valid logger is given or found' do
22
+ expect { LoggerBomb.new }.to raise_error(/logger.*required/)
23
+ end
24
+ end
25
+
26
+ describe LoggerBomb, '#trigger' do
27
+ let(:fake_logger) { double(info: 'foo') }
28
+ let(:logger_bomb) { LoggerBomb.new(fake_logger) }
29
+ let(:message) { StinkBomb.configuration.message }
30
+ let(:yesterday) { (Date.today - 1).to_time }
31
+ let(:tomorrow) { (Date.today + 1).to_time }
32
+
33
+ it 'does nothing if tomorrow is given' do
34
+ logger_bomb.trigger(tomorrow, message: message)
35
+
36
+ expect(fake_logger).not_to have_received(:info).with(/Your code stinks!/)
37
+ end
38
+
39
+ it 'does nothing if now + epsilon is given' do
40
+ logger_bomb.trigger(Time.now.getlocal + 1, message: message)
41
+
42
+ expect(fake_logger).not_to have_received(:info).with(/Your code stinks!/)
43
+ end
44
+
45
+ it 'logs a message if the given date is before today' do
46
+ logger_bomb.trigger(yesterday, message: message)
47
+
48
+ expect(fake_logger).to have_received(:info).with(/Your code stinks!/)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,44 @@
1
+ module StinkBomb
2
+ describe RaiseBomb, '#initialize' do
3
+ let(:message) { StinkBomb.configuration.message }
4
+ let(:yesterday) { (Date.today - 1).to_time }
5
+
6
+ it 'accepts an error class to raise' do
7
+ raise_bomb = RaiseBomb.new(StinkyTestError)
8
+ expect do
9
+ raise_bomb.trigger(yesterday, message: message)
10
+ end.to raise_error(StinkyTestError, /Your code stinks!/)
11
+ end
12
+
13
+ it 'raises a StinkyCodeError by default' do
14
+ expect do
15
+ RaiseBomb.new.trigger(yesterday, message: message)
16
+ end.to raise_error(StinkyCodeError, /Your code stinks!/)
17
+ end
18
+ end
19
+
20
+ describe RaiseBomb, '#trigger' do
21
+ let(:raise_bomb) { RaiseBomb.new }
22
+ let(:message) { StinkBomb.configuration.message }
23
+ let(:yesterday) { (Date.today - 1).to_time }
24
+ let(:tomorrow) { (Date.today + 1).to_time }
25
+
26
+ it 'does nothing if tomorrow is given' do
27
+ expect do
28
+ raise_bomb.trigger(tomorrow, message: message)
29
+ end.not_to raise_error
30
+ end
31
+
32
+ it 'does nothing if now + epsilon is given' do
33
+ expect do
34
+ raise_bomb.trigger(Time.now.getlocal + 1, message: message)
35
+ end.not_to raise_error
36
+ end
37
+
38
+ it 'raises an error if the given date is before today' do
39
+ expect do
40
+ raise_bomb.trigger(yesterday, message: message)
41
+ end.to raise_error(/Your code stinks!/)
42
+ end
43
+ end
44
+ end
@@ -1,8 +1,75 @@
1
1
  describe StinkBomb do
2
- describe '#create' do
3
- it 'creates an instance of Bomb with the parameters' do
4
- expect(StinkBomb::Bomb).to receive(:new).with('My date', message: nil)
5
- StinkBomb.create('My date')
2
+ describe '.create' do
3
+ let(:configuration) { StinkBomb.configuration }
4
+ let(:yesterday) { (Date.today - 1).to_time }
5
+
6
+ it 'triggers the configured bombs when there are bombs configured' do
7
+ configuration.raise = true
8
+ expect do
9
+ StinkBomb.create('01/01/1900')
10
+ end.to raise_error(StinkBomb::StinkyCodeError)
11
+ end
12
+
13
+ it 'does nothing when there are no bombs triggered' do
14
+ expect { StinkBomb.create('01/01/1900') }.not_to raise_error
15
+ end
16
+
17
+ it 'accepts a date object' do
18
+ configuration.raise = true
19
+ expect do
20
+ StinkBomb.create(yesterday)
21
+ end.to raise_error(StinkBomb::StinkyCodeError)
22
+ end
23
+
24
+ it 'accepts a time object' do
25
+ configuration.raise = true
26
+ expect do
27
+ StinkBomb.create(Time.now.getlocal - 86_400)
28
+ end.to raise_error(StinkBomb::StinkyCodeError)
29
+ end
30
+
31
+ it 'raises an error if the time is not a date or a string' do
32
+ expect do
33
+ StinkBomb.create(1)
34
+ end.to raise_error('Parameter has to be a Time, Date, or a String')
35
+ end
36
+
37
+ it 'raises an error if the given date is after today' do
38
+ configuration.raise = true
39
+ yesterday_string = Regexp.quote(yesterday.to_s)
40
+ expect do
41
+ StinkBomb.create(yesterday)
42
+ end.to raise_error(/It was supposed to be fixed by #{yesterday_string}/)
43
+ end
44
+
45
+ it 'raises a custom message when specified' do
46
+ configuration.raise = true
47
+ yesterday_string = Regexp.quote(yesterday.to_s)
48
+ expect do
49
+ StinkBomb.create(yesterday, message: '{deadline} Smells like poo')
50
+ end.to raise_error(/#{yesterday_string} Smells like poo/)
51
+ end
52
+ end
53
+
54
+ describe '.configuration' do
55
+ it 'returns the same object every time' do
56
+ expect(StinkBomb.configuration).to equal(StinkBomb.configuration)
57
+ end
58
+ end
59
+
60
+ describe '.configure' do
61
+ it 'yields the current configuration' do
62
+ StinkBomb.configure do |configuration|
63
+ expect(configuration).to equal(StinkBomb.configuration)
64
+ end
65
+ end
66
+ end
67
+
68
+ describe '.reset' do
69
+ it 'resets the configuration' do
70
+ old_configuration = StinkBomb.configuration
71
+ StinkBomb.reset
72
+ expect(StinkBomb.configuration).not_to equal(old_configuration)
6
73
  end
7
74
  end
8
75
  end
@@ -1,9 +1,21 @@
1
- require 'coveralls'
2
- Coveralls.wear!
1
+ require 'simplecov'
2
+ if ENV['CI']
3
+ require 'codeclimate-test-reporter'
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ CodeClimate::TestReporter::Formatter
7
+ ]
8
+ SimpleCov.minimum_coverage 100
9
+ end
10
+ SimpleCov.start { add_filter '/spec/' }
3
11
 
4
12
  require_relative '../lib/stink_bomb'
5
13
 
6
14
  RSpec.configure do |config|
7
15
  config.filter_run focus: true
8
16
  config.run_all_when_everything_filtered = true
17
+
18
+ config.after(:each) { StinkBomb.reset }
9
19
  end
20
+
21
+ class StinkyTestError < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stink_bomb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Holman Gao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-01 00:00:00.000000000 Z
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -17,18 +17,24 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - .gitignore
21
- - .rspec
22
- - .rubocop.yml
23
- - .travis.yml
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - ".travis.yml"
24
24
  - Gemfile
25
+ - Guardfile
25
26
  - LICENSE.txt
26
27
  - README.md
27
28
  - Rakefile
28
29
  - lib/stink_bomb.rb
29
30
  - lib/stink_bomb/bomb.rb
31
+ - lib/stink_bomb/configuration.rb
32
+ - lib/stink_bomb/logger_bomb.rb
33
+ - lib/stink_bomb/raise_bomb.rb
30
34
  - lib/stink_bomb/version.rb
31
- - spec/lib/stink_bomb/bomb_spec.rb
35
+ - spec/lib/stink_bomb/configuration_spec.rb
36
+ - spec/lib/stink_bomb/logger_bomb_spec.rb
37
+ - spec/lib/stink_bomb/raise_bomb_spec.rb
32
38
  - spec/lib/stink_bomb_spec.rb
33
39
  - spec/spec_helper.rb
34
40
  - stink_bomb.gemspec
@@ -42,22 +48,23 @@ require_paths:
42
48
  - lib
43
49
  required_ruby_version: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - '>='
51
+ - - ">="
46
52
  - !ruby/object:Gem::Version
47
53
  version: '0'
48
54
  required_rubygems_version: !ruby/object:Gem::Requirement
49
55
  requirements:
50
- - - '>='
56
+ - - ">="
51
57
  - !ruby/object:Gem::Version
52
58
  version: '0'
53
59
  requirements: []
54
60
  rubyforge_project:
55
- rubygems_version: 2.2.2
61
+ rubygems_version: 2.4.3
56
62
  signing_key:
57
63
  specification_version: 4
58
64
  summary: Fail your CI when your code becomes stinky
59
65
  test_files:
60
- - spec/lib/stink_bomb/bomb_spec.rb
66
+ - spec/lib/stink_bomb/configuration_spec.rb
67
+ - spec/lib/stink_bomb/logger_bomb_spec.rb
68
+ - spec/lib/stink_bomb/raise_bomb_spec.rb
61
69
  - spec/lib/stink_bomb_spec.rb
62
70
  - spec/spec_helper.rb
63
- has_rdoc:
@@ -1,43 +0,0 @@
1
- class StinkBomb
2
- describe Bomb, '#initialize' do
3
- it 'does nothing if tomorrow is given' do
4
- expect do
5
- Bomb.new(Date.today + 1)
6
- end.not_to raise_error
7
- end
8
-
9
- it 'does nothing if now + epsilon is given' do
10
- expect do
11
- Bomb.new(Time.now.getlocal + 1)
12
- end.not_to raise_error
13
- end
14
-
15
- it 'does not raise an error in production' do
16
- expect(ENV).to receive(:[]).with('RAILS_ENV').and_return('production')
17
-
18
- expect do
19
- Bomb.new(Date.today - 1)
20
- end.not_to raise_error
21
- end
22
-
23
- it 'raises a custom message when specified' do
24
- yesterday = Date.today - 1
25
- expect do
26
- Bomb.new(yesterday, message: 'Smells like poo')
27
- end.to raise_error(/Smells like poo/)
28
- end
29
-
30
- it 'raises an error if the given date is after today' do
31
- yesterday = Date.today - 1
32
- expect do
33
- Bomb.new(yesterday)
34
- end.to raise_error(/stinks! It was supposed to be fixed by #{yesterday}/)
35
- end
36
-
37
- it 'raises an error if the parameter is not a date or a string' do
38
- expect do
39
- Bomb.new(1)
40
- end.to raise_error('Parameter has to be a Time, Date, or a String')
41
- end
42
- end
43
- end