Last active
August 18, 2020 23:25
-
-
Save sephraim/f45b44dcd74a407b01b96d2139d96011 to your computer and use it in GitHub Desktop.
[Test a Ruby module] #rspec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Related: https://www.rubydoc.info/gems/rubocop-rspec/1.6.0/RuboCop/Cop/RSpec/AnyInstance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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