Sha256: 1ce13cbb766e9988c44d475e5ba489e9e4fb6e8f5a1506ae981dc15062ad5d4e

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'

module RSpecSubjectExtensions::ClassMethods
  describe "initialization" do
    it "should extend RSpec::Core::ExampleGroup with RSpecSubjectExtensions::ClassMethods" do
      RSpec::Core::ExampleGroup.respond_to?('each').should be_true
    end
  end

  describe "#each" do
    it "should satisfy expectation" do
      group = RSpec::Core::ExampleGroup.describe("object") do
        subject {
          Class.new do
            def items
              [1, 2]
            end
          end.new
        }

        each(:item) { should be_an(Integer) }
      end
      group.run(NullObject.new).should be_true
    end

    it "fails when expectation should fail" do
      group = RSpec::Core::ExampleGroup.describe("object") do
        subject {
          Class.new do
            def items
              [1, 'a']
            end
          end.new
        }

        each(:item) { should be_an(Integer) }
      end
      group.run(NullObject.new).should be_false
    end

    context "when it doesn't respond to the pluralized version of the attribute" do
      subject { Object.new }

      context "it raises an error" do
        each(:item) do
          expect do
            should be_an(Integer)
          end.to raise_error(NoMethodError)
        end
      end
    end

    context "when it doesn't return an object responding to each" do
      subject do
        Class.new do
          def items
            1
          end
        end.new
      end

      context "it raises an error" do
        each(:item) do
          expect do
            should be_an(Integer)
          end.to raise_error(NoMethodError)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rspec-subject-extensions-0.2.3 spec/rspec-subject-extensions/class_methods_spec.rb
rspec-subject-extensions-0.2.2 spec/rspec-subject-extensions/class_methods_spec.rb
rspec-subject-extensions-0.2.1 spec/rspec-subject-extensions/class_methods_spec.rb