Skip to content

Commit

Permalink
Use described_class
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Apr 30, 2023
1 parent 3585768 commit 6f4719a
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions spec/cli_spec.rb
Expand Up @@ -10,7 +10,7 @@

before do
T::RCFile.instance.path = "#{fixture_path}/.trc"
@cli = T::CLI.new
@cli = described_class.new
@cli.options = @cli.options.merge('color' => 'always')
@old_stderr = $stderr
$stderr = StringIO.new
Expand Down Expand Up @@ -4699,7 +4699,7 @@
context 'no configuration' do
it 'prints a helpful message and no errors' do
T::RCFile.instance.path = ''
@cli = T::CLI.new
@cli = described_class.new
@cli.whoami
expect($stderr.string).to eq "You haven't authorized an account, run `t authorize` to get started.\n"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/delete_spec.rb
Expand Up @@ -5,7 +5,7 @@
describe T::Delete do
before do
T::RCFile.instance.path = "#{fixture_path}/.trc"
@delete = T::Delete.new
@delete = described_class.new
@old_stderr = $stderr
$stderr = StringIO.new
@old_stdout = $stdout
Expand Down
20 changes: 10 additions & 10 deletions spec/editor_spec.rb
Expand Up @@ -5,13 +5,13 @@
describe T::Editor do
context 'when editing a file' do
before do
allow(T::Editor).to receive(:edit) do |path|
allow(described_class).to receive(:edit) do |path|
File.binwrite(path, 'A tweet!!!!')
end
end

it 'fetches your tweet content without comments' do
expect(T::Editor.gets).to eq('A tweet!!!!')
expect(described_class.gets).to eq('A tweet!!!!')
end
end

Expand All @@ -24,21 +24,21 @@
context 'host_os is Mac OSX' do
it 'returns the system editor' do
RbConfig::CONFIG['host_os'] = 'darwin12.2.0'
expect(T::Editor.editor).to eq('vi')
expect(described_class.editor).to eq('vi')
end
end

context 'host_os is Linux' do
it 'returns the system editor' do
RbConfig::CONFIG['host_os'] = '3.2.0-4-amd64'
expect(T::Editor.editor).to eq('vi')
expect(described_class.editor).to eq('vi')
end
end

context 'host_os is Windows' do
it 'returns the system editor' do
RbConfig::CONFIG['host_os'] = 'mswin'
expect(T::Editor.editor).to eq('notepad')
expect(described_class.editor).to eq('notepad')
end
end
end
Expand All @@ -50,7 +50,7 @@
end

it 'returns the system editor' do
expect(T::Editor.editor).to eq('/my/vim/install')
expect(described_class.editor).to eq('/my/vim/install')
end
end

Expand All @@ -61,7 +61,7 @@
end

it 'returns the system editor' do
expect(T::Editor.editor).to eq('/usr/bin/subl')
expect(described_class.editor).to eq('/usr/bin/subl')
end
end

Expand All @@ -72,7 +72,7 @@
end

it 'returns the system editor' do
expect(T::Editor.editor).to eq('/usr/bin/emacs')
expect(described_class.editor).to eq('/usr/bin/emacs')
end
end
end
Expand All @@ -84,7 +84,7 @@
end

it "returns 'vi' on a unix machine" do
expect(T::Editor.system_editor).to eq('vi')
expect(described_class.system_editor).to eq('vi')
end
end

Expand All @@ -94,7 +94,7 @@
end

it "returns 'notepad' on a windows box" do
expect(T::Editor.system_editor).to eq('notepad')
expect(described_class.system_editor).to eq('notepad')
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/list_spec.rb
Expand Up @@ -10,7 +10,7 @@

before do
T::RCFile.instance.path = "#{fixture_path}/.trc"
@list = T::List.new
@list = described_class.new
@old_stderr = $stderr
$stderr = StringIO.new
@old_stdout = $stdout
Expand Down
46 changes: 23 additions & 23 deletions spec/rcfile_spec.rb
Expand Up @@ -4,28 +4,28 @@

describe T::RCFile do
after do
T::RCFile.instance.reset
described_class.instance.reset
FileUtils.rm_f("#{project_path}/tmp/trc")
end

it 'is a singleton' do
expect(T::RCFile).to be_a Class
expect(described_class).to be_a Class
expect do
T::RCFile.new
described_class.new
end.to raise_error(NoMethodError, /private method `new' called/)
end

describe '#[]' do
it 'returns the profiles for a user' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{fixture_path}/.trc"
expect(rcfile['testcli'].keys).to eq %w[abc123]
end
end

describe '#[]=' do
it 'adds a profile for a user' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{project_path}/tmp/trc"
rcfile['testcli'] = {
'abc123' => {
Expand All @@ -40,7 +40,7 @@
end

it 'is not be world writable' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{project_path}/tmp/trc"
rcfile['testcli'] = {
'abc123' => {
Expand All @@ -55,7 +55,7 @@
end

it 'is not be world readable' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{project_path}/tmp/trc"
rcfile['testcli'] = {
'abc123' => {
Expand All @@ -72,39 +72,39 @@

describe '#configuration' do
it 'returns configuration' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{fixture_path}/.trc"
expect(rcfile.configuration.keys).to eq %w[default_profile]
end
end

describe '#active_consumer_key' do
it 'returns default consumer key' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{fixture_path}/.trc"
expect(rcfile.active_consumer_key).to eq 'abc123'
end
end

describe '#active_consumer_secret' do
it 'returns default consumer secret' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{fixture_path}/.trc"
expect(rcfile.active_consumer_secret).to eq 'asdfasd223sd2'
end
end

describe '#active_profile' do
it 'returns default profile' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{fixture_path}/.trc"
expect(rcfile.active_profile).to eq %w[testcli abc123]
end
end

describe '#active_profile=' do
it 'sets default profile' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{project_path}/tmp/trc"
rcfile.active_profile = {'username' => 'testcli', 'consumer_key' => 'abc123'}
expect(rcfile.active_profile).to eq %w[testcli abc123]
Expand All @@ -113,15 +113,15 @@

describe '#active_token' do
it 'returns default token' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{fixture_path}/.trc"
expect(rcfile.active_token).to eq '428004849-cebdct6bwobn'
end
end

describe '#active_secret' do
it 'returns default secret' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{fixture_path}/.trc"
expect(rcfile.active_secret).to eq 'epzrjvxtumoc'
end
Expand All @@ -132,7 +132,7 @@
path = "#{project_path}/tmp/trc"
File.write(path, YAML.dump({}))
expect(File.exist?(path)).to be true
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = path
rcfile.delete
expect(File.exist?(path)).to be false
Expand All @@ -142,15 +142,15 @@
describe '#empty?' do
context 'when a non-empty file exists' do
it 'returns false' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{fixture_path}/.trc"
expect(rcfile.empty?).to be false
end
end

context 'when file does not exist at path' do
it 'returns true' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = File.expand_path('fixtures/foo', __dir__)
expect(rcfile.empty?).to be true
end
Expand All @@ -160,15 +160,15 @@
describe '#load_file' do
context 'when file exists at path' do
it 'loads data from file' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{fixture_path}/.trc"
expect(rcfile.load_file['profiles']['testcli']['abc123']['username']).to eq 'testcli'
end
end

context 'when file does not exist at path' do
it 'loads default structure' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = File.expand_path('fixtures/foo', __dir__)
expect(rcfile.load_file.keys.sort).to eq %w[configuration profiles]
end
Expand All @@ -177,27 +177,27 @@

describe '#path' do
it 'defaults to ~/.trc' do
expect(T::RCFile.instance.path).to eq File.join(File.expand_path('~'), '.trc')
expect(described_class.instance.path).to eq File.join(File.expand_path('~'), '.trc')
end
end

describe '#path=' do
it 'overrides path' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{project_path}/tmp/trc"
expect(rcfile.path).to eq "#{project_path}/tmp/trc"
end

it 'reloads data' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{fixture_path}/.trc"
expect(rcfile['testcli']['abc123']['username']).to eq 'testcli'
end
end

describe '#profiles' do
it 'returns profiles' do
rcfile = T::RCFile.instance
rcfile = described_class.instance
rcfile.path = "#{fixture_path}/.trc"
expect(rcfile.profiles.keys).to eq %w[testcli]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/search_spec.rb
Expand Up @@ -10,7 +10,7 @@

before do
T::RCFile.instance.path = "#{fixture_path}/.trc"
@search = T::Search.new
@search = described_class.new
@search.options = @search.options.merge('color' => 'always')
@old_stderr = $stderr
$stderr = StringIO.new
Expand Down
2 changes: 1 addition & 1 deletion spec/set_spec.rb
Expand Up @@ -5,7 +5,7 @@
describe T::Set do
before do
T::RCFile.instance.path = "#{fixture_path}/.trc"
@set = T::Set.new
@set = described_class.new
@old_stderr = $stderr
$stderr = StringIO.new
@old_stdout = $stdout
Expand Down
2 changes: 1 addition & 1 deletion spec/stream_spec.rb
Expand Up @@ -15,7 +15,7 @@
before do
T::RCFile.instance.path = "#{fixture_path}/.trc"
@streaming_client = double('Twitter::Streaming::Client').as_null_object
@stream = T::Stream.new
@stream = described_class.new
allow(@stream).to receive(:streaming_client) { @streaming_client }
allow(@stream).to receive(:say)
allow(STDOUT).to receive(:tty?).and_return(true)
Expand Down
2 changes: 1 addition & 1 deletion spec/utils_spec.rb
Expand Up @@ -12,7 +12,7 @@ class Test; end

before do
@test = Test.new
@test.extend(T::Utils)
@test.extend(described_class)
end

after :all do
Expand Down

0 comments on commit 6f4719a

Please sign in to comment.