             context("passwordTextField") {
 
                 it("is properly configured") {
-                    expect(controller.passwordTextField.keyboardType.rawValue) == UIKeyboardType.Default.rawValue
-                    expect(controller.passwordTextField.returnKeyType.rawValue) == UIReturnKeyType.Go.rawValue
-                    expect(controller.passwordTextField.secureTextEntry) == true
+                    expect(subject.passwordTextField.keyboardType.rawValue) == UIKeyboardType.Default.rawValue
+                    expect(subject.passwordTextField.returnKeyType.rawValue) == UIReturnKeyType.Go.rawValue
+                    expect(subject.passwordTextField.secureTextEntry) == true
                 }
 
                 it("has controller as delegate") {
-                    expect(controller.passwordTextField.delegate) === controller
+                    expect(subject.passwordTextField.delegate) === subject
                 }
             }
         }
 
         describe("-viewDidLoad") {
 
-            beforeEach {
-                controller = SignInViewController()
-                controller.loadView()
-                controller.viewDidLoad()
-            }
-
             it("has a cross dissolve modal transition style") {
-                expect(controller.modalTransitionStyle.rawValue) == UIModalTransitionStyle.CrossDissolve.rawValue
+                expect(subject.modalTransitionStyle.rawValue) == UIModalTransitionStyle.CrossDissolve.rawValue
             }
 
             it("has a disabled enter button") {
-                expect(controller.enterButton.enabled) == false
+                expect(subject.enterButton.enabled) == false
+            }
+        }
+
+        describe("IBActions") {
+            describe("enterTapped") {
+
+                it("dismisses the keyboard") {
+                    subject.emailTextField.becomeFirstResponder()
+                    subject.enterTapped(subject.enterButton)
+                    expect(subject.emailTextField.isFirstResponder()) == false
+
+
+                    subject.passwordTextField.becomeFirstResponder()
+                    subject.enterTapped(subject.enterButton)
+                    expect(subject.passwordTextField.isFirstResponder()) == false
+                }
+
+                context("input is valid") {
+
+                    it("disables input") {
+                        subject.emailTextField.text = "name@example.com"
+                        subject.passwordTextField.text = "12345678"
+
+                        subject.enterTapped(subject.enterButton)
+                        expect(subject.emailTextField.enabled) == false
+                        expect(subject.passwordTextField.enabled) == false
+                        expect(subject.enterButton.enabled) == false
+                        expect(subject.view.userInteractionEnabled) == false
+                    }
+
+                }
+
+                context("input is invalid") {
+
+                    it("does not disable input") {
+                        subject.emailTextField.text = "invalid email"
+                        subject.passwordTextField.text = "abc"
+
+                        subject.enterTapped(subject.enterButton)
+                        expect(subject.emailTextField.enabled) == true
+                        expect(subject.passwordTextField.enabled) == true
+                        expect(subject.enterButton.enabled) == false
+                        expect(subject.view.userInteractionEnabled) == true
+                    }
+                }
             }
         }
 
         describe("notifications") {
-
-            beforeEach {
-                controller = SignInViewController()
-                controller.loadView()
-                controller.viewDidLoad()
-            }
 
             describe("UIKeyboardWillShowNotification") {
 

class SignInViewControllerSpec: QuickSpec {
    override func spec() {

        beforeSuite {
            ElloProvider.sharedProvider = ElloProvider.StubbingProvider()
        }

        afterSuite {
            ElloProvider.sharedProvider = ElloProvider.DefaultProvider()
        }

        var controller = SignInViewController()
        let screenHeight = controller.view.bounds.size.height
        let screenWidth = controller.view.bounds.size.width

        describe("initialization") {

            beforeEach {
                controller = SignInViewController()
            }

            describe("nib") {

                beforeEach {
                    controller.loadView()
                    controller.viewDidLoad()
                }

                it("IBOutlets are  not nil") {
                    expect(controller.scrollView).notTo(beNil())
                    expect(controller.enterButton).notTo(beNil())
                    expect(controller.forgotPasswordButton).notTo(beNil())
                    expect(controller.emailTextField).notTo(beNil())
                    expect(controller.passwordTextField).notTo(beNil())
                    expect(controller.joinButton).notTo(beNil())
                    expect(controller.enterButtonTopContraint).notTo(beNil())
                    expect(controller.errorLabel).notTo(beNil())
                    expect(controller.elloLogo).notTo(beNil())
                    expect(controller.onePasswordButton).notTo(beNil())
                }

                it("IBActions are wired up") {
                    let enterActions = controller.enterButton.actionsForTarget(controller, forControlEvent: UIControlEvents.TouchUpInside)
                    expect(enterActions).to(contain("enterTapped:"))
                    expect(enterActions?.count) == 1

                    let forgotPasswordActions = controller.forgotPasswordButton.actionsForTarget(controller, forControlEvent: UIControlEvents.TouchUpInside)
                    expect(forgotPasswordActions).to(contain("forgotPasswordTapped:"))
                    expect(forgotPasswordActions?.count) == 1

                    let joinActions = controller.joinButton.actionsForTarget(controller, forControlEvent: UIControlEvents.TouchUpInside)
                    expect(joinActions).to(contain("joinTapped:"))
                    expect(joinActions?.count) == 1

                    let onePasswordActions = controller.onePasswordButton.actionsForTarget(controller, forControlEvent: UIControlEvents.TouchUpInside)
                    expect(onePasswordActions).to(contain("findLoginFrom1Password:"))
                    expect(onePasswordActions?.count) == 1
                }
            }

            it("can be instantiated from nib") {
                expect(controller).notTo(beNil())
            }

            it("is a BaseElloViewController") {
                expect(controller).to(beAKindOf(BaseElloViewController.self))
            }

            it("is a SignInViewController") {
                expect(controller).to(beAKindOf(SignInViewController.self))
            }
        }

        describe("text fields") {

            beforeEach {
                controller = SignInViewController()
                controller.loadView()
                controller.viewDidLoad()
            }

            context("emailTextField") {

                it("is properly configured") {
                    expect(controller.emailTextField.keyboardType.rawValue) == UIKeyboardType.EmailAddress.rawValue
                    expect(controller.emailTextField.returnKeyType.rawValue) == UIReturnKeyType.Next.rawValue
                }

                it("has controller as delegate") {
                    expect(controller.emailTextField.delegate) === controller
                }

            }

                        Keyboard.shared().topEdge = screenHeight - 100.0
                        postNotification(Keyboard.Notifications.KeyboardWillShow, Keyboard.shared())

                        expect(subject.scrollView.contentInset.bottom) == 0
                    }
                }
            }
