Conversation
slack.rbWhat We're Looking For
|
| end | ||
|
|
||
| def details | ||
| details = """ |
There was a problem hiding this comment.
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!" |
| input = gets.chomp | ||
|
|
||
| if workspace.select_channel(input: input) | ||
| workspace.select_channel(input: input) |
There was a problem hiding this comment.
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.
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.
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.
I'd like to see this raise instead of just returning nil.
| return @selected | ||
| end | ||
|
|
||
| def select_user(input: nil) |
| end | ||
| describe "#initialize" do | ||
| it "creates instance of Channel" do | ||
| VCR.use_cassette("initialize_channel") do |
There was a problem hiding this comment.
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.
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.
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