From 14d77bf9740364097624f8a6d5416617cd712f63 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Wed, 26 Jan 2011 20:11:56 -0600 Subject: [PATCH] move 'its' specs to subject_spec and reorg a bit --- spec/rspec/core/example_group_spec.rb | 77 ------------------------- spec/rspec/core/subject_spec.rb | 81 +++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 77 deletions(-) diff --git a/spec/rspec/core/example_group_spec.rb b/spec/rspec/core/example_group_spec.rb index 55ee7d7b68..84de9a2458 100644 --- a/spec/rspec/core/example_group_spec.rb +++ b/spec/rspec/core/example_group_spec.rb @@ -635,83 +635,6 @@ module RSpec::Core end end - describe "#its" do - subject do - Class.new do - def initialize - @call_count = 0 - end - def attribute_call_count - @call_count += 1 - end - end.new - end - - its(:attribute_call_count) { should eq(1) } - - context "with nil value" do - subject do - Class.new do - def nil_value - nil - end - end.new - end - its(:nil_value) { should be_nil } - end - - context "with nested attributes" do - subject do - Class.new do - def name - "John" - end - end.new - end - its("name.size") { should == 4 } - its("name.size.class") { should == Fixnum } - end - - context "when it is a Hash" do - subject do - { :attribute => 'value', - 'another_attribute' => 'another_value' } - end - its([:attribute]) { should == 'value' } - its([:attribute]) { should_not == 'another_value' } - its([:another_attribute]) { should == 'another_value' } - its([:another_attribute]) { should_not == 'value' } - its(:keys) { should =~ ['another_attribute', :attribute] } - context "when referring to an attribute without the proper array syntax" do - context "it raises an error" do - its(:attribute) do - expect do - should eq('value') - end.to raise_error(NoMethodError) - end - end - end - end - - context "calling and overriding super" do - it "calls to the subject defined in the parent group" do - group = ExampleGroup.describe(Array) do - subject { [1, 'a'] } - - its(:last) { should == 'a' } - - describe '.first' do - def subject; super().first; end - - its(:next) { should == 2 } - end - end - - group.run.should be_true - end - end - - end describe "#top_level_description" do it "returns the description from the outermost example group" do diff --git a/spec/rspec/core/subject_spec.rb b/spec/rspec/core/subject_spec.rb index b63972375f..5394dbd905 100644 --- a/spec/rspec/core/subject_spec.rb +++ b/spec/rspec/core/subject_spec.rb @@ -93,5 +93,86 @@ def ok?; true; end end end + describe "#its" do + subject do + Class.new do + def initialize + @call_count = 0 + end + + def call_count + @call_count += 1 + end + end.new + end + + context "with a call counter" do + its(:call_count) { should eq(1) } + end + + context "with nil value" do + subject do + Class.new do + def nil_value + nil + end + end.new + end + its(:nil_value) { should be_nil } + end + + context "with nested attributes" do + subject do + Class.new do + def name + "John" + end + end.new + end + its("name") { should eq("John") } + its("name.size") { should eq(4) } + its("name.size.class") { should eq(Fixnum) } + end + + context "when it is a Hash" do + subject do + { :attribute => 'value', + 'another_attribute' => 'another_value' } + end + its([:attribute]) { should == 'value' } + its([:attribute]) { should_not == 'another_value' } + its([:another_attribute]) { should == 'another_value' } + its([:another_attribute]) { should_not == 'value' } + its(:keys) { should =~ ['another_attribute', :attribute] } + context "when referring to an attribute without the proper array syntax" do + context "it raises an error" do + its(:attribute) do + expect do + should eq('value') + end.to raise_error(NoMethodError) + end + end + end + end + + context "calling and overriding super" do + it "calls to the subject defined in the parent group" do + group = ExampleGroup.describe(Array) do + subject { [1, 'a'] } + + its(:last) { should == 'a' } + + describe '.first' do + def subject; super().first; end + + its(:next) { should == 2 } + end + end + + group.run.should be_true + end + end + + end end end