diff --git a/lib/bogus/rspec/syntax.rb b/lib/bogus/rspec/syntax.rb index 0d01cb5..56726a7 100644 --- a/lib/bogus/rspec/syntax.rb +++ b/lib/bogus/rspec/syntax.rb @@ -8,6 +8,9 @@ class RSpecSyntax def_delegators :context, :before, :after, :described_class def described_class=(value) + # for new RSpec (> 3.0) + context.metadata[:described_class] = value + # for old RSpec (< 3.0) context.example.metadata[:example_group][:described_class] = value end diff --git a/spec/bogus/rspec/syntax_spec.rb b/spec/bogus/rspec/syntax_spec.rb new file mode 100644 index 0000000..a82dbbe --- /dev/null +++ b/spec/bogus/rspec/syntax_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe Bogus::RSpecSyntax do + context = self + let(:syntax) { Bogus::RSpecSyntax.new(context) } + + it "gets the described class" do + expect(syntax.described_class).to eq(Bogus::RSpecSyntax) + end + + it "can set the described class" do + syntax.described_class = Object + + expect(described_class).to eq(Object) + end +end