Sha256: e7d4060d61fc097e1fae682754c0ec2b0a74f5a2f2cabcd2e6a1764424a68ddc

Contents?: true

Size: 1.63 KB

Versions: 4

Compression:

Stored size: 1.63 KB

Contents

require File.join(__FILE__.gsub(/(.*)?\/spec\/.*$/, '\1'), 'spec/spec_helper')

describe Rtml::Widgets::EventListener do
  before(:each) do
    @doc = Rtml::Document.new
    @doc.screen :on_cancel
    @doc.screen :on_menu
    @doc.screen :on_key
  end

  context "at document level" do
    it "should raise an error given an invalid key" do
      proc { @doc.on :invalid_key => 'invalid_destination' }.should raise_error(Rtml::Errors::RulesViolationError)
    end

    it "should assign a cancel button" do
      @doc.on :cancel => 'on_cancel'
      @doc.to_tml.should have_selector(:defaults, :cancel => '#on_cancel')
    end

    it "should assign a menu button" do
      @doc.on :menu => 'on_menu'
      @doc.to_tml.should have_selector(:defaults, :menu => '#on_menu')
    end
  end

  context "at screen level" do
    before(:each) { @scr = @doc.screen :main }
    
    it "should raise an error given an invalid key" do
      proc { @scr.on :invalid_key => 'invalid_destination' }.should raise_error(Rtml::Errors::RulesViolationError)
    end

    it "should assign a cancel button" do
      @scr.on :cancel => 'on_cancel'
      @doc.to_tml.should have_selector(:variant, :uri => '#on_cancel', :key => "cancel")
    end

    it "should assign a menu button" do
      @scr.on :menu => 'on_menu'
      @doc.to_tml.should have_selector(:variant, :uri => '#on_menu', :key => "menu")
    end

    %w(0 1 2 3 4 5 6 7 8 9 00 f1 f2 f3 f4 f5 f6 f7 f8 f9 down up stop enter).each do |key|
      it "should assign a #{key} button" do
        @scr.on key => "on_key"
        @doc.to_tml.should have_selector(:variant, :uri => "#on_key", :key => key)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rtml-2.0.3 spec/widgets/event_listener_spec.rb
rtml-2.0.2 spec/widgets/event_listener_spec.rb
rtml-2.0.1 spec/widgets/event_listener_spec.rb
rtml-2.0.0.alpha.1 spec/widgets/event_listener_spec.rb