-
Notifications
You must be signed in to change notification settings - Fork 26
Branches - Amal and Julia #2
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?
Conversation
slack.rbWhat We're Looking For
|
| end | ||
|
|
||
| def details | ||
| details = """ |
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.
Triple quotes aren't needed in Ruby like they are in some other languages. Ruby does multi-line strings by default.
| details = """ | |
| details = " |
(In fact Ruby actually reads this as a empty string followed by a multi-line string followed by another empty string. By default in Ruby strings get joined together if they are next to each other. greeting = "Hello," " world!" is the same as greeting = "Hello, world!".)
| end | ||
|
|
||
| def details | ||
| raise NotImplementedError.new "Implement me in a child class!" |
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.
Abstract method! 🎉
| input = gets.chomp | ||
|
|
||
| if workspace.select_channel(input: input) | ||
| workspace.select_channel(input: input) |
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.
Running workspace.select_channel(input: input) twice here is redundant. (The user would already be selected if it worked the first time.)
| """ | ||
| else | ||
| puts """ | ||
| No channel has that name or ID |
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.
I would have liked to have seen this as an error raised in select_channel and then rescued here. You could even put your entire case inside of the begin/rescue to DRY up your code.
until search == "quit"
begin
case search
when "list channels", "channels"
# ...
when "select channel", "channel"
puts "Please enter a channel name or slack_id for the channel you would like to select:"
print prompt
input = gets.chomp
workspace.select_channel(input: input)
puts "
#{input} is now selected
"
when "select user", "user"
puts "Please enter a username or slack_id for the user you would like to select:"
print prompt
input = gets.chomp
workspace.select_user(input: input)
puts "
#{input} is now selected
"
# other menu options...
rescue SlackWorkspaceError => error
puts e.message
end
end| @selected = nil | ||
| end | ||
|
|
||
| def select_channel(input: nil) |
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.
A keyword argument is probably overkill here. Positional parameters can be optional too.
| def select_channel(input: nil) | |
| def select_channel(input = nil) |
Though I'm not sure it makes sense to select a channel without giving a name.
| elsif channel_ids.include?(input) | ||
| @selected = @channels.find { |c| input == c.slack_id } | ||
| else | ||
| return nil |
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.
I'd like to see this raise instead of just returning nil.
| return @selected | ||
| end | ||
|
|
||
| def select_user(input: nil) |
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.
Good use of map and find!
| end | ||
| describe "#initialize" do | ||
| it "creates instance of Channel" do | ||
| VCR.use_cassette("initialize_channel") do |
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.
You don't need to VCR.use_cassette here since Channel.new doesn't make any API calls.
| end | ||
|
|
||
| it "must return accurate info" do | ||
| expect (@channel.details).must_include "cool_things" |
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.
Good use of must_include! This is way more robust then checking the exact string.
|
|
||
| response = HTTParty.get(url, query: query) | ||
|
|
||
| if response["error"] |
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.
You should also check response.code here.
| if response["error"] | |
| if response["error"] || response.code != 200 |
slack.rb
Congratulations! You're submitting your assignment!
You and your partner should collaborate on the answers to these questions.
Comprehension Questions