Rspec给出的文件没有定义错误

时间:2015-06-09 11:11:18

标签: ruby-on-rails ruby rspec

我的代码在这里

rspec spec/rootfiles_spec.rb

但是当我使用/home/ravendra/Documents/rails-project/pif_form/spec/rootfiles_spec.rb:2:in `<top (required)>': undefined method `file' for main:Object (NoMethodError) from /home/ravendra/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `load' from /home/ravendra/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `block in load_spec_files' from /home/ravendra/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `each' from /home/ravendra/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `load_spec_files' from /home/ravendra/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:97:in `setup' from /home/ravendra/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:85:in `run' from /home/ravendra/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run' from /home/ravendra/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:in `invoke' from /home/ravendra/.rvm/gems/ruby-2.2.2/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>' from /home/ravendra/.rvm/gems/ruby-2.2.2/bin/rspec:23:in `load' from /home/ravendra/.rvm/gems/ruby-2.2.2/bin/rspec:23:in `<main>' from /home/ravendra/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval' from /home/ravendra/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>' 时,它会给我们

  #define k_KEYBOARD_OFFSET 95.0

-(void)keyboardWillAppear {
    // Move current view up / down with Animation
    if (self.view.frame.origin.y >= 0)
    {
        [self moveViewUp:NO];
    }
    else if (self.view.frame.origin.y < 0)
    {
        [self moveViewUp:YES];
    }
}

-(void)keyboardWillDisappear {
    if (self.view.frame.origin.y >= 0)
    {
        [self moveViewUp:YES];
    }
    else if (self.view.frame.origin.y < 0)
    {
        [self moveViewUp:NO];
    }
}

-(void)textFieldDidBeginEditing:(UITextField *)sender
{
    //if ([sender isEqual:_txtPassword])
   // {
        //move the main view up, so the keyboard will not hide it.
        if  (self.view.frame.origin.y >= 0)
        {
            [self moveViewUp:YES];
        }
    //}
}

//Custom method to move the view up/down whenever the keyboard is appeared / disappeared
-(void)moveViewUp:(BOOL)bMovedUp
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.4]; // to slide the view up

    CGRect rect = self.view.frame;
    if (bMovedUp) {
        // 1. move the origin of view up so that the text field will come above the keyboard
        rect.origin.y -= k_KEYBOARD_OFFSET;

        // 2. increase the height of the view to cover up the area behind the keyboard
        rect.size.height += k_KEYBOARD_OFFSET;
    } else {
        // revert to normal state of the view.
        rect.origin.y += k_KEYBOARD_OFFSET;
        rect.size.height -= k_KEYBOARD_OFFSET;
    }

    self.view.frame = rect;

    [UIView commitAnimations];
}

- (void)viewWillAppear:(BOOL)animated
{
    // register keyboard notifications to appear / disappear the keyboard
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillAppear)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillDisappear)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    // unregister for keyboard notifications while moving to the other screen.
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIKeyboardWillShowNotification
                                                  object:nil];

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIKeyboardWillHideNotification
                                                  object:nil];
}

有人帮助我

1 个答案:

答案 0 :(得分:4)

错误消息告诉您RSpec中没有file方法。而且,如果你看一下RSpec的文档,你会发现RSpec中确实没有file方法。

所以,你必须要么写一个或安装一个有一个的库。