Skip to content

Conversation

@Daniel-Worrall
Copy link
Member

Summary

Aims to begin to improve upon and homogenise the style of rspec tests by adding rubocop rules

There are some TODO actions that require more thought to iterate on than in this PR

There is also room to discuss rules to configure. This PR is an entry into that discussion as it demonstrates the required changes needed to abide by the rules.

There are some rubocops that will fail in CI which are fixed in another PR

Added

  • rspec rubocop gem

Fixed

  • a couple tests that were testing incorrectly and some broken code would have also allowed them to pass

@Daniel-Worrall Daniel-Worrall requested a review from Copilot June 3, 2025 22:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the style and consistency of the test suite while updating several instances of test doubles to use stricter instance doubles, and it adds additional RuboCop configuration for RSpec. It also includes minor functional improvements such as aliasing methods in event classes and updates to documentation and gemspec dependencies.

  • Updated test doubles to use instance_double for stronger type checking.
  • Renamed spec descriptions and commands for better clarity.
  • Added new RuboCop configurations for RSpec and made minor refactoring in library files.

Reviewed Changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 3 comments.

File Description
spec/**/*.rb Updated tests to use instance_double and refactored spec names and expectations for clarity
lib/discordrb/permissions.rb Simplified bitwise check in defined_permissions
lib/discordrb/events/* Introduced alias_method :matching? to simplify event matching logic
discordrb.gemspec & .rubocop.yml Added rubocop-rspec dependency and updated RuboCop configuration for RSpec

].freeze

# TODO: Rework tests
# rubocop:disable RSpec/MultipleExpectations
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider refactoring these tests to reduce the number of multiple expectations per test case. This would improve test clarity and maintainability over time.

Suggested change
# rubocop:disable RSpec/MultipleExpectations

Copilot uses AI. Check for mistakes.
expect { described_class.new(token: nil) }.to raise_error('Token string is empty or nil')
shared_examples 'raises when token string is' do |token, value|
it "raises when token string is #{token}" do
expect { described_class.new(token: value) }.to raise_error('Token string is empty or nil')
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] To improve maintainability, consider extracting the error message ('Token string is empty or nil') to a constant so that tests remain in sync if the error message changes in the future.

Suggested change
expect { described_class.new(token: value) }.to raise_error('Token string is empty or nil')
expect { described_class.new(token: value) }.to raise_error(TOKEN_ERROR_MESSAGE)

Copilot uses AI. Check for mistakes.
end

# TODO: Rework tests to not rely on multiple expectations
# rubocop:disable RSpec/MultipleExpectations
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Review and refactor tests that require disabling the 'RSpec/MultipleExpectations' cop to reduce complexity and improve overall test quality.

Copilot uses AI. Check for mistakes.
@Daniel-Worrall Daniel-Worrall requested a review from swarley June 8, 2025 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant