Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to run initial commands for a program. #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ view : Model -> Html.Html Msg
view model =
div [ onClick Set ] [ text model ]

specs : Node
specs : Node msg
specs =
describe "Example"
[ it "clicking on the div should change the text"
Expand All @@ -87,6 +87,7 @@ main =
, update = update
, view = view
, init = init
, initCmd = Cmd.none
} specs
```

Expand Down
37 changes: 20 additions & 17 deletions source/Spec.elm
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ module Spec exposing
@docs run, runWithProgram
-}
import Spec.Assertions exposing (pass, fail, error)
import Spec.Runner exposing (Prog, State, Msg)
import Spec.Runner exposing (Prog, State)
import Spec.Messages exposing (Msg)
import Spec.Types exposing (..)
import Spec.CoreTypes exposing (..)
import Spec.Native

import Task exposing (Task)
Expand All @@ -66,20 +68,20 @@ type alias Step =

{-| Representation of a test.
-}
type alias Test =
Spec.Types.Test
type alias Test msg =
Spec.Types.Test msg


{-| The outcome of an assertion or step.
-}
type alias Outcome
= Spec.Types.Outcome
= Spec.CoreTypes.Outcome


{-| Representation of a test tree (Node).
-}
type alias Node =
Spec.Types.Node
type alias Node msg =
Spec.Types.Node msg


flip =
Expand All @@ -94,21 +96,21 @@ flip =
]
]
-}
group : String -> List Node -> Node
group : String -> List (Node msg) -> Node msg
group name nodes =
GroupNode { name = name, nodes = nodes }


{-| Alias for `group`.
-}
context : String -> List Node -> Node
context : String -> List (Node msg) -> Node msg
context =
group


{-| Alias for `group`.
-}
describe : String -> List Node -> Node
describe : String -> List (Node msg) -> Node msg
describe =
group

Expand All @@ -117,7 +119,7 @@ describe =

test "description"
-}
test : String -> List Assertion -> Node
test : String -> List Assertion -> Node msg
test name steps =
TestNode
{ steps = steps
Expand All @@ -127,34 +129,35 @@ test name steps =
, name = name
, path = []
, id = -1
, initCmd = Nothing
}


{-| Alias for `it`.
-}
it : String -> List Assertion -> Node
it : String -> List Assertion -> Node msg
it =
test


{-|-}
before : List Assertion -> Node
before : List Assertion -> Node msg
before =
Before

{-|-}
layout : List (String, Rect) -> Node
layout : List (String, Rect) -> Node msg
layout =
Layout

{-|-}
after : List Assertion -> Node
after : List Assertion -> Node msg
after =
After


{-|-}
http : List Request -> Node
http : List Request -> Node msg
http =
Http

Expand Down Expand Up @@ -303,13 +306,13 @@ steps =

{-| Runs the given tests without an app / component.
-}
run : Node -> Program Never (State String msg) (Msg msg)
run : Node msg -> Program Never (State String msg) (Msg msg)
run =
Spec.Runner.run


{-| Runs the given tests with the given app / component.
-}
runWithProgram : Prog model msg -> Node -> Program Never (State model msg) (Msg msg)
runWithProgram : Prog model msg -> Node msg -> Program Never (State model msg) (Msg msg)
runWithProgram =
Spec.Runner.runWithProgram
3 changes: 2 additions & 1 deletion source/Spec/Assertions.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ module Spec.Assertions exposing (..)

import Spec.Types exposing (..)
import Task exposing (Task)
import Spec.CoreTypes exposing (Outcome(..))

{-| The outcome of an assertion or step.
-}
type alias Outcome
= Spec.Types.Outcome
= Spec.CoreTypes.Outcome

{-| Creates a failed outcome with the given message.
-}
Expand Down
12 changes: 12 additions & 0 deletions source/Spec/CoreTypes.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Spec.CoreTypes exposing (..)


{-| Represents an outcome for a step:
* Error - if there was an error during the step (element not found for example)
* Fail - represents failure
* Pass - represents success
-}
type Outcome
= Error String
| Fail String
| Pass String
10 changes: 10 additions & 0 deletions source/Spec/Messages.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Spec.Messages exposing (..)

import Spec.CoreTypes exposing (..)

{-| Messages for a test program.
-}
type Msg msg
= Next (Maybe Outcome)
| NoOp ()
| App msg
6 changes: 4 additions & 2 deletions source/Spec/Reporter.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Spec.Reporter exposing (render)
-}
import Spec.Styles as Styles exposing (stylesheet)
import Spec.Types exposing (..)
import Spec.CoreTypes exposing (Outcome)
import Spec.CoreTypes exposing (Outcome(..))

import Json.Encode

Expand Down Expand Up @@ -48,7 +50,7 @@ renderOutcome outcome =

{-| Renders a test.
-}
renderTest : Test -> Html.Html msg
renderTest : Test msg -> Html.Html msg
renderTest model =
let
requests =
Expand Down Expand Up @@ -89,7 +91,7 @@ renderTest model =

{-| Renders the test results.
-}
render : List Test -> Html.Html msg
render : List (Test msg) -> Html.Html msg
render tests =
let
styles =
Expand Down
Loading