Sha256: fdb22562392873832cddf6441bb83e4e1b00d8adca31479d3ffd9872742455fc

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'

describe 'Shoes.url' do
  let(:klazz) do
    Class.new(Shoes) do
      include RSpec::Matchers

      url '/', :index
      url '/path', :path
      url '/number/(\d+)', :number
      url '/foo', :foo
      url '/visit_me', :visit_me

      def index
      end

      def path
      end

      def number(i)
      end

      def foo
        some_method
      end

      def visit_me
        expect(location).to eq '/visit_me'
      end

      def some_method
      end
    end
  end

  subject do
    Shoes.app
  end

  it "should call index upon startup" do
    expect_any_instance_of(klazz).to receive(:index)
    subject
  end

  it 'should receive path when visitting path' do
    expect_any_instance_of(klazz).to receive(:path)
    Shoes.app { visit '/path' }
  end

  it 'handles the arguments given in the regexes' do
    expect_any_instance_of(klazz).to receive(:number).with('7')
    Shoes.app { visit '/number/7' }
  end

  it 'can call methods defined in the URL class when visitting a URL' do
    expect_any_instance_of(klazz).to receive(:some_method)
    Shoes.app { visit '/foo' }
  end

  it 'has a location method that returns the current URL' do
    Shoes.app { visit('/visit_me') }
  end

  it 'instances report class as klazz (regression, do not ask...)' do
    expect(klazz.new.class).to eq klazz
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoes-core-4.0.0.pre7 spec/shoes/url_spec.rb