Skip to content

Instantly share code, notes, and snippets.

@sephraim
Last active August 18, 2020 23:25
Show Gist options
  • Select an option

  • Save sephraim/f45b44dcd74a407b01b96d2139d96011 to your computer and use it in GitHub Desktop.

Select an option

Save sephraim/f45b44dcd74a407b01b96d2139d96011 to your computer and use it in GitHub Desktop.
[Test a Ruby module] #rspec
Related: https://www.rubydoc.info/gems/rubocop-rspec/1.6.0/RuboCop/Cop/RSpec/AnyInstance
module Some
module Module
def module_method
"I'm a module method!"
end
class << self
def class_method
"I'm a class method!"
end
end
end
end
include 'spec_helper'
include 'some_module'
describe Some::Module do
include described_class # Allow module methods to be tested
let(:klass) do
Class.new do
include described_class # Allow class methods to be tested
end
end
describe '.module_method' do
it 'prints something' do
expect(module_method).to eql("I'm a module method!")
end
end
describe '.class_method' do
it 'prints something' do
expect(klass.new.class_method).to eql("I'm a class method!")
end
# This *might* also work
it 'prints something' do
expect(described_class.class_method).to eql("I'm a class method!")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment