tools

various tools I have been using throughout the years
Log | Files | Refs | README | LICENSE

command_spec.rb (1000B)


      1 # frozen_string_literal: true
      2 
      3 require 'spec_helper'
      4 
      5 describe Hue::CLI::Command do
      6   before do
      7     mock_application_config_path
      8     mock_bridge_config_path
      9     allow(Hue::CLI).to receive(:bridge).and_return(test_bridge)
     10   end
     11 
     12   let(:subclass) do
     13     Class.new(described_class) do
     14       def self.name
     15         'Hue::CLI::Commands::Test'
     16       end
     17 
     18       def hello(*_args)
     19         :hi
     20       end
     21     end
     22   end
     23 
     24   it 'exposes the configured bridge' do
     25     expect(described_class.new.bridge).to be_a(Hue::Bridge)
     26   end
     27 
     28   it 'dispatches to a defined method' do
     29     expect(subclass.new.send(:send_method, 'hello')).to eq(:hi)
     30   end
     31 
     32   it 'raises Hue::CLI::Error for an unavailable method' do
     33     expect { subclass.new.send(:send_method, 'nope') }
     34       .to raise_error(Hue::CLI::Error, /not available/)
     35   end
     36 
     37   it 'falls back to bridge.print_state when execute called with no args' do
     38     instance = described_class.new
     39     expect(instance.bridge).to receive(:print_state)
     40     instance.execute
     41   end
     42 end