Skip to content

Instantly share code, notes, and snippets.

@jfredett
Last active December 14, 2015 13:19
Show Gist options
  • Save jfredett/5092389 to your computer and use it in GitHub Desktop.
Save jfredett/5092389 to your computer and use it in GitHub Desktop.
#command_factory_spec.rb:
require 'spec_helper'
describe CommandFactory do
let(:factory) { CommandFactory.new nil }
subject { factory.command(:foo) }
context 'a thing' do
it_behaves_like "a command"
end
end
# shared_examples_for_commands.rb:
shared_examples "a command" do
# your way (fixed)
#it "should respond to execute" do
# subject.should respond_to(:execute)
#end
#better way
it { should respond_to :execute }
# similar
#it "should respond to unexecute" do
# subject.should respond_to(:unexecute)
#end
# better
it { should respond_to :unexecute }
end
@expez
Copy link

expez commented Mar 5, 2013

When I run this I get:

CommandFactory
behaves like a command
should respond to #execute
should respond to #unexecute

The idea of the it block so I could get:

CommandFactory
Creates commands which:
behaves like a command
should respond to #execute
should respond to #unexecute

@expez
Copy link

expez commented Mar 5, 2013

context "Creates commands which:" do
    subject {  factory.command(:foo) }
    it_behaves_like "a command"
end
CommandFactory
  Creates commands which:
    behaves like a command
      should respond to #execute
      should respond to #unexecute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment