learn-co-curriculum / rack-responses-lab Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
This seems to still be a slight issue several years later. Since this lab provides no instructions on the implementation of Time and the SEI courses never really discuss it until now, I'm therefore googling the correct implementation. I find out that Time.now is an alias for Time.new. If I pick the wrong one, when they both should be equal, I get a failure in the tests that is confusing and contrary to the documentation.
I'd suggest an addition to the readme that explains you need to use Time.now to pass the tests. It appears that using Time.new fails because the test ends up getting the system's current time.
I do not see an issue with a readme addition because this lab is about the use of the #write
method and nothing is lost by explaining the small quirk in this test.
Passes:
class Application
def call(env)
resp = Rack::Response.new
if Time.now.hour < 12
resp.write "Good Morning!"
else
resp.write "Good Afternoon"
end
resp.finish
end
end
Fails:
class Application
def call(env)
resp = Rack::Response.new
if Time.new.hour < 12
resp.write "Good Morning!"
else
resp.write "Good Afternoon"
end
resp.finish
end
end
I had to make a change to the tests to set the time, the tests were always using the current time:
allow(Time).to receive(:now).and_return(Time.utc(*[26, 10, 10, 2, 1, 2018, 1, 154, false, "MST"]))
# allow(Time).to receive(:now){
# Time.new(2015,11,27,9,30)
# }
I noticed that the Rack labs are missing the .rspec
files, I added it manually but wasn't sure if it was omitted on purpose so I thought I should submit an issue.
The tests only work if the app gets the time using Time.now (allowing the test to use the time from the spec instead of the current time). It fails if using Time.new because the test will use the system's current time. System time can only be morning or afternoon—so one of the tests will fail.
The code below works in this lab to pass all test cases. However, when initially setting up my instance variable current_time, i used current_time = Time.new.hour . This code did not pass the good afternon rspec. To my knowledge, .now is an alias of .new so both should work? If not what should i take into consideration to distinguish why .now is to be used.
Thank you
class Application
def call(env)
resp = Rack::Response.new
current_time = Time.now.hour #initially i used .new, however, if i used .now, the code works
if current_time > 12
resp.write "Afternoon\n"
else
resp.write "Morning\n"
end
resp.finish
end
end
Spent way too long attempting to refactor my code before I realized the tests were looking for capital Morning and Afternoon. Seems like this could be built into the tests.
The solution says that if the number is greater than 12, then the response should be "Good Afternoon!"
Should we clarify that they should be working with military time? Should we also say that for any time after 12 is afternoon, and any time before 12 is morning.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.