Skip to content
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

Rupert more rspec #82

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

RupertSaxton
Copy link

No description provided.

Gemfile.lock Outdated
@@ -20,3 +20,9 @@ PLATFORMS

DEPENDENCIES
rspec (~> 3.0.0.beta2)

RUBY VERSION
ruby 2.0.0p648
Copy link

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

Copy link
Author

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

output << "Buzz" if input % 5 == 0
output = input if output.empty?

output
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty slick.

Copy link
Author

Choose a reason for hiding this comment

The 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

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!"
Copy link

Choose a reason for hiding this comment

The 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 speak("BYE")'s? If it's all three, then maybe too much is being covered in a single test.

Copy link
Author

Choose a reason for hiding this comment

The 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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏁

@@ -35,6 +50,18 @@ def get_user_input
gets.chomp
end

def soft
Copy link

Choose a reason for hiding this comment

The 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.

Copy link

Choose a reason for hiding this comment

The 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

@bye_counter = 0
yell
end
end
Copy link

Choose a reason for hiding this comment

The 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
end


def speak(input)
if input.match(/\p{Lower}/)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\p{Lower}

Wow, I've never seen this before. Standard approaches would be

  input == input.downcase

or

  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.

Copy link
Author

Choose a reason for hiding this comment

The 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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆒

@@ -14,14 +14,26 @@ def run!
loop do
user_input = get_user_input
p speak(user_input)
exit if @bye_counter == 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since @bye_counter is compared with 3 in two places, consider a new instance method called exiting?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants