<commit_before>describe 'UIAlertView' do
  tests UIViewController  # this is just needed so that a window is available

  it 'should have :show option (show: false)' do
    alert = UIAlertView.alert('test', show: false)
    proper_wait 0.6
    alert.visible?.should == false
  end

  it 'should have :show option (show: true)' do
    alert = UIAlertView.alert('test', show: true)
    proper_wait 1
    alert.visible?.should == true
    alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
  end

  it 'should show by default' do
    alert = UIAlertView.alert('test')
    proper_wait 1
    alert.visible?.should == true
    alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
  end

  it 'should assign the title' do
    alert = UIAlertView.alert('test title', show: false)
    alert.title.should == 'test title'
  end

  it 'should support three args' do
    alert = UIAlertView.alert('test title', 'test message', show: false)
    alert.visible?.should == false
  end

  describe 'should assign the message' do

    it 'should use the second arg' do
      alert = UIAlertView.alert('test title', 'test message', show: false)
      alert.message.should == 'test message'
    end

    it 'should use the :message option' do
      alert = UIAlertView.alert('test title', message: 'test message', show: false)
      alert.message.should == 'test message'
    end

  end

  it 'should have << method' do
    alert = UIAlertView.alert('test', show: false)
    -> {
      alert << 'title'
    }.should.not.raise
  end

  it 'should add a button with << method' do
    alert = UIAlertView.alert('test', show: false)
    alert << 'title'
    alert.buttonTitleAtIndex(alert.firstOtherButtonIndex + 1).should == 'title'
  end

  it 'should display "OK" when no buttons are specified' do
    alert = UIAlertView.alert('test', show: false)
    alert.cancelButtonIndex.should == -1
    alert.buttonTitleAtIndex(alert.firstOtherButtonIndex).should == 'OK'
  end

  it 'should use a cancel button if any buttons are specified' do
    alert = UIAlertView.alert('test', buttons: ['a', 'b'], show: false)
    alert.buttonTitleAtIndex(alert.cancelButtonIndex).should == 'a'
    alert.buttonTitleAtIndex(alert.firstOtherButtonIndex).should == 'b'
  end

  it 'should have :style option' do
    Symbol.uialertstyle.each do |style, value|
      # as symbol
      alert = UIAlertView.alert('test', show: false, style: style)
      alert.alertViewStyle.should == value

      # as constant
      alert = UIAlertView.alert('test', show: false, style: value)
      alert.alertViewStyle.should == value
    end
  end

  it 'should call the block when dismissed' do
    alert = UIAlertView.alert('test') { @touched = true }
    alert.numberOfButtons.should == 1
    proper_wait 0.6
    alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)

    @touched.should == true
  end

  it 'should call the block and pass the button when dismissed' do
    alert = UIAlertView.alert('test') { |button| @touched = button }
    proper_wait 0.6
    alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)

    @touched.should == 'OK'
  end

  it 'should call the block and pass the button and index when dismissed' do
    alert = UIAlertView.alert('test') { |button, index| @touched, @touched_index = button, index }
    proper_wait 0.6
    alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)

    @touched.should == 'OK'
    @touched_index.should == 0
  end

  it 'should call the block when dismissed no matter when cancel button pressed' do
    alert = UIAlertView.alert('test', buttons:['cancel','ok']) { @touched = true }
    alert.numberOfButtons.should == 2
    proper_wait 0.6
    alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)

    @touched.should == true
  end

  it 'should call the block and pass the button when dismissed with multiple buttons' do
    alert = UIAlertView.alert('test', buttons: ['cancel', 'ok']) { |button| @touched = button }
    proper_wait 0.6
    alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)

    @touched.should == 'cancel'
  end

  it 'should call the block and pass the button and index when dismissed with multiple buttons' do
    alert = UIAlertView.alert('test', buttons: ['cancel', 'ok']) { |button, index| @touched, @touched_index = button, index }
    proper_wait 0.6
    alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)

    @touched.should == 'cancel'
    @touched_index.should == 0
  end

  describe 'Should call the appropriate block when :cancel and :success handlers are used' do

    before do
      @touched = nil
      @alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'],
        cancel: ->{ @touched = :cancel },
        success: ->{ @touched = :success }
        )
    end

    after do
      @alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
    end

    it 'should work for :cancel' do
      proper_wait 0.6
      @alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)

      @touched.should == :cancel
    end

    it 'should work for :success' do
      proper_wait 0.6
      @alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)

      @touched.should == :success
    end

  end

  describe 'should call the block and pass the button and inputs' do

    before do
      @text = nil
    end

    it 'should work with :secure_text_input' do
      alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :secure_text_input) { |button, text|
        @text = text
      }
      proper_wait 0.6
      alert.textFieldAtIndex(0).text = 'test text'
      alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)

      @text.should == 'test text'
    end

    it 'should work with :plain_text_input' do
      alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :plain_text_input) { |button, text|
        @text = text
      }
      proper_wait 0.6
      alert.textFieldAtIndex(0).text = 'test text'<commit_msg>spec update, still fails mysteriously<commit_after>describe 'UIAlertView' do
  tests UIViewController  # this is just needed so that a window is available

  it 'should have :show option (show: false)' do
    alert = UIAlertView.alert('test', show: false)
    proper_wait 0.6
    alert.visible?.should == false
  end

  it 'should have :show option (show: true)' do
    alert = UIAlertView.alert('test', show: true)
    proper_wait 1
    alert.visible?.should == true
    alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
  end

  it 'should show by default' do
    alert = UIAlertView.alert('test')
    proper_wait 1
    alert.visible?.should == true
    alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
  end

  it 'should assign the title' do
    alert = UIAlertView.alert('test title', show: false)
    alert.title.should == 'test title'
  end

  it 'should support three args' do
    alert = UIAlertView.alert('test title', 'test message', show: false)
    alert.visible?.should == false
  end

  describe 'should assign the message' do

    it 'should use the second arg' do
      alert = UIAlertView.alert('test title', 'test message', show: false)
      alert.message.should == 'test message'
    end

    it 'should use the :message option' do
      alert = UIAlertView.alert('test title', message: 'test message', show: false)
      alert.message.should == 'test message'
    end

  end

  it 'should have << method' do
    alert = UIAlertView.alert('test', show: false)
    -> {
      alert << 'title'
    }.should.not.raise
  end

  it 'should add a button with << method' do
    alert = UIAlertView.alert('test', show: false)
    alert << 'title'
    alert.buttonTitleAtIndex(alert.firstOtherButtonIndex + 1).should == 'title'
  end

  it 'should display "OK" when no buttons are specified' do
    alert = UIAlertView.alert('test', show: false)
    alert.cancelButtonIndex.should == -1
    alert.buttonTitleAtIndex(alert.firstOtherButtonIndex).should == 'OK'
  end

  it 'should use a cancel button if any buttons are specified' do
    alert = UIAlertView.alert('test', buttons: ['a', 'b'], show: false)
    alert.buttonTitleAtIndex(alert.cancelButtonIndex).should == 'a'
    alert.buttonTitleAtIndex(alert.firstOtherButtonIndex).should == 'b'
  end

  it 'should have :style option' do
    Symbol.uialertstyle.each do |style, value|
      # as symbol
      alert = UIAlertView.alert('test', show: false, style: style)
      alert.alertViewStyle.should == value

      # as constant
      alert = UIAlertView.alert('test', show: false, style: value)
      alert.alertViewStyle.should == value
    end
  end

  it 'should call the block when dismissed' do
    alert = UIAlertView.alert('test') { @touched = true }
    alert.numberOfButtons.should == 1
    proper_wait 0.6
    alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)

    @touched.should == true
  end

  it 'should call the block and pass the button when dismissed' do
    alert = UIAlertView.alert('test') { |button| @touched = button }
    proper_wait 0.6
    alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)

    @touched.should == 'OK'
  end

  it 'should call the block and pass the button and index when dismissed' do
    alert = UIAlertView.alert('test') { |button, index| @touched, @touched_index = button, index }
    proper_wait 0.6
    alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)

    @touched.should == 'OK'
    @touched_index.should == 0
  end

  it 'should call the block when dismissed no matter when cancel button pressed' do
    alert = UIAlertView.alert('test', buttons:['cancel','ok']) { @touched = true }
    alert.numberOfButtons.should == 2
    proper_wait 0.6
    alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)

    @touched.should == true
  end

  it 'should call the block and pass the button when dismissed with multiple buttons' do
    alert = UIAlertView.alert('test', buttons: ['cancel', 'ok']) { |button| @touched = button }
    proper_wait 0.6
    alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)

    @touched.should == 'cancel'
  end

  it 'should call the block and pass the button and index when dismissed with multiple buttons' do
    alert = UIAlertView.alert('test', buttons: ['cancel', 'ok']) { |button, index| @touched, @touched_index = button, index }
    proper_wait 0.6
    alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)

    @touched.should == 'cancel'
    @touched_index.should == 0
  end

  describe 'Should call the appropriate block when :cancel and :success handlers are used' do

    before do
      @touched = nil
      @alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'],
        cancel: ->{ @touched = :cancel },
        success: ->{ @touched = :success }
        )
    end

    after do
      @alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
    end

    it 'should work for :cancel' do
      proper_wait 0.6
      @alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)

      @touched.should == :cancel
    end

    it 'should work for :success' do
      proper_wait 0.6
      @alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)

      @touched.should == :success
    end

  end

  describe 'should call the block and pass the button and inputs' do

    before do
      @text = nil
    end

    it 'should work with :secure_text_input' do
      @called = false
      alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :secure_text_input) { |button, text|
        @called = true
        @text = text
      }
      proper_wait 0.6
      alert.textFieldAtIndex(0).text = 'test text'
      alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)

      @called.should == true
      @text.should == 'test text'
    end

    it 'should work with :plain_text_input' do
      alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :plain_text_input) { |button, text|
        @text = text
      }
      proper_wait 0.6
      alert.textFieldAtIndex(0).text = 'test text'
{'fraction_non_alphanumeric': 0.1081145966709347, 'fraction_numerical': 0.005121638924455826, 'mean_word_length': 3.3833742546474923, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1274805', 'n_tokens_mistral': 3836, 'n_tokens_neox': 3637, 'n_words': 1127}