TDDing tmux

TDDing tmux

502828deee7e3b38ca1e527dded8a1a9?s=128

Seth Vargo

April 04, 2013
Tweet

Transcript

  1. 2.
  2. 4.
  3. 6.

    How to apply the testing cookbooks to chef know in

    Ruby stuff you already because Chef is just Ruby and you already know Ruby, so strap in
  4. 9.
  5. 14.

    source 'https://rubygems.org' gem 'chef' gem 'chefspec' gem 'fauxhai' gem 'foodcritic'

    gem 'strainer' # Guard gem 'guard' gem 'guard-bundler' gem 'guard-rspec' gem 'rb-fsevent' gem 'terminal-notifier-guard' Gemfile
  6. 15.
  7. 16.
  8. 17.
  9. 19.
  10. 20.
  11. 23.

    $ knife cookbook create tmux ** Creating cookbook tmux **

    Creating README for cookbook: tmux ** Creating CHANGELOG for cookbook: tmux ** Creating metadata for cookbook: tmux
  12. 24.
  13. 25.
  14. 26.
  15. 32.

    require 'spec_helper' describe 'tmux::default' do let(:runner) { ChefSpec::ChefRunner.new.converge('tmux::default') } it

    'installs the tmux package' do expect(runner).to install_package('tmux') end end spec/default_spec.rb
  16. 33.

    require 'spec_helper' describe 'tmux::default' do let(:runner) { ChefSpec::ChefRunner.new.converge('tmux::default') } it

    'installs the tmux package' do expect(runner).to install_package('tmux') end it 'creates the tmux.conf file' do expect(runner).to create_file('/etc/tmux.conf') end end spec/default_spec.rb
  17. 34.
  18. 35.
  19. 40.

    $ rspec cookbooks/tmux/spec/default_spec.rb Failures: 1) tmux::default should install the tmux

    package Failure/Error: let(:runner) { ChefSpec::ChefRunner.new.converge('tmux::default') } TypeError: can't convert Symbol into Integer # ./cookbooks/bluepill/attributes/default.rb: 18:in `[]' # ./cookbooks/bluepill/attributes/default.rb: 18:in `from_file' # ./cookbooks/tmux/spec/default_spec.rb:4:in `block (2 levels) in <top (required)>' # ./cookbooks/tmux/spec/default_spec.rb:7:in `block (2 levels) in <top (required)>' 2) tmux::default should create the tmux.conf file Failure/Error: let(:runner) { ChefSpec::ChefRunner.new.converge('tmux::default') }
  20. 41.
  21. 42.

    require 'spec_helper' describe 'tmux::default' do before { Fauxhai.mock(platform: 'ubuntu', version:

    '12.04') } let(:runner) { ChefSpec::ChefRunner.new.converge('tmux::default') } end Before
  22. 44.

    require 'spec_helper' describe 'tmux::default' do let(:runner) { ChefSpec::ChefRunner.new( platform: 'ubuntu',

    version: '12.04' ).converge('tmux::default') } it 'installs the tmux package' do expect(runner).to install_package('tmux') end it 'creates the tmux.conf file' do expect(runner).to create_file('/etc/tmux.conf') end end After
  23. 46.

    $ rspec cookbooks/tmux/spec/default_spec.rb Failures: 1) tmux::default should install the tmux

    package Failure/Error: runner.should install_package 'tmux' No package resource named 'tmux' with action :install found. # ./cookbooks/tmux/spec/default_spec.rb:8:in `block (2 levels) in <top (required)>' 2) tmux::default should create the tmux.conf file Failure/Error: runner.should create_file('/etc/ tmux.conf') No file resource named '/etc/tmux.conf' with action :create found. # ./cookbooks/tmux/spec/default_spec.rb:12:in `block (2 levels) in <top (required)>' Finished in 0.14994 seconds 2 examples, 2 failures
  24. 53.

    guard 'rspec', spec_paths: ['spec', 'cookbooks/*/spec'] do watch(%r{^spec/.+_spec\.rb$}) watch('spec/spec_helper.rb') { 'spec'

    } watch(%r{^cookbooks/(.+)/recipes/(.+)\.rb$}) do |m| "cookbooks/#{m[1]}/spec/#{m[2]}_spec.rb" end end Guardfile
  25. 54.

    guard 'rspec', spec_paths: ['spec', 'cookbooks/*/spec'] do watch(%r{^spec/.+_spec\.rb$}) watch('spec/spec_helper.rb') { 'spec'

    } watch(%r{^cookbooks/(.+)/recipes/(.+)\.rb$}) do |m| "cookbooks/#{m[1]}/spec/#{m[2]}_spec.rb" end watch(%r{^cookbooks/([A-Za-z]+)/(.+)(\..*)?$}) do |m| "cookbooks/#{m[1]}/spec/*.rb" end end Guardfile
  26. 55.
  27. 56.

    $ guard Guard is now watching at '[...]/chef-repo' Guard::RSpec is

    running Running all specs Failures: 1) tmux::default should install the tmux package Failure/Error: runner.should install_package 'tmux' No package resource named 'tmux' with action :install found. # ./cookbooks/tmux/spec/default_spec.rb:8:in `block (2 levels) in <top (required)>' 2) tmux::default should create the tmux.conf file Failure/Error: runner.should create_file('/etc/ tmux.conf') No file resource named '/etc/tmux.conf' with action :create found. # ./cookbooks/tmux/spec/default_spec.rb:12:in `block (2 levels) in <top (required)>'
  28. 58.

    # Install the tmux package package 'tmux' # Drop the

    tmux configuration template template '/etc/tmux.conf' do source 'tmux.conf.erb' mode '0644' end recipes/default.rb
  29. 59.

    $ guard Guard is now watching at '[...]/chef-repo' Guard::RSpec is

    running Running all specs ** Finished in 0.0003 seconds 2 examples, 0 failures
  30. 60.
  31. 61.

    require 'spec_helper' describe 'tmux::default' do let(:runner) { ChefSpec::ChefRunner.new.converge('tmux::default') } it

    'installs the tmux package' do expect(runner).to install_package('tmux') end it 'creates the tmux.conf file' do expect(runner).to create_file('/etc/tmux.conf') end end spec/default_spec.rb
  32. 62.

    require 'spec_helper' describe 'tmux::default' do let(:runner) { ChefSpec::ChefRunner.new.converge('tmux::default') } it

    'installs the tmux package' do expect(runner).to install_package('tmux') end it 'creates the tmux.conf file' do expect(runner).to create_file('/etc/tmux.conf'). with_content('set -g prefix C-a') end end spec/default_spec.rb
  33. 63.

    $ guard Guard is now watching at '[...]/chef-repo' Guard::RSpec is

    running Running all specs *F Failures: 1) tmux::default should create the tmux.conf file Failure/Error: runner.should create_file('/etc/ tmux.conf') No source template named 'tmux.conf.erb' found in the default locations. # ./cookbooks/tmux/spec/default_spec.rb:12:in `block (2 levels) in <top (required)>' Finished in 0.15691 seconds 2 examples, 1 passed, 1 failures
  34. 64.

    # Use a better prefix: set -g prefix C-a unbind

    C-b # Change the default delay: set -sg escape-time 1 # Set the window and panes index set -g base-index 1 setw -g pane-base-index 1 # Send prefix to other apps: bind C-a send-prefix # Split windows with more logical keys bind | split-window -h bind - split-window -v # Remap movement keys bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R templates/default/tmux.conf.erb
  35. 65.

    $ guard Guard is now watching at '[...]/chef-repo' Guard::RSpec is

    running Running all specs ** Finished in 0.0003 seconds 2 examples, 0 failures
  36. 70.

    $ foodcritic -I my-rules/* cookbooks/tmux FC045: Consider setting cookbook name

    in metadata: cookbooks/tmux/metadata.rb:1 $ echo $? 0
  37. 71.

    $ foodcritic -I my-rules/* -f any cookbooks/tmux FC045: Consider setting

    cookbook name in metadata: cookbooks/tmux/metadata.rb:1 $ echo $? 3
  38. 74.

    $ knife cookbook test tmux checking tmux Running syntax check

    on tmux Validating ruby files Validating templates
  39. 78.

    knife: knife cookbook test $COOKBOOK foodcritic: foodcritic -f any $SANDBOX/$COOKBOOK

    chefspec: bundle exec rspec $SANDBOX/$COOKBOOK Strainerfile
  40. 79.

    $ strainer test tmux # Straining 'tmux (v0.0.1)' knife |

    knife cookbook test tmux knife | checking tmux knife | Running syntax check on tmux knife | Validating ruby files knife | Validating templates knife | SUCCESS! foodcritic | foodcritic -f any /Users/ sethvargo/Development/chef-is/cookbooks/tmux foodcritic | SUCCESS! chefspec | bundle exec rspec /Users/ sethvargo/Development/chef-is/cookbooks/tmux chefspec | No examples found. chefspec | Finished in 0.00006 seconds chefspec | 0 examples, 0 failures chefspec | SUCCESS!
  41. 80.
  42. 81.

    #!/bin/bash set -e set +x git submodule update --init 2>&1

    > /dev/null bundle install --quiet rm -Rf .colander strainer test `echo $JOB_NAME | sed 's/_cookbook//'` script/ci
  43. 82.