question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Play 2.6 - users may still use the depracated Action

See original GitHub issue

Hi,

Despite the library now compiling without warnings, users that use it may still run into depracated warnings whenever they use it:

import mockws.MockWS
import play.api.mvc.Results.Ok
import play.api.mvc.Action
val ws = MockWS {
  case (GET, "http://www.example.com") => Action { Ok("homepage") }
}

Will cause:

Warning:(30, 49) object Action in package mvc is deprecated (since 2.6.0): Inject an ActionBuilder (e.g. DefaultActionBuilder) or extend BaseController/AbstractController/InjectedController
        case (GET, "http://www.example.com") => Action { Ok("homepage") }

Maybe it’s a good idea to provide a helper action that the users can import and use without warnings:

import play.api.mvc.{AnyContentAsEmpty, DefaultActionBuilder}
import play.api.test.Helpers.stubBodyParser
import scala.concurrent.ExecutionContext
object MockWS {
  val Action: DefaultActionBuilder = DefaultActionBuilder(stubBodyParser(AnyContentAsEmpty))(ExecutionContext.global)
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
raphaelbauercommented, Sep 18, 2017

Hi @yanns here’s a sketch: https://github.com/leanovate/play-mockws/pull/30 Feedback welcome! Thanks, Raphael

1reaction
francisdbcommented, Sep 14, 2017

this is how we currently work around this for specs2

class UsingMockSpec(implicit ee: ExecutionEnv) extends Specification with FutureMatchers with ResultMatchers with MockHelper{
  // test code here
}
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import org.specs2.specification.AfterAll
import play.api.mvc.{DefaultActionBuilder, PlayBodyParsers}

import scala.concurrent.Await
import scala.concurrent.duration._

/**
  * See https://github.com/leanovate/play-mockws/issues/29
  */
trait MockHelper extends AfterAll{
  private implicit val sys = ActorSystem("test")
  private implicit val mat = ActorMaterializer()

  val BodyParser: PlayBodyParsers = PlayBodyParsers()
  val Action: DefaultActionBuilder = DefaultActionBuilder(BodyParser.anyContent)(mat.executionContext)

  override def afterAll = {
    mat.shutdown()
    Await.result(sys.terminate(), 10.seconds)
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Play 2.6 Migration Guide - Documentation
The play.api.mvc.Action global object and BodyParsers#parse are now deprecated. They are replaced by injectable traits, DefaultActionBuilder and ...
Read more >
PlayFramework migration 2.5.x to 2.6.x deprecated Action.async
Trying to migrate from 2.5.x to 2.6.x. I have trait Secured with old method IsAuthenticatedAsync, i'm trying to write new method ...
Read more >
Play 2.6 Security Analysis - nVisium Blog
Play 2.6 introduces several new security filters that aim to make applications more inherently secure out of the box. They will also make...
Read more >
Migration Guide 2.5.x to 2.6.x • Akka Documentation
If you are still using Scala 2.11 then you must upgrade to 2.12 or 2.13 ... Classic remoting is deprecated but can be...
Read more >
Reactive Scala Driver for MongoDB - ReactiveMongo
Play has deprecated the plugins in version 2.4, therefore it is recommended to remove the former ReactiveMongoPlugin from your project. It must be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found