diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4a9bb29..d924416 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-11-15 20:50:06 UTC using RuboCop version 1.3.0. +# on 2020-11-15 22:07:57 UTC using RuboCop version 1.3.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -23,6 +23,18 @@ Layout/EmptyLinesAroundAttributeAccessor: - 'slack-shellbot/models/current_directory_entry.rb' - 'slack-shellbot/models/parent_directory_entry.rb' +# Offense count: 8 +Lint/MixedRegexpCaptureTypes: + Exclude: + - 'slack-shellbot/commands/cat.rb' + - 'slack-shellbot/commands/cd.rb' + - 'slack-shellbot/commands/echo.rb' + - 'slack-shellbot/commands/mkdir.rb' + - 'slack-shellbot/commands/rm.rb' + - 'slack-shellbot/commands/rmdir.rb' + - 'slack-shellbot/commands/touch.rb' + - 'slack-shellbot/commands/vi.rb' + # Offense count: 2 # Cop supports --auto-correct. Lint/NonDeterministicRequireOrder: @@ -51,7 +63,7 @@ Naming/HeredocDelimiterNaming: - 'slack-shellbot/commands/help.rb' - 'slack-shellbot/info.rb' -# Offense count: 43 +# Offense count: 19 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https diff --git a/Gemfile b/Gemfile index dbf170b..0bc735f 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem 'rack-robotz' gem 'rack-server-pages' gem 'slack-ruby-bot-server' gem 'slack-ruby-bot-server-mailchimp' -gem 'slack-ruby-bot-server-rtm', github: 'slack-ruby/slack-ruby-bot-server-rtm', branch: 'main' +gem 'slack-ruby-bot-server-rtm' gem 'unicorn' group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 01ff30d..ed0ce31 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,13 +1,3 @@ -GIT - remote: git://github.com/slack-ruby/slack-ruby-bot-server-rtm.git - revision: b6b030c89a303bee09cb060fe1118a61703fc20b - branch: main - specs: - slack-ruby-bot-server-rtm (0.1.1) - async-websocket (~> 0.8.0) - slack-ruby-bot (>= 0.12.0) - slack-ruby-bot-server (>= 1.0.0) - GEM remote: https://rubygems.org/ specs: @@ -256,6 +246,10 @@ GEM slack-ruby-bot-server-mailchimp (0.2.0) mailchimp_api_v3 slack-ruby-bot-server (>= 0.10.0) + slack-ruby-bot-server-rtm (0.1.1) + async-websocket (~> 0.8.0) + slack-ruby-bot (>= 0.12.0) + slack-ruby-bot-server (>= 1.0.0) slack-ruby-client (0.14.6) activesupport faraday (>= 0.9) @@ -314,7 +308,7 @@ DEPENDENCIES selenium-webdriver slack-ruby-bot-server slack-ruby-bot-server-mailchimp - slack-ruby-bot-server-rtm! + slack-ruby-bot-server-rtm unicorn vcr webmock diff --git a/config/initializers/slack-ruby-bot/hooks/message.rb b/config/initializers/slack-ruby-bot/hooks/message.rb index 53b3846..6053526 100644 --- a/config/initializers/slack-ruby-bot/hooks/message.rb +++ b/config/initializers/slack-ruby-bot/hooks/message.rb @@ -6,7 +6,6 @@ def call(client, data) return if client.message_to_self?(data) Thread.current[:stdout] = [] - data = Hashie::Mash.new(data) return if data.subtype if data.key?(:text) @@ -14,6 +13,7 @@ def call(client, data) command, redirect_to = split_redirect(data.text) data.text = command if command end + fs = client.owner.fs[data.channel] if data.channel if fs && fs.program client.logger.info "PROGRAM: #{client.owner}, #{fs}, program=#{fs.program._type}, user=#{data.user}, message_ts=#{fs.program.message_ts}" diff --git a/slack-shellbot/commands/cat.rb b/slack-shellbot/commands/cat.rb index 0892459..e106094 100644 --- a/slack-shellbot/commands/cat.rb +++ b/slack-shellbot/commands/cat.rb @@ -1,9 +1,11 @@ module SlackShellbot module Commands class Cat < SlackRubyBot::Commands::Base + match(/^cat([\s])?(?.*)$/) + def self.call(client, data, match) fs = client.owner.fs[data.channel] - file = Shellwords.split(match['expression']).first if match.names.include?('expression') + file = Shellwords.split(match['file']).first if match.names.include?('file') raise 'usage: cat ...' unless file file_entry = fs.current_directory_entry.find(file) diff --git a/slack-shellbot/commands/cd.rb b/slack-shellbot/commands/cd.rb index a249d60..0399029 100644 --- a/slack-shellbot/commands/cd.rb +++ b/slack-shellbot/commands/cd.rb @@ -1,9 +1,11 @@ module SlackShellbot module Commands class Cd < SlackRubyBot::Commands::Base + match(/^cd([\s])?(?.*)$/) + def self.call(client, data, match) fs = client.owner.fs[data.channel] - directory = Shellwords.split(match['expression']).first if match.names.include?('expression') + directory = Shellwords.split(match['path']).first if match.names.include?('path') raise 'usage: cd directory ...' unless directory directory_entry = fs.cd(directory) diff --git a/slack-shellbot/commands/echo.rb b/slack-shellbot/commands/echo.rb index 8e1c208..10cf8ec 100644 --- a/slack-shellbot/commands/echo.rb +++ b/slack-shellbot/commands/echo.rb @@ -1,11 +1,14 @@ module SlackShellbot module Commands class Echo < SlackRubyBot::Commands::Base + match(/^echo$/) + match(/^echo([\s])?(?.*)$/) + def self.call(client, data, match) fs = client.owner.fs[data.channel] - expression = match['expression'] if match.names.include?('expression') - client.say(channel: data.channel, text: expression || "\n") - logger.info "ECHO: #{client.owner}, #{fs}, expression=#{expression}, user=#{data.user}" + text = match['text'] if match.names.include?('text') + client.say(channel: data.channel, text: text || "\n") + logger.info "ECHO: #{client.owner}, #{fs}, text=#{text}, user=#{data.user}" end end end diff --git a/slack-shellbot/commands/help.rb b/slack-shellbot/commands/help.rb index 1759d8f..8c061b8 100644 --- a/slack-shellbot/commands/help.rb +++ b/slack-shellbot/commands/help.rb @@ -1,6 +1,8 @@ module SlackShellbot module Commands class Help < SlackRubyBot::Commands::Base + command 'help' + HELP = <<~EOS.freeze I am your friendly Shellbot, here to help. diff --git a/slack-shellbot/commands/ls.rb b/slack-shellbot/commands/ls.rb index 1ca62e3..e1066a9 100644 --- a/slack-shellbot/commands/ls.rb +++ b/slack-shellbot/commands/ls.rb @@ -1,6 +1,8 @@ module SlackShellbot module Commands class Ls < SlackRubyBot::Commands::Base + match(/^ls$/) + def self.call(client, data, _match) fs = client.owner.fs[data.channel] dirs = fs.current_directory_entry.map(&:to_s).join("\n") diff --git a/slack-shellbot/commands/mkdir.rb b/slack-shellbot/commands/mkdir.rb index 4d07366..991f0e3 100644 --- a/slack-shellbot/commands/mkdir.rb +++ b/slack-shellbot/commands/mkdir.rb @@ -1,9 +1,11 @@ module SlackShellbot module Commands class Mkdir < SlackRubyBot::Commands::Base + match(/^mkdir([\s])?(?.*)$/) + def self.call(client, data, match) fs = client.owner.fs[data.channel] - directory = Shellwords.split(match['expression']).first if match.names.include?('expression') + directory = Shellwords.split(match['path']).first if match.names.include?('path') raise 'usage: mkdir ...' unless directory directory_entry = fs.current_directory_entry.mkdir(directory) diff --git a/slack-shellbot/commands/pwd.rb b/slack-shellbot/commands/pwd.rb index 81b7cc0..fe467cc 100644 --- a/slack-shellbot/commands/pwd.rb +++ b/slack-shellbot/commands/pwd.rb @@ -1,6 +1,8 @@ module SlackShellbot module Commands class Pwd < SlackRubyBot::Commands::Base + match(/^pwd$/) + def self.call(client, data, _match) fs = client.owner.fs[data.channel] client.say(channel: data.channel, text: fs.current_directory_entry.path) diff --git a/slack-shellbot/commands/rm.rb b/slack-shellbot/commands/rm.rb index 02c5b07..bdf114d 100644 --- a/slack-shellbot/commands/rm.rb +++ b/slack-shellbot/commands/rm.rb @@ -1,9 +1,11 @@ module SlackShellbot module Commands class Rm < SlackRubyBot::Commands::Base + match(/^rm([\s])?(?.*)$/) + def self.call(client, data, match) fs = client.owner.fs[data.channel] - file = Shellwords.split(match['expression']).first if match.names.include?('expression') + file = Shellwords.split(match['file']).first if match.names.include?('file') raise 'usage: rm ...' unless file file_entry = fs.current_directory_entry.rm(file) diff --git a/slack-shellbot/commands/rmdir.rb b/slack-shellbot/commands/rmdir.rb index 55ed507..6227ed7 100644 --- a/slack-shellbot/commands/rmdir.rb +++ b/slack-shellbot/commands/rmdir.rb @@ -1,9 +1,11 @@ module SlackShellbot module Commands class Rmdir < SlackRubyBot::Commands::Base + match(/^rmdir([\s])?(?.*)$/) + def self.call(client, data, match) fs = client.owner.fs[data.channel] - directory = Shellwords.split(match['expression']).first if match.names.include?('expression') + directory = Shellwords.split(match['path']).first if match.names.include?('path') raise 'usage: rmdir ...' unless directory directory_entry = fs.current_directory_entry.rmdir(directory) diff --git a/slack-shellbot/commands/touch.rb b/slack-shellbot/commands/touch.rb index cb948c8..f9b53fd 100644 --- a/slack-shellbot/commands/touch.rb +++ b/slack-shellbot/commands/touch.rb @@ -1,9 +1,11 @@ module SlackShellbot module Commands class Touch < SlackRubyBot::Commands::Base + match(/^touch([\s])?(?.*)$/) + def self.call(client, data, match) fs = client.owner.fs[data.channel] - file = Shellwords.split(match['expression']).first if match.names.include?('expression') + file = Shellwords.split(match['file']).first if match.names.include?('file') raise 'usage: touch ...' unless file file_entry = fs.current_directory_entry.touch(file) diff --git a/slack-shellbot/commands/uname.rb b/slack-shellbot/commands/uname.rb index 14a3f81..738c517 100644 --- a/slack-shellbot/commands/uname.rb +++ b/slack-shellbot/commands/uname.rb @@ -1,6 +1,8 @@ module SlackShellbot module Commands class Uname < SlackRubyBot::Commands::Base + match(/^uname$/) + def self.call(client, data, _match) client.say(channel: data.channel, text: 'Shell') logger.info "UNAME: #{client.owner}, user=#{data.user}" diff --git a/slack-shellbot/commands/vi.rb b/slack-shellbot/commands/vi.rb index 8424e7b..9d25a85 100644 --- a/slack-shellbot/commands/vi.rb +++ b/slack-shellbot/commands/vi.rb @@ -1,9 +1,11 @@ module SlackShellbot module Commands class Vi < SlackRubyBot::Commands::Base + match(/^vi([\s])?(?.*)$/) + def self.call(client, data, match) fs = client.owner.fs[data.channel] - filename = Shellwords.split(match['expression']).first if match.names.include?('expression') + filename = Shellwords.split(match['path']).first if match.names.include?('path') program = ViProgram.create!(filename: filename, file_system: fs) sent = client.say(channel: data.channel, text: program.to_s) program.update_attributes!(message_ts: sent.ts) if sent && sent.ts diff --git a/slack-shellbot/commands/whoami.rb b/slack-shellbot/commands/whoami.rb index 7a73092..5fc2623 100644 --- a/slack-shellbot/commands/whoami.rb +++ b/slack-shellbot/commands/whoami.rb @@ -1,6 +1,8 @@ module SlackShellbot module Commands class Whoami < SlackRubyBot::Commands::Base + match(/^whoami$/) + def self.call(client, data, _match) client.say(channel: data.channel, text: "<@#{data.user}>") logger.info "UNAME: #{client.owner}, user=#{data.user}" diff --git a/slack-shellbot/models/vi_program.rb b/slack-shellbot/models/vi_program.rb index 1fa5822..7ac918f 100644 --- a/slack-shellbot/models/vi_program.rb +++ b/slack-shellbot/models/vi_program.rb @@ -16,7 +16,7 @@ def to_s def message(client, request) ensure_data text, = SlackRubyBot::Commands::Base.send(:parse, client, request) - match = text.match(/^(?\S*)[\s]*(?.*)$/) + match = text.match(/(?.*)$/) expression = match['expression'] if match.names.include?('expression') if expression case expression diff --git a/spec/slack-shellbot/commands/cat_spec.rb b/spec/slack-shellbot/commands/cat_spec.rb index 6e2d861..6db6761 100644 --- a/spec/slack-shellbot/commands/cat_spec.rb +++ b/spec/slack-shellbot/commands/cat_spec.rb @@ -10,7 +10,11 @@ let!(:file) { Fabricate(:file_entry, data: 'hello world', parent_directory_entry: fs.root_directory_entry) } it 'pipe into a file' do expect(client).to receive(:say).with(channel: 'channel', text: 'hello world') - message_hook.call(client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} cat #{file.name}", channel: 'channel', team: team)) + message_hook.call(client, Hashie::Mash.new(text: "cat #{file.name}", channel: 'channel', team: team)) + end + it 'provides syntax' do + expect(client).to receive(:say).with(channel: 'channel', text: 'usage: cat ...') + message_hook.call(client, Hashie::Mash.new(text: "cat", channel: 'channel', team: team)) end end end diff --git a/spec/slack-shellbot/commands/cd_spec.rb b/spec/slack-shellbot/commands/cd_spec.rb index 199c6ce..d555d6e 100644 --- a/spec/slack-shellbot/commands/cd_spec.rb +++ b/spec/slack-shellbot/commands/cd_spec.rb @@ -8,13 +8,13 @@ context 'cd' do it 'changes directory' do expect(client).to receive(:say).with(channel: 'channel', text: '/test') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} mkdir test", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "mkdir test", channel: 'channel')) expect(client).to receive(:say).with(channel: 'channel', text: '/test') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} cd test", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "cd test", channel: 'channel')) expect(client).to receive(:say).with(channel: 'channel', text: '/test') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} pwd", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "pwd", channel: 'channel')) end end end diff --git a/spec/slack-shellbot/commands/echo_spec.rb b/spec/slack-shellbot/commands/echo_spec.rb index 9e495e8..562aefe 100644 --- a/spec/slack-shellbot/commands/echo_spec.rb +++ b/spec/slack-shellbot/commands/echo_spec.rb @@ -8,17 +8,17 @@ context 'echo' do it 'no message' do expect(client).to receive(:say).with(channel: 'channel', text: "\n") - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} echo", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "echo", channel: 'channel')) end it 'message' do expect(client).to receive(:say).with(channel: 'channel', text: 'hi') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} echo hi", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "echo hi", channel: 'channel')) end it 'pipe into a file' do expect do expect(client.web_client).to receive(:chat_postMessage).with(channel: 'channel', text: '```hi```', as_user: true) expect(client.web_client).to receive(:chat_postMessage).with(channel: 'channel', text: '```2 byte(s) written```', as_user: true) - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} echo hi > \"text file.txt\"", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "echo hi > \"text file.txt\"", channel: 'channel')) end.to change(FileEntry, :count).by(1) root = team.fs['channel'].root_directory_entry expect(root.entries.count).to eq 1 diff --git a/spec/slack-shellbot/commands/ls_spec.rb b/spec/slack-shellbot/commands/ls_spec.rb index de39bba..ccea56a 100644 --- a/spec/slack-shellbot/commands/ls_spec.rb +++ b/spec/slack-shellbot/commands/ls_spec.rb @@ -8,7 +8,7 @@ context 'ls' do it 'returns contents of the current directory' do expect(client).to receive(:say).with(channel: 'channel', text: ".\n..") - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} ls", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "ls", channel: 'channel')) end end end diff --git a/spec/slack-shellbot/commands/mkdir_spec.rb b/spec/slack-shellbot/commands/mkdir_spec.rb index 906c6fa..14410cc 100644 --- a/spec/slack-shellbot/commands/mkdir_spec.rb +++ b/spec/slack-shellbot/commands/mkdir_spec.rb @@ -8,11 +8,11 @@ context 'mkdir' do it 'returns current directory' do expect(client).to receive(:say).with(channel: 'channel', text: '/test') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} mkdir test", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "mkdir test", channel: 'channel')) end it 'makes a directory with a space' do expect(client).to receive(:say).with(channel: 'channel', text: '/foo bar') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} mkdir \"foo bar\"", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "mkdir \"foo bar\"", channel: 'channel')) end end end diff --git a/spec/slack-shellbot/commands/pwd_spec.rb b/spec/slack-shellbot/commands/pwd_spec.rb index b2e09a0..5729753 100644 --- a/spec/slack-shellbot/commands/pwd_spec.rb +++ b/spec/slack-shellbot/commands/pwd_spec.rb @@ -8,7 +8,7 @@ context 'pwd' do it 'returns current directory' do expect(client).to receive(:say).with(channel: 'channel', text: '/') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} pwd", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "pwd", channel: 'channel')) end end end diff --git a/spec/slack-shellbot/commands/rm_spec.rb b/spec/slack-shellbot/commands/rm_spec.rb index e16dfc8..8ff64d0 100644 --- a/spec/slack-shellbot/commands/rm_spec.rb +++ b/spec/slack-shellbot/commands/rm_spec.rb @@ -12,7 +12,7 @@ it 'returns removed file name' do expect do expect(client).to receive(:say).with(channel: 'channel', text: '/test.txt') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} rm test.txt", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "rm test.txt", channel: 'channel')) end.to change(FileEntry, :count).by(-1) end end @@ -21,7 +21,7 @@ it 'returns removed file name' do expect do expect(client).to receive(:say).with(channel: 'channel', text: '/> test.txt') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} rm \"> test.txt\"", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "rm \"> test.txt\"", channel: 'channel')) end.to change(FileEntry, :count).by(-1) end end diff --git a/spec/slack-shellbot/commands/touch_spec.rb b/spec/slack-shellbot/commands/touch_spec.rb index af031b2..b96426c 100644 --- a/spec/slack-shellbot/commands/touch_spec.rb +++ b/spec/slack-shellbot/commands/touch_spec.rb @@ -8,7 +8,7 @@ context 'touch' do it 'returns new file name' do expect(client).to receive(:say).with(channel: 'channel', text: '/test.txt') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} touch test.txt", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "touch test.txt", channel: 'channel')) end end end diff --git a/spec/slack-shellbot/commands/uname_spec.rb b/spec/slack-shellbot/commands/uname_spec.rb index 3529fe3..3334550 100644 --- a/spec/slack-shellbot/commands/uname_spec.rb +++ b/spec/slack-shellbot/commands/uname_spec.rb @@ -8,7 +8,7 @@ context 'uname' do it 'returns Shell' do expect(client).to receive(:say).with(channel: 'channel', text: 'Shell') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} uname", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "uname", channel: 'channel')) end end end diff --git a/spec/slack-shellbot/commands/vi_spec.rb b/spec/slack-shellbot/commands/vi_spec.rb index 7dac65d..c5d4a5e 100644 --- a/spec/slack-shellbot/commands/vi_spec.rb +++ b/spec/slack-shellbot/commands/vi_spec.rb @@ -10,7 +10,7 @@ it 'creates a file' do expect do expect(client).to receive(:say).with(channel: 'channel', text: "~|\n\n\n\"/test.txt\" [New File]") - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} vi test.txt", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "vi test.txt", channel: 'channel')) end.to change(Program, :count).by(1) expect(fs.reload.program).to be_a ViProgram end @@ -19,7 +19,7 @@ it 'opens an existing file' do expect do expect(client).to receive(:say).with(channel: 'channel', text: "hello world\n~|\n\n\n\"/name.txt\" 1 line(s), 11 character(s)") - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} vi \"#{file.name}\"", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "vi \"#{file.name}\"", channel: 'channel')) end.to change(Program, :count).by(1) expect(fs.reload.program).to be_a ViProgram end @@ -29,22 +29,22 @@ let!(:vi) { Fabricate(:vi_program, file_system: fs, file_entry: file, filename: file.name) } it 'appends to the file' do expect(client).to receive(:say).with(channel: 'channel', text: "\hello world\nanother line\n~|\n\n\n\"/name.txt\" 2 line(s), 24 character(s)") - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} another line", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "another line", channel: 'channel')) expect(vi.reload.data).to eq ['hello world', 'another line'].join("\n") expect(file.reload.data).to eq ['hello world'].join("\n") end it 'saves file' do expect(client).to receive(:say).with(channel: 'channel', text: "\hello world\nanother line\n~|\n\n\n\"/name.txt\" 2 line(s), 24 character(s)") - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} another line", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "another line", channel: 'channel')) expect(client).to receive(:say).with(channel: 'channel', text: 'written /name.txt, 2 line(s), 24 character(s)') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} :wq", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: ":wq", channel: 'channel')) expect(file.reload.data).to eq ['hello world', 'another line'].join("\n") end it 'quits without saving file' do expect(client).to receive(:say).with(channel: 'channel', text: "\hello world\nanother line\n~|\n\n\n\"/name.txt\" 2 line(s), 24 character(s)") - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} another line", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "another line", channel: 'channel')) expect(client).to receive(:say).with(channel: 'channel', text: 'quit without saving /name.txt') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} :q", channel: 'channel')) + message_hook.call(client, Hashie::Mash.new(team: team, text: ":q", channel: 'channel')) expect(file.reload.data).to eq ['hello world'].join("\n") end end diff --git a/spec/slack-shellbot/commands/whoami_spec.rb b/spec/slack-shellbot/commands/whoami_spec.rb index ef241be..777365a 100644 --- a/spec/slack-shellbot/commands/whoami_spec.rb +++ b/spec/slack-shellbot/commands/whoami_spec.rb @@ -8,7 +8,7 @@ context 'whoami' do it 'returns username' do expect(client).to receive(:say).with(channel: 'channel', text: '<@user>') - message_hook.call(client, Hashie::Mash.new(team: team, text: "#{SlackRubyBot.config.user} whoami", channel: 'channel', user: 'user')) + message_hook.call(client, Hashie::Mash.new(team: team, text: "whoami", channel: 'channel', user: 'user')) end end end