-
Notifications
You must be signed in to change notification settings - Fork 79
Rupert more rspec #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,9 @@ PLATFORMS | |
|
|
||
| DEPENDENCIES | ||
| rspec (~> 3.0.0.beta2) | ||
|
|
||
| RUBY VERSION | ||
| ruby 2.0.0p648 | ||
|
|
||
| BUNDLED WITH | ||
| 1.16.1 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,14 +14,29 @@ def run! | |
| loop do | ||
| user_input = get_user_input | ||
| p speak(user_input) | ||
| exit if @bye_counter == 3 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
| end | ||
| end | ||
|
|
||
|
|
||
| def speak(input) | ||
| if input.match(/\p{Lower}/) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Wow, I've never seen this before. Standard approaches would be input == input.downcaseor input.match /\A[a-z]*\z/(or something like that, I'm not actually testing these things out.) But if you can point me to do the relevant docs, I'm always happy to pick up another option.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was using an option that was gentle on non-alphabet characters but I achieved the same thing by using upcase as well. \p is a regex way of matching Unicode categories but it's not fully supported across languages (https://www.regular-expressions.info/unicode.html#category). It's supported in Ruby since 1.9 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🆒 |
||
| @bye_counter = 0 | ||
| soft | ||
| else | ||
| if input == "BYE" | ||
| @bye_counter += 1 | ||
|
|
||
| #Implement your code here <<<<<<<<< | ||
|
|
||
| if @bye_counter == 3 | ||
| see_you_later | ||
| else | ||
| yell | ||
| end | ||
| else | ||
| @bye_counter = 0 | ||
| yell | ||
| end | ||
| end | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is nested three levels deep. It's actually not a terrible use-case for deep nesting, but generally that's something to avoid. |
||
| end | ||
|
|
||
| private | ||
|
|
@@ -35,6 +50,18 @@ def get_user_input | |
| gets.chomp | ||
| end | ||
|
|
||
| def soft | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally, you want your method names to be verbs - something an instance of the class in question could do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^^Maybe that's not right. Better: you want your method names to be either verbs (something an instance of the class in question could do) -- or else you want your method names to be nouns - a piece of data an instance of the class can tell you about itself |
||
| "SPEAK UP SONNY!" | ||
| end | ||
|
|
||
| def see_you_later | ||
| "SEE YOU LATER SONNY!" | ||
| end | ||
|
|
||
| def yell | ||
| "NOT SINCE 1964!" | ||
| end | ||
|
|
||
| end | ||
|
|
||
| #Uncomment this next line to run your script but BE SURE to comment it, before you try and run your tests. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,13 @@ class SuperFizzBuzz | |
|
|
||
| def run(input) | ||
|
|
||
| #Implement your code here | ||
| output = "" | ||
|
|
||
| output << "Fizz" if input % 3 == 0 | ||
| output << "Buzz" if input % 5 == 0 | ||
| output = input if output.empty? | ||
|
|
||
| output | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty slick.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw Jay use a similar method a few months back for running a FizzBuzz server with Sinatra and I was impressed with his work |
||
|
|
||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,10 +9,19 @@ | |
| end | ||
|
|
||
| it "says 'NOT SINCE 1964!' when we yell" do | ||
| #implement your test here | ||
| expect(script.speak("HELLO!")).to eq "NOT SINCE 1964!" | ||
| end | ||
|
|
||
| it "EXTRA CREDIT: How would you test yelling BYE?" do | ||
| #implement your test here | ||
| it "says 'SEE YOU LATER SONNY! when we say 3 consecutive 'BYE's" do | ||
| expect(script.speak("BYE")).to eq "NOT SINCE 1964!" | ||
| expect(script.speak("BYE")).to eq "NOT SINCE 1964!" | ||
| expect(script.speak("BYE")).to eq "SEE YOU LATER SONNY!" | ||
| end | ||
|
|
||
| it "says 'NOT SINCE 1964! when we say 3 'BYE's nonconsecutively" do | ||
| expect(script.speak("BYE")).to eq "NOT SINCE 1964!" | ||
| expect(script.speak("BYE")).to eq "NOT SINCE 1964!" | ||
| expect(script.speak("I guess I'll stay")).to eq "SPEAK UP SONNY!" | ||
| expect(script.speak("BYE")).to eq "NOT SINCE 1964!" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are interesting semi-theoretical questions here about what should be under test in these two examples. If it's really what the third response is, given the setup, then why check the expectation on the first two
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. I haven't done much work on testing so I'm still working my way through it. It is aiming to test that saying 'BYE' 3 times non consecutively doesn't change the output. I'll update now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🏁 |
||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:-) all of our stuff is on ruby 2.2, so you'll save yourself some trouble later by switching over now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Gemfile specified 2.0 so for some reason I switched ruby versions as opposed to updating the Gemfile. In hindsight, that wasn't my most efficient option