spec/rspec/its_spec.rb in rspec-its-1.1.0 vs spec/rspec/its_spec.rb in rspec-its-1.2.0

- old
+ new

@@ -3,11 +3,11 @@ module RSpec describe Its do describe "#its" do context "with implicit subject" do context "preserves described_class" do - its(:symbol) { expect(described_class).to be Its} + its(:symbol) { expect(described_class).to be Its } its([]) { expect(described_class).to be Its } end end context "with explicit subject" do subject do @@ -51,22 +51,25 @@ def name "John" end end.new end - its("name") { should eq("John") } - its("name.size") { should eq(4) } + its("name") { should eq("John") } + its("name.size") { should eq(4) } its("name.size.class") { should eq(Fixnum) } context "using should_not" do - its("name") { should_not eq("Paul") } + its("name") { should_not eq("Paul") } end context "using is_expected" do - its("name") { is_expected.to eq("John") } + its("name") { is_expected.to eq("John") } end + context "using are_expected" do + its("name.chars.to_a") { are_expected.to eq(%w[J o h n]) } + end end context "when it responds to #[]" do subject do Class.new do @@ -128,11 +131,13 @@ subject { [1, 'a'] } its(:last) { should eq("a") } describe '.first' do - def subject; super().first; end + def subject; + super().first; + end its(:next) { should eq(2) } end end @@ -144,10 +149,11 @@ subject do Class.new do def initialize @counter = -1 end + def nil_if_first_time @counter += 1 @counter == 0 ? nil : true end end.new @@ -159,10 +165,11 @@ subject do Class.new do def initialize @counter = -1 end + def false_if_first_time @counter += 1 @counter > 0 end end.new @@ -184,12 +191,12 @@ its(nil) { expect(eager_loaded_subject_in_let).to eq('my subject') } end describe "in shared_context" do shared_context "shared stuff" do - subject {Array} - its(:name) {should eq "Array"} + subject { Array } + its(:name) { should eq "Array" } end include_context "shared stuff" end @@ -210,10 +217,21 @@ status = result.respond_to?(:status) ? result.status : result[:status].to_sym expect(status).to eq(:passed) end end end + context "with metadata" do + context "preserves access to metadata that doesn't end in hash" do + its([], :foo) do |example| + expect(example.metadata[:foo]).to be(true) + end + end + context "preserves access to metadata that ends in hash" do + its([], :foo, :bar => 17) do |example| + expect(example.metadata[:foo]).to be(true) + expect(example.metadata[:bar]).to be(17) + end + end + end end end - - end