"About the gifts of the Spirit, brothers, I want you to be quite certain. You remember that when you were pagans, you were irresistibly drawn to inarticulate heathen gods. Because of that, I want to make it quite clear to you that no one who says 'A curse on Jesus' can be speaking in the Spirit of God, and nobody is able to say, 'Jesus is Lord' except in the Holy Spirit." (1 Corinthians 12: 1-3)
The gift of discernment of spirits helps us to discern the will of God for us in concrete situations. The same gift can be used to discern the spirit inside a person. The above scripture gives a simple guideline. Nobody who causes Jesus can have a good spirit living within him. On the other hand, acknowledgment of Jesus as Lord is sign of the presence of a good spirit.
Do you want to exercise the gift of discernment of spirits, then fill your mind with the word of God. The word of God is filled with principles of discernment. One of my favorites is "By their fruits you shall know them."