Skip to content

Commit

Permalink
move 'its' specs to subject_spec and reorg a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Jan 27, 2011
1 parent 599c0c9 commit 14d77bf
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 77 deletions.
77 changes: 0 additions & 77 deletions spec/rspec/core/example_group_spec.rb
Expand Up @@ -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
Expand Down
81 changes: 81 additions & 0 deletions spec/rspec/core/subject_spec.rb
Expand Up @@ -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

0 comments on commit 14d77bf

Please sign in to comment.