Skip to content

Commit

Permalink
Fix rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline committed Oct 17, 2015
1 parent 0fee333 commit 5426911
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 45 deletions.
21 changes: 21 additions & 0 deletions .rubocop.yml
Expand Up @@ -11,3 +11,24 @@ Style/StringLiterals:
SupportedStyles:
- single_quotes
- double_quotes

Style/RegexpLiteral:
Enabled: false

Metrics/ModuleLength:
Enabled: false

Lint/NestedMethodDefinition:
Enabled: false

Style/SpaceAroundOperators:
Enabled: false

Style/ClosingParenthesisIndentation:
Enabled: false

Style/ParallelAssignment:
Enabled: false

Style/RescueModifier:
Enabled: false
5 changes: 0 additions & 5 deletions .rubocop_todo.yml
Expand Up @@ -98,11 +98,6 @@ Style/AlignParameters:
Style/AndOr:
Enabled: false

# Offense count: 18
# Cop supports --auto-correct.
Style/Blocks:
Enabled: false

# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -14,6 +14,6 @@ matrix:
# http://blog.travis-ci.com/2014-12-17-faster-builds-with-container-based-infrastructure/
sudo: false

# script:
# - bundle exec rspec
# - bundle exec rubocop
script:
- bundle exec rspec
- bundle exec rubocop -D
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -2,4 +2,4 @@ source 'https://rubygems.org'

gemspec

gem 'coveralls', require: false
gem 'coveralls', :require => false
2 changes: 1 addition & 1 deletion gmail.gemspec
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |s|
# development dependencies
s.add_development_dependency "rake"
s.add_development_dependency "rspec", ">= 3.1"
s.add_development_dependency "rubocop"
s.add_development_dependency "rubocop", ">= 0.34.2"
s.add_development_dependency "gem-release"

s.files = `git ls-files`.split("\n")
Expand Down
12 changes: 6 additions & 6 deletions lib/gmail/mailbox.rb
Expand Up @@ -46,9 +46,9 @@ def fetch_uids(*args)
opts[:gm] and search.concat ['X-GM-RAW', opts[:gm]]
opts[:query] and search.concat opts[:query]

@gmail.mailbox(name) {
@gmail.mailbox(name) do
@gmail.conn.uid_search(search)
}
end
elsif args.first.is_a?(Hash)
fetch_uids(:all, args.first)
else
Expand Down Expand Up @@ -133,14 +133,14 @@ def wait_once(options = {})
complete_now = false

@gmail.conn.idle do |resp|
if resp.kind_of?(Net::IMAP::ContinuationRequest) && resp.data.text == 'idling'
if resp.is_a?(Net::IMAP::ContinuationRequest) && resp.data.text == 'idling'
Thread.new do
@gmail.conn.synchronize do
complete_cond.wait(options[:idle_timeout]) unless complete_now
@gmail.conn.idle_done
end
end
elsif resp.kind_of?(Net::IMAP::UntaggedResponse) && resp.name == 'EXISTS'
elsif resp.is_a?(Net::IMAP::UntaggedResponse) && resp.name == 'EXISTS'
response = resp

@gmail.conn.synchronize do
Expand All @@ -166,10 +166,10 @@ def to_s
name
end

MAILBOX_ALIASES.each_key { |mailbox|
MAILBOX_ALIASES.each_key do |mailbox|
define_method(mailbox) do |*args, &block|
emails(mailbox, *args, &block)
end
}
end
end # Message
end # Gmail
2 changes: 1 addition & 1 deletion lib/gmail/message.rb
Expand Up @@ -8,7 +8,7 @@ class NoLabelError < Exception; end
def initialize(mailbox, uid, _attrs = nil)
@uid = uid
@mailbox = mailbox
@gmail = mailbox.instance_variable_get("@gmail") if mailbox # UGLY
@gmail = mailbox.instance_variable_get("@gmail") if mailbox # UGLY
@_attrs = _attrs
end

Expand Down
20 changes: 10 additions & 10 deletions spec/gmail/client/plain_spec.rb
Expand Up @@ -32,19 +32,19 @@
end

it "raises error when given Gmail account is invalid and errors enabled" do
expect {
expect do
client = Gmail::Client::Plain.new("foo", "bar")
expect(client.connect).to be_truthy
expect(client.login!).not_to be_nil
}.to raise_error
end.to raise_error
end

it "does not raise error even though Gmail account is invalid" do
expect {
expect do
client = Gmail::Client::Plain.new("foo", "bar")
expect(client.connect).to be_truthy
expect(client.login).to_not be_truthy
}.not_to raise_error
end.not_to raise_error
end

it "does not log in when given Gmail account is invalid" do
Expand Down Expand Up @@ -101,17 +101,17 @@
end

it "does not raise error when mail can't be delivered and errors are disabled" do
expect {
expect do
client = mock_client
expect(client.deliver(Mail.new {})).to be false
}.not_to raise_error
end.not_to raise_error
end

it "raises error when mail can't be delivered and errors are disabled" do
expect {
expect do
client = mock_client
client.deliver!(Mail.new {})
}.to raise_error(Gmail::Client::DeliveryError)
end.to raise_error(Gmail::Client::DeliveryError)
end

it "properly switches to given mailbox" do
Expand All @@ -132,11 +132,11 @@
end

context "labels" do
subject {
subject do
client = Gmail::Client::Plain.new(*TEST_ACCOUNT)
client.connect
client.labels
}
end

it "returns list of all available labels" do
labels = subject
Expand Down
24 changes: 12 additions & 12 deletions spec/gmail/client/xoauth2_spec.rb
Expand Up @@ -31,10 +31,10 @@ def mock_client(&block)
end

it "connects to Gmail IMAP service" do
expect(-> {
expect(-> do
client = mock_client
expect(client.connect!).to be_truthy
}).to_not raise_error
end).to_not raise_error
end

it "properly logs in to valid Gmail account" do
Expand All @@ -47,19 +47,19 @@ def mock_client(&block)
end

it "raises error when given Gmail account is invalid and errors enabled" do
expect(-> {
expect(-> do
client = Gmail::Client::XOAuth2.new("foo", { :token => "bar" })
expect(client.connect).to be_truthy
expect(client.login!).not_to be_truthy
}).to raise_error(Gmail::Client::AuthorizationError)
end).to raise_error(Gmail::Client::AuthorizationError)
end

it "does not log in when given Gmail account is invalid" do
expect(-> {
expect(-> do
client = Gmail::Client::XOAuth2.new("foo", { :token => "bar" })
expect(client.connect).to be_truthy
expect(client.login).not_to be_truthy
}).to_not raise_error
end).to_not raise_error
end

it "properly logs out from Gmail" do
Expand Down Expand Up @@ -112,17 +112,17 @@ def mock_client(&block)
end

it "does not raise error when mail can't be delivered and errors are disabled" do
expect(-> {
expect(-> do
client = mock_client
expect(client.deliver(Mail.new {})).to be_falsey
}).to_not raise_error
end).to_not raise_error
end

it "raises error when mail can't be delivered and errors are disabled" do
expect(-> {
expect(-> do
client = mock_client
client.deliver!(Mail.new {})
}).to raise_error(Gmail::Client::DeliveryError)
end).to raise_error(Gmail::Client::DeliveryError)
end

it "properly switches to given mailbox" do
Expand All @@ -145,11 +145,11 @@ def mock_client(&block)
end

context "labels" do
subject {
subject do
client = Gmail::Client::XOAuth2.new(*TEST_ACCOUNT)
client.connect
client.labels
}
end

it "returns list of all available labels" do
pending
Expand Down
2 changes: 1 addition & 1 deletion spec/gmail/mailbox_spec.rb
Expand Up @@ -68,7 +68,7 @@
expect(client.conn).to receive(:idle).and_call_original.at_least(:twice)

mailbox = client.inbox
mailbox.wait_once(idle_timeout: 0.001)
mailbox.wait_once(:idle_timeout => 0.001)
end

it "performs full text search of message bodies" do
Expand Down
8 changes: 4 additions & 4 deletions spec/gmail_spec.rb
Expand Up @@ -23,17 +23,17 @@
end

it "#new does not raise error when couldn't connect with given account" do
expect {
expect do
gmail = Gmail.new("foo", "bar")
expect(gmail).not_to be_logged_in
}.not_to raise_error
end.not_to raise_error
end

it "#new! raises error when couldn't connect with given account" do
expect {
expect do
gmail = Gmail.new!("foo", "bar")
expect(gmail).not_to be_logged_in
}.to raise_error
end.to raise_error
### FIX: can someone dig to the bottom of this? We are getting NoMethodError instead of Gmail::Client::AuthorizationError in 1.9
end
end
2 changes: 1 addition & 1 deletion spec/support/imap_mock.rb
Expand Up @@ -133,7 +133,7 @@ def mock_command(method, cmd, *args, &block)
# @responses (the third argument here) contains untagged responses captured
# via the Net::IMAP#record_response method.
Net::IMAP.recordings[digest] ||= []
Net::IMAP.recordings[digest] << [action, response.dup, @responses ? @responses.dup : nil, all_responses]
Net::IMAP.recordings[digest] << [action, response.dup, @responses ? @responses.dup : nil, all_responses]
end

raise(response) if action == :raise
Expand Down

0 comments on commit 5426911

Please sign in to comment.