Решение на Седма задача от Михаела Чуренска

Обратно към всички решения

Към профила на Михаела Чуренска

Резултати

  • 1 точка от тестове
  • 0 бонус точки
  • 1 точка общо
  • 3 успешни тест(а)
  • 28 неуспешни тест(а)

Код

class LazyMode
class Date
def initialize(data)
@data = data
end
def year
@data.split("-").map(&:to_i)[0]
end
def month
@data.split("-").map(&:to_i)[1]
end
def day
@data.split("-").map(&:to_i)[2]
end
def to_s
@data.insert(0, '0') if(@data.split("-")[0].size < 4)
@data.insert(5, '0') if(@data.split("-")[1].size < 2)
@data.insert(8, '0') if(@data.split("-")[2].size < 2)
@data
end
end
class Note
def initialize(header = '')
@header = header
end
def header
@header
end
def file_name(name)
@file_name = name
@file_name
end
def body(text = String.new)
@body = text
@body
end
def status(status = :postponed)
@status = status
@status
end
def tags(tags)
@tags = tags
end
def scheduled(date)
Date.new(date)
end
end
class File
def create_file(name, &block)
@notes = Note.new
@name = notes.file_name(name)
end
end
end

Лог от изпълнението

...FFFFFFFFFFFFFFFFFFFFFFFFFFFF

Failures:

  1) LazyMode LazyMode::Note has file_name
     Failure/Error: file = LazyMode.create_file('my_todos') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:21:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) LazyMode LazyMode::Note has header
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:30:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) LazyMode LazyMode::Note can have nested notes
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:99:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) LazyMode LazyMode::Note #tags has tags
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:40:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) LazyMode LazyMode::Note #tags can have no tags
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:49:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) LazyMode LazyMode::Note #status has status
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:60:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) LazyMode LazyMode::Note #status can have default status
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:69:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) LazyMode LazyMode::Note #body has body
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:80:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) LazyMode LazyMode::Note #body can have no body
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:89:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) LazyMode#daily_agenda returns note scheduled without repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:120:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) LazyMode#daily_agenda returns note scheduled with daily repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:142:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) LazyMode#daily_agenda returns note scheduled with weekly repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:164:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  13) LazyMode#daily_agenda returns note scheduled with monthly repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:187:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  14) LazyMode#daily_agenda does not return note whose start date is in the future
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:209:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  15) LazyMode#daily_agenda returns nested notes
     Failure/Error: file = LazyMode.create_file('nesting') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:220:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  16) LazyMode#weekly_agenda returns note scheduled without repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:238:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  17) LazyMode#weekly_agenda returns multiple notes with different dates when scheduled with daily repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:260:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  18) LazyMode#weekly_agenda returns note scheduled with weekly repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:284:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  19) LazyMode#weekly_agenda returns note scheduled with monthly repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:316:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  20) LazyMode#weekly_agenda does not return note whose start date is in the future
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:338:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  21) LazyMode#weekly_agenda returns nested notes
     Failure/Error: file = LazyMode.create_file('nesting') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:349:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  22) LazyMode#where filters by tag
     Failure/Error: file = LazyMode.create_file('notes') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:367:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  23) LazyMode#where filters by body text
     Failure/Error: file = LazyMode.create_file('notes') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:367:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  24) LazyMode#where filters by header text
     Failure/Error: file = LazyMode.create_file('notes') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:367:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  25) LazyMode#where filters by status
     Failure/Error: file = LazyMode.create_file('notes') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:367:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  26) LazyMode#where filters by multiple filters
     Failure/Error: file = LazyMode.create_file('notes') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:367:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  27) LazyMode.create_file can assign name to files
     Failure/Error: file = LazyMode.create_file('important_notes_and_todos') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:457:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  28) LazyMode.create_file can build notes in the block
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Class
     # /tmp/d20160107-5693-1pb1xel/spec.rb:464:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01579 seconds
31 examples, 28 failures

Failed examples:

rspec /tmp/d20160107-5693-1pb1xel/spec.rb:20 # LazyMode LazyMode::Note has file_name
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:29 # LazyMode LazyMode::Note has header
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:98 # LazyMode LazyMode::Note can have nested notes
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:39 # LazyMode LazyMode::Note #tags has tags
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:48 # LazyMode LazyMode::Note #tags can have no tags
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:59 # LazyMode LazyMode::Note #status has status
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:68 # LazyMode LazyMode::Note #status can have default status
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:79 # LazyMode LazyMode::Note #body has body
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:88 # LazyMode LazyMode::Note #body can have no body
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:119 # LazyMode#daily_agenda returns note scheduled without repeater
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:141 # LazyMode#daily_agenda returns note scheduled with daily repeater
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:163 # LazyMode#daily_agenda returns note scheduled with weekly repeater
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:186 # LazyMode#daily_agenda returns note scheduled with monthly repeater
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:208 # LazyMode#daily_agenda does not return note whose start date is in the future
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:219 # LazyMode#daily_agenda returns nested notes
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:237 # LazyMode#weekly_agenda returns note scheduled without repeater
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:259 # LazyMode#weekly_agenda returns multiple notes with different dates when scheduled with daily repeater
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:283 # LazyMode#weekly_agenda returns note scheduled with weekly repeater
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:315 # LazyMode#weekly_agenda returns note scheduled with monthly repeater
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:337 # LazyMode#weekly_agenda does not return note whose start date is in the future
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:348 # LazyMode#weekly_agenda returns nested notes
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:390 # LazyMode#where filters by tag
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:408 # LazyMode#where filters by body text
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:420 # LazyMode#where filters by header text
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:432 # LazyMode#where filters by status
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:443 # LazyMode#where filters by multiple filters
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:456 # LazyMode.create_file can assign name to files
rspec /tmp/d20160107-5693-1pb1xel/spec.rb:463 # LazyMode.create_file can build notes in the block

История (1 версия и 0 коментара)

Михаела обнови решението на 21.12.2015 14:49 (преди над 8 години)

+class LazyMode
+
+ class Date
+ def initialize(data)
+ @data = data
+ end
+
+ def year
+ @data.split("-").map(&:to_i)[0]
+ end
+
+ def month
+ @data.split("-").map(&:to_i)[1]
+ end
+
+ def day
+ @data.split("-").map(&:to_i)[2]
+ end
+
+ def to_s
+ @data.insert(0, '0') if(@data.split("-")[0].size < 4)
+ @data.insert(5, '0') if(@data.split("-")[1].size < 2)
+ @data.insert(8, '0') if(@data.split("-")[2].size < 2)
+ @data
+ end
+
+ end
+
+
+ class Note
+ def initialize(header = '')
+ @header = header
+ end
+
+ def header
+ @header
+ end
+
+ def file_name(name)
+ @file_name = name
+ @file_name
+ end
+
+ def body(text = String.new)
+ @body = text
+ @body
+ end
+
+ def status(status = :postponed)
+ @status = status
+ @status
+ end
+
+ def tags(tags)
+ @tags = tags
+ end
+
+ def scheduled(date)
+ Date.new(date)
+ end
+ end
+
+ class File
+ def create_file(name, &block)
+ @notes = Note.new
+ @name = notes.file_name(name)
+ end
+ end
+end