diff --git a/.gitignore b/.gitignore index 61a293a..de633b8 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ doc/ config/database.yml TODO +.idea diff --git a/api.rb b/api.rb index f439be6..c304447 100644 --- a/api.rb +++ b/api.rb @@ -8,11 +8,13 @@ Rabl.register! class LogRequest - attr_reader :text, :time, :created_at + attr_reader :text, :time, :created_at, :execution_time + def initialize(time, text) @text = text @time = time @created_at = Time.now + @execution_time = (@created_at - @time).round(2) end @@log = [] @@ -30,7 +32,7 @@ def self.clear_log! end -LogRequest.log_request Time.now, "Just do it alreay" +LogRequest.log_request Time.now, "Just do it already" get '/' do @logs = LogRequest.log diff --git a/spec/api_spec.rb b/spec/api_spec.rb index c51885f..efeed21 100644 --- a/spec/api_spec.rb +++ b/spec/api_spec.rb @@ -23,6 +23,8 @@ def app log_request.fetch("text").should eq("Hello World") time_in_utc = Time.parse(log_request.fetch("time")) time_in_utc.should be_within(1).of(6.seconds.ago.utc) + exec_time = log_request.fetch('execution_time') + exec_time.should be_within(0.5).of(6.seconds) end it "not be ok with /wack" do @@ -42,6 +44,10 @@ def app it "should keep the time" do subject.time.should be_within(0.01).of(45.minutes.ago) end + it 'should have an execution time' do + subject.should respond_to(:execution_time) + subject.execution_time.should be_within(0.5).of(45.minutes) + end describe ":log" do before do @@ -49,17 +55,16 @@ def app LogRequest.log_request(Time.now, "Now") LogRequest.log_request(Time.now, "Now") end + it "should be an array-like thing" do LogRequest.log.count.should eq(2) end - it "should request LogRequest" do + it "should return a LogRequest" do LogRequest.log.first.should be_a(LogRequest) end - it "can clear out the log" do LogRequest.clear_log! LogRequest.log.should be_empty end - end end diff --git a/views/logs.rabl b/views/logs.rabl index a9ac504..f0dcd09 100644 --- a/views/logs.rabl +++ b/views/logs.rabl @@ -1,3 +1,3 @@ collection @logs -attributes :time, :text +attributes :time, :text, :execution_time