Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replace 'state' with 'in_block?' (less invasive and no need for state

yet).
  • Loading branch information...
commit c542ce2d88d5e58691938fd329a1c2648f78734b 1 parent c2df11a
@dchelimsky dchelimsky authored
View
14 lib/rspec/core/example.rb
@@ -2,7 +2,7 @@ module Rspec
module Core
class Example
- attr_reader :metadata, :example_block, :state
+ attr_reader :metadata, :example_block
def self.delegate_to_metadata(*keys)
keys.each do |key|
@@ -10,7 +10,7 @@ def self.delegate_to_metadata(*keys)
end
end
- delegate_to_metadata :description, :full_description, :execution_result, :file_path, :pending, :subject_modifier
+ delegate_to_metadata :description, :full_description, :execution_result, :file_path, :pending
alias_method :inspect, :full_description
alias_method :to_s, :full_description
@@ -24,9 +24,14 @@ def example_group
@example_group_class
end
+ def in_block?
+ @in_block
+ end
+
alias_method :behaviour, :example_group
def run(example_group_instance, reporter)
+ @in_block = false
@example_group_instance = example_group_instance
@example_group_instance.running_example = self
@@ -35,10 +40,9 @@ def run(example_group_instance, reporter)
exception = nil
begin
- @state = :before
run_before_each
- @state = :block
pending_declared_in_example = catch(:pending_declared_in_example) do
+ @in_block = true
if @example_group_class.around_eachs.empty?
@example_group_instance.instance_eval(&example_block) unless pending
else
@@ -49,11 +53,11 @@ def run(example_group_instance, reporter)
rescue Exception => e
exception = e
ensure
+ @in_block = false
assign_auto_description
end
begin
- @state = :after
run_after_each
rescue Exception => e
exception ||= e
View
8 lib/rspec/core/example_group.rb
@@ -42,13 +42,6 @@ def self.#{name}(desc=nil, options={}, &block)
END_RUBY
end
- def self.its(modifier, desc=nil, options={}, &block)
- options.update(:pending => true) unless block
- options.update(:caller => caller)
- options.update(:subject_modifier => modifier)
- examples << Rspec::Core::Example.new(self, desc, options, block)
- end
-
define_example_method :example
class << self
@@ -56,6 +49,7 @@ class << self
end
alias_example_to :it
+ alias_example_to :its, :attribute_of_subject => true
alias_example_to :specify
alias_example_to :focused, :focused => true
alias_example_to :pending, :pending => true
View
17 lib/rspec/core/subject.rb
@@ -9,7 +9,7 @@ def self.included(kls)
end
def subject
- modify_subject? ? modified_subject : unmodified_subject
+ attribute_of_subject || original_subject
end
# When +should+ is called with no explicit receiver, the call is
@@ -75,18 +75,17 @@ def implicit_subject
private
- def modify_subject?
- !running_example.nil? &&
- !running_example.subject_modifier.nil? &&
- running_example.state == :block
+ def original_subject
+ @original_subject ||= instance_eval(&self.class.subject)
end
- def unmodified_subject
- @unmodified_subject ||= instance_eval(&self.class.subject)
+ def attribute_of_subject
+ original_subject.send(running_example.description) if using_attribute?
end
- def modified_subject
- unmodified_subject.send(running_example.subject_modifier)
+ def using_attribute?
+ running_example.in_block? &&
+ running_example.metadata[:attribute_of_subject]
end
end
View
16 spec/rspec/core/example_group_spec.rb
@@ -412,27 +412,17 @@ module Rspec::Core
end
end
- describe "example added with its" do
- it "should have a subject_modifier" do
- group = ExampleGroup.describe
- examples = group.its(:some_method) { }
- example = examples.last
- example.subject_modifier.should === :some_method
- end
- end
-
describe "#its" do
- its(:class, "should be ExampleGroup") { should == Rspec::Core::ExampleGroup }
- it "does not interfere between tests" do
+ its(:class) { should == Rspec::Core::ExampleGroup }
+ it "does not interfere between examples" do
subject.class.should == Rspec::Core::ExampleGroup
end
context "subject modified in before block" do
before { subject.class.should == Rspec::Core::ExampleGroup }
- its(:class, "should be ExampleGroup") { should == Rspec::Core::ExampleGroup }
end
end
- describe "top_level_description" do
+ describe "#top_level_description" do
it "returns the description from the outermost example group" do
group = nil
ExampleGroup.describe("top") do
View
18 spec/rspec/core/example_spec.rb
@@ -25,14 +25,6 @@
it "should have one for it's block" do
example.should respond_to(:example_block)
end
-
- it "should have one for its subject modifier" do
- example.should respond_to(:subject_modifier)
- end
-
- it "should have one for its state" do
- example.should respond_to(:state)
- end
end
describe '#inspect' do
@@ -96,15 +88,15 @@
end
end
- describe "#state" do
+ describe "#in_block?" do
before do
- running_example.state.should == :before
+ running_example.should_not be_in_block
end
- it "should have block state while running actual example block" do
- running_example.state.should == :block
+ it "is only true during the example (but not before or after)" do
+ running_example.should be_in_block
end
after do
- running_example.state.should == :after
+ running_example.should_not be_in_block
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.